LogInput constructor
LogInput({
- required String url,
- required InputReadyCallback onReady,
Implementation
LogInput({required this.url, required this.onReady})
: socket = sio.io(url, OptionBuilder().enableForceNew().build()) {
_controller = StreamController(
onListen: () => _shouldForward = true,
onPause: () => _shouldForward = false,
onResume: () => _shouldForward = true,
onCancel: () => _shouldForward = false,
);
socket.onConnect((_) {
debugPrint('connected to url => $url, id => ${socket.id}');
onReady(socket.id!);
socket.on('msg', (data) {
_peer = data[0];
if (!_shouldForward) {
debugPrint('will not forward stream');
return;
}
OutputEvent event = _outputEvent(data[1]);
_controller.add(event);
});
socket.onError((error) => debugPrint('error => $error'));
socket.onConnectError((error) => debugPrint('error => $error'));
socket.onConnectTimeout((error) => debugPrint('error => $error'));
socket.onDisconnect((reason) =>
debugPrint('disconnected from url => $url, reason => $reason'));
});
}