Is it possible to send a message to all clients without roomAPI

Azhar Ali

Member
Hi,
I know there is a function to send a message to all clients using roomAPI and clients can receieve the message and process. Is the same possible using normal streams without using the roomAPI?
Any pointer to the example would be really helpful

thanks
 

Max

Administrator
Staff member
Good day.
You can use REST hooks to broadcast message to the connected clients as follows:
1) Use /connect REST hook to collect the client sessionId (you are probably already using /connect to authenticate users):
Code:
POST /EchoApp/connect HTTP/1.1
Accept: application/json, application/*+json
Content-Type: application/json;charset=UTF-8
Host: localhost:8081
Connection: keep-alive
Content-Length: 537
{
   "nodeId":"Hw47CFMBEchVOpBMDr29IxjudnJ1sjOY@192.168.1.101",
   "appKey":"defaultApp",
   "sessionId":"/192.168.1.103:15422/192.168.1.101:8443",
   ...
}
2) Use Session.sendData({"message": "hello"}) WebSDK API call to send message from broadcaster to WCS
3) Use /OnDataEvent REST hook to get this message on backend server, it should receive something like
Code:
POST /rest/my_api/OnDataEvent HTTP/1.1
Accept: application/json, application/*+json
Content-Type: application/json;charset=UTF-8
Host: 192.168.1.101
Connection: keep-alive
Content-Length: 218
{
    "nodeId":"Hw47CFMBEchVOpBMDr29IxjudnJ1sjOY@192.168.1.101",
    "appKey":"defaultApp",
    "sessionId":"/192.168.1.102:55839/192.168.1.101:8443",
    "operationId":"d1999750-fde9-11e6-9f1b-913210792931",
    "payload":{
        "message":"hello"
    }
}
4) Use REST API query /rest-api/data/send to send this message to all the connected clients (you should iterate through the list of clients sessionId):
Code:
POST /rest-api/data/send HTTP/1.1
Host: 192.168.1.101:8081
Content-Length: 201
Content-Type: application/json
{
    "nodeId":"Hw47CFMBEchVOpBMDr29IxjudnJ1sjOY@192.168.1.101",
    "operationId":"d1999750-fde9-11e6-9f1b-913210792931",
    "sessionId":"/192.168.1.103:15422/192.168.1.101:8443",
    "payload":{
        "message":"hello"
    }
}
 

Azhar Ali

Member
Hi Max,

Thank you for getting back to me.
I understood the first three points. I am not sure about the forth step, what would be the URL address for /rest-api/data/send call? Which app would it be?
 
Top