RTCDataChannel constructor

RTCDataChannel(
  1. RtcDataChannel _jsDc
)

Implementation

RTCDataChannel(this._jsDc) {
  stateChangeStream = _stateChangeController.stream;
  messageStream = _messageController.stream;
  _jsDc.onClose.listen((_) {
    _state = RTCDataChannelState.RTCDataChannelClosed;
    _stateChangeController.add(_state);
    if (onDataChannelState != null) {
      onDataChannelState(_state);
    }
  });
  _jsDc.onOpen.listen((_) {
    _state = RTCDataChannelState.RTCDataChannelOpen;
    _stateChangeController.add(_state);
    if (onDataChannelState != null) {
      onDataChannelState(_state);
    }
  });
  _jsDc.onMessage.listen((event) async {
    RTCDataChannelMessage msg = await _parse(event.data);
    _messageController.add(msg);
    if (onMessage != null) {
      onMessage(msg);
    }
  });
}