json_socket.dart 547 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:convert';
import 'dart:io';

class JSONSocket {
Hixie's avatar
Hixie committed
10
  JSONSocket(WebSocket socket, this.unusualTermination)
11 12 13 14
    : _socket = socket, stream = socket.map(JSON.decode).asBroadcastStream();

  final WebSocket _socket;
  final Stream stream;
Hixie's avatar
Hixie committed
15
  final Future<String> unusualTermination;
16 17 18 19 20

  void send(dynamic data) {
    _socket.add(JSON.encode(data));
  }
}