ObsWebSocket constructor Null safety
- {required WebSocketChannel channel,
- Function? fallbackEvent}
When the object is created we open the websocket connection and create a broadcast stream so that we can have multiple listeners providing responses to commands. channel is an existing WebSocketChannel.
Implementation
ObsWebSocket({required this.channel, Function? fallbackEvent}) {
broadcast = channel.stream.asBroadcastStream();
broadcast.listen((jsonEvent) {
final Map<String, dynamic> rawEvent = jsonDecode(jsonEvent);
if (!rawEvent.containsKey('message-id')) {
_handleEvent(BaseEvent.fromJson(rawEvent));
}
}, cancelOnError: true);
}