initDataChannel method
this method Initialize data channel on handle's internal peer connection object. It is mainly used for Janus TextRoom and can be used for other plugins with data channel support
Implementation
Future<void> initDataChannel({RTCDataChannelInit? rtcDataChannelInit}) async {
if (webRTCHandle!.peerConnection != null) {
if (webRTCHandle!.dataChannel[_context._dataChannelDefaultLabel] != null)
return;
if (rtcDataChannelInit == null) {
rtcDataChannelInit = RTCDataChannelInit();
rtcDataChannelInit.ordered = true;
rtcDataChannelInit.protocol = 'janus-protocol';
}
webRTCHandle!.dataChannel[_context._dataChannelDefaultLabel] =
await webRTCHandle!.peerConnection!.createDataChannel(
_context._dataChannelDefaultLabel, rtcDataChannelInit);
if (webRTCHandle!.dataChannel[_context._dataChannelDefaultLabel] !=
null) {
webRTCHandle!.dataChannel[_context._dataChannelDefaultLabel]!
.onDataChannelState = (state) {
if (!_onDataStreamController!.isClosed) {
_onDataStreamController!.sink.add(state);
}
};
webRTCHandle!.dataChannel[_context._dataChannelDefaultLabel]!
.onMessage = (RTCDataChannelMessage message) {
if (!_dataStreamController!.isClosed) {
_dataStreamController!.sink.add(message);
}
};
}
} else {
throw Exception(
"You Must Initialize Peer Connection before even attempting data channel creation!");
}
}