ImSocketChannel constructor
ImSocketChannel(
- String url, {
- ValueChanged? onData,
- ValueChanged? onError,
- 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();
});
}