listen method
Listens to a specific event from the socket.
Throws SocketNotConnectedException if not connected. Throws SocketEventException if event listening fails.
Implementation
@override
Future<void> listen(String eventName) async {
try {
if (eventName.isEmpty) {
throw SocketEventException('Event name cannot be empty');
}
await methodChannel.invokeMethod('listen', {'event': eventName});
} on PlatformException catch (e) {
_handlePlatformException(e, 'listen');
} catch (e) {
if (e is SocketException) {
rethrow;
}
throw SocketEventException('Unexpected error while listening to event "$eventName": $e');
}
}