ImSocketChannel constructor

ImSocketChannel(
  1. String url, {
  2. ValueChanged? onData,
  3. ValueChanged? onError,
  4. VoidCallback? onClose,
})

Implementation

ImSocketChannel(String url, {this.onData, this.onError, this.onClose}) {
  Uri uri = Uri.parse(url);
  _channel = PlatformUtils.isWeb() ? WebSocketChannel.connect(uri) : IOWebSocketChannel.connect(uri);
  _channel?.stream.listen((event) {
    onData?.call(event);
  }, onError: (error, stackTrace) {
    onError?.call(error);
  }, onDone: () {
    onClose?.call();
  });
}