We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I could connect successfully with pusher at the backend but it wont receive anything.
The text was updated successfully, but these errors were encountered:
@bensonarafat Have you use channel.stream.listen() it?
In my project:
ChatGPT-Flutter-Web
import 'package:web_socket_channel/web_socket_channel.dart'; /// /// Connect Send Socket /// @Riverpod(keepAlive: true) WebSocketChannel send(SendRef ref) { const backendWebSocketUrl = String.fromEnvironment('BACKEND_WS_URL', defaultValue: ApiProvider.wsUrl); return WebSocketChannel.connect( Uri.parse( "${backendWebSocketUrl}chat/receive?token=${ref.watch(tokenProvider)}"), ); } /// /// Listen Stream /// _userMessageStreamListen() { ref.read(sendProvider).stream.listen( (jsonData) { var data = json.decode(jsonData); var result = BaseResult<List<ChatMessageInfo>>.fromJson( data, (jsonT) => (jsonT as List<dynamic>) .map((item) => ChatMessageInfo.fromJson(item)) .toList()); result.data != null && result.data!.length == 1 ? ref.read(chatMessagesProvider.notifier).insertMessageList(result) : ref.read(chatMessagesProvider.notifier).selectMessageList(result); }, onDone: () { retryUserSocket(); }, onError: (error) { Logger().d('WebSocket error: $error'); }, ); } /// send message ref.read(sendProvider).sink.add(_chatMessageData(next.$1, next.$3));
Because channel.stream is asnyc stream, you should listen it to receive server message, do not use await for(xxxxxxx)
Sorry, something went wrong.
Okay, great. I'll try it
No branches or pull requests
I could connect successfully with pusher at the backend but it wont receive anything.
The text was updated successfully, but these errors were encountered: