I want to create a Rocket Chat client to subscribe to a channel through browser using Realtime API. Documentation here does not provide step by step procedure. Please let me know how to achieve it.
Links to any documentation would be very helpful.
Our real-time API is composed of two elements: Method Calls and Subscriptions. Both of them are supported directly in the websocket connection.
To connect to a Rocket. Chat server through a web browser, enter the desired server address in the browser's address bar, such as https://open.rocket.chat . After entering a valid Rocket. Chat server address, the registration page appears.
FAQs about Rocket.Yes, you can self-host it and use your Community Edition workspace for free, forever.
The Rocket. Chat mobile app is developed with React Native, helping us create both Android and iOS applications from a single codebase.
I had less idea about websockets when I asked this question. For the benefit of all, mentioning the steps I followed.
var rocketChatSocket = new WebSocket("ws://locahost:3000/websocket");
var connectRequest = {
"msg": "connect",
"version": "1",
"support": ["1", "pre2", "pre1"]
}
rocketChatSocket.send(JSON.stringify(connectRequest));
After connecting, keep responding with {"msg":"pong"}
for {"msg":"ping"}
from server.
var loginRequest = {
"msg": "method",
"method": "login",
"id": "42",
"params": [
{ "resume": "authToken" }
]
}
rocketChatSocket.send(JSON.stringify(loginRequest));
var subscribeRequest = {
"msg": "sub",
"id": "unique-id",
"name": "stream-notify-room",
"params":[
"room-id/event",
false
]
}
rocketChatSocket.send(JSON.stringify(subscribeRequest));
var request={
"msg": "method",
"method": "sendMessage",
"id": "42",
"params":
[
{
"_id": "message-id",
"rid": "room-id",
"msg": "Hello World!"
}
]
}
rocketChatSocket.send(JSON.stringify(request));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With