connect method
Joins the session with code on the relay at server, for example
wss://support.example.com.
Implementation
Future<void> connect({required Uri server, required String code}) async {
await disconnect();
_setStatus(RemoteViewerStatus.connecting);
final uri = server.replace(
path: '${server.path.replaceAll(RegExp(r'/$'), '')}/ws/viewer',
queryParameters: {...server.queryParameters, 'code': code},
);
try {
final channel = WebSocketChannel.connect(uri);
_channel = channel;
await channel.ready;
_setStatus(RemoteViewerStatus.waitingForDevice);
_subscription = channel.stream.listen(
_onMessage,
onDone: () => _onClosed(channel.closeReason),
onError: (Object e) => _onClosed('$e'),
);
} catch (e) {
_onClosed('$e');
}
}