listen method
Listen this connection
Implementation
Future<void> listen() async {
/**
* Socket listener for each identified device
*/
subscription = socketBroadcast.listen((event) async {
///data oluĆturuluyor
try {
lastOnline = DateTime.now().millisecondsSinceEpoch;
if (event.runtimeType != String) {
// print(utf8.decode(event));
}
var data = SocketData.fromSocket(event);
if (data.type == 'error') {
sendMessage(client, data);
} else if (data.type == 'close') {
// print("CLOSE CLOSE CLOSE");
await close();
} else if (data.type == 'connection_confirmation') {
// print("connection_confirmation");
} else {
if (data.isEncrypted) {
try {
if (cnonce != null && nonce != null) {
await data.decrypt(nonce, cnonce);
}
await operation.operate(this, data);
} on Exception {
// TODO:ADD ERROR
}
} else {
// print('DATA NULLLL : ${data.data}');
}
}
} on Exception {
// TODO:ADD ERROR
}
}, onError: (e) async {
// print(e);
await close();
}, cancelOnError: true, onDone: close);
}