-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
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
Message parameter in event.on('message', chatController.newMessage); always receive as null value #63
Comments
i found that the payload must be under "payload" key instead of "data" as mentioned in the documentation |
still toRoom Function is not working .. it seems that joinRoom is not working fine , I have printed the members in webSocketClientImpl and always returns an empty array |
Fixed websocket issue(#63) join and left room
Thank you for reporting, fixed in version 0.2.2 please update To join a room use this {
"event":"join-room",
"room":"unique room name or ID"
} To send a message to a room {
"event":"message",
"payload":{
"room":"room name or id",
"message": "message"
}
} Controller import 'package:vania/vania.dart';
class ChatWebSocketController extends Controller {
Future newMessage(WebSocketClient client, dynamic payload) async {
client.toRoom('message', payload['room'].toString(), payload['message']);
}
}
ChatWebSocketController chatController = ChatWebSocketController(); |
I am still unable to join a room or print anything to verify
|
Hi @WissamALSbenaty please test with this Dart client code import 'dart:convert';
import 'package:web_socket_channel/web_socket_channel.dart';
void main() async {
final wsUrl = Uri.parse('ws://127.0.0.1:8000/ws');
final channel = WebSocketChannel.connect(wsUrl);
await channel.ready;
channel.stream.listen((message) {
print('message $message');
});
channel.sink.add(jsonEncode({"event": "join-room", "room": "myRoom"}));
Future.delayed(Duration(seconds: 2), () {
channel.sink.add(jsonEncode({
"event": "message-to-room",
"payload": {"room": "myRoom", "message": "Javad Join Room"}
}));
});
} Server Code // Router
import 'package:vania/vania.dart';
import 'package:server/app/http/controllers/ws/chat_web_socket_controller.dart';
class WebSocketRoute implements Route {
@override
void register() {
Router.websocket('/ws', (WebSocketEvent event) {
event.on('message', chatController.newMessage);
event.on('message-to-room', chatController.joinRoom);
});
}
} // Controller
import 'package:vania/vania.dart';
class ChatWebSocketController extends Controller {
Future newMessage(WebSocketClient client, dynamic message) async {
}
Future joinRoom(WebSocketClient client, dynamic payload) async {
client.toRoom('message-to-room', payload['room'], payload['message']); // send the message to the room
}
}
ChatWebSocketController chatController = ChatWebSocketController();
|
same result |
The code I sent has been tested and is working. Could you please provide your cod? |
I am trying to run my first vania server
my main focus is testing how websocket works
so I discovered that I need to change the value of websocket in both .env file and app config file to true after taking a long time
but the problem for me now I print the value of the message that the client sent
web_socket.dart file
chat_web_socket_controller.dart
the events
the output recieved null
and the toRoom does nothing which is another problem , emit and broadcast worked fine with me
The text was updated successfully, but these errors were encountered: