open method
Attempts to open the connection with the server. Returns true if successful and false otherwise.
Implementation
Future<bool> open() async {
try {
_webSocket = await WebSocket.connect(_speechURL);
} on SocketException catch (e) {
_logger?.log(this, e);
return false;
} on Exception catch (e) {
_logger?.log(this, e);
return false;
}
_webSocket?.pingInterval = const Duration(seconds: 5);
_webSocket?.listen(
(data) {
if (_onMessage != null) {
_onMessage!(data);
}
},
cancelOnError: true,
onDone: () {
if (_onDisconnected != null) {
_onDisconnected!();
}
_webSocket = null;
},
onError: (error) {
if (_onError != null) {
_onError!(error);
}
});
return true;
}