dart-lang / web_socket_channel

StreamChannel wrappers for WebSockets.
https://pub.dev/packages/web_socket_channel
BSD 3-Clause "New" or "Revised" License
415 stars 109 forks source link

Provide concrete example of multiplatform websocket #44

Open lukepighetti opened 5 years ago

lukepighetti commented 5 years ago

I have not been able to implement a multiplatform websocket with this package. I see no code examples to assist in the process. The only thing I can figure is that we're supposed to create a platform specific socket channel and pass it to WebSocketChannel.

It's basically gone like this so far:

1) Oh hey, I'm going to use web_socket_channel it's multiplatform! 2) What is a StreamChannel? 3) Okay, import package:web_socket_channel/io.dart... 4) Now I need a WebSocket? 5) Okay, import dart:io.... 6) Wait, WebSocket is abstract? Okay, lets implement.... 48 methods?!?!?!

Please give us some breadcrumbs.

lukepighetti commented 5 years ago

I don't understand the architecture of web_socket_channel. Shouldn't I be specifying the URI and channels within my package to a multi-platform interface and having the user provide only a websocket driver? The way this is architected it looks like the consuming package specifies all endpoints/channels etc.

micimize commented 3 years ago

The top-level cross-platform export WebSocketChannel handles delegating to the platform-specific implementations. Just call WebSocketChannel.connect(uri, protocols: protocols)

https://github.com/dart-lang/web_socket_channel/blob/ca5659502200535a232c28501d4a01c410732d2a/lib/src/channel.dart#L110-L111