emit method

  1. @override
Future<void> emit(
  1. String eventName,
  2. dynamic data
)
override

Emits an event to the socket.

Throws SocketNotConnectedException if not connected. Throws SocketEmissionException if emission fails.

Implementation

@override
Future<void> emit(String eventName, dynamic data) async {
  try {
    if (eventName.isEmpty) {
      throw SocketEmissionException('Event name cannot be empty');
    }

    await methodChannel.invokeMethod('emit', {'event': eventName, 'data': data});
  } on PlatformException catch (e) {
    _handlePlatformException(e, 'emit');
  } catch (e) {
    if (e is SocketException) {
      rethrow;
    }
    throw SocketEmissionException('Unexpected error while emitting event "$eventName": $e');
  }
}