connect method
Connect with the given access token via WebSocket to the backend. Will be rejected without right access token.
Implementation
Future<PhoenixSocket?> connect(String accessToken) {
phoenixSocket = PhoenixSocket(TeleRepo.websocketURL,
socketOptions: PhoenixSocketOptions(params: {
"token": accessToken,
"app_id": LocalitySocialCloud.getAppID()
}, timeout: Duration(seconds: 30)));
phoenixSocket!.openStream.listen((event) {
for (var element
in globalSessionInstance.functionsToBeExecutedOnConnect) {
element(phoenixSocket!);
}
connected = true;
notifyListeners();
});
phoenixSocket!.closeStream.listen((event) {
for (var element
in globalSessionInstance.functionsToBeExecutedOnDisconnect) {
element(phoenixSocket!);
}
connected = false;
notifyListeners();
});
phoenixSocket!.errorStream.listen((event) {
connected = false;
notifyListeners();
print("LocalitySocialCloud connect ERROR: $event");
});
return phoenixSocket!.connect();
}