Realtime stream information can be obtained using STOMP protocol over Websocket API.
To connect to backend server for obtaining realtime metric values, do the following:
1. Establish Secure Websocket connection to https://hostname:8090/ws, where hostname is backend server address
2. Establish STOMP connection by sending the message
CONNECT accept-version:1.2 host:hostname ^@ |
3. Subscribe to /stream/nodeId/mediaId event by sending the message
SUBSCRIBE id:sub-1 destination:/stream/15/010934f0-0766-11e9-a950-59983a9de3c8 ^@ |
Where
4. Subscribe to /alarm event for receiving alarms
SUBSCRIBE id:sub-0 destination:/alarm ^@ |
After that, client starts receiving STOMP messages in plain text
"MESSAGE\ndestination:/stream/15/010934f0-0766-11e9-a950-59983a9de3c8\ncontent-type:application/json;charset=UTF-8\nsubscription:sub-1\nmessage-id:oilwo0os-701\ncontent-length:1349\n\n[{\"VIDEO_SYNC\":3754637125197,\"VIDEO_CODEC\":120,\"VIDEO_NACK\":18,\"VIDEO_PLI\":0,\"VIDEO_RATE\":478104,\"VIDEO_WIDTH\":320,\"VIDEO_HEIGHT\":240,\"VIDEO_FPS\":30,\"timestamp\":1545648325506},{\"AUDIO_SYNC\":3754637125227,\"AUDIO_CODEC\":111,\"AUDIO_RATE\":32616,\"timestamp\":1545648325558,\"AUDIO_LOST\":21},{\"AUDIO_SYNC\":3754637125347,\"AUDIO_CODEC\":111,\"AUDIO_RATE\":32960,\"timestamp\":1545648325684,\"AUDIO_LOST\":21},{\"VIDEO_SYNC\":3754637125397,\"VIDEO_CODEC\":120,\"VIDEO_NACK\":18,\"VIDEO_PLI\":0,\"VIDEO_RATE\":504632,\"VIDEO_WIDTH\":320,\"VIDEO_HEIGHT\":240,\"VIDEO_FPS\":31,\"timestamp\":1545648325701},{\"AUDIO_SYNC\":3754637125467,\"AUDIO_CODEC\":111,\"AUDIO_RATE\":33048,\"timestamp\":1545648325805,\"AUDIO_LOST\":21},{\"VIDEO_SYNC\":3754637125597,\"VIDEO_CODEC\":120,\"VIDEO_NACK\":18,\"VIDEO_PLI\":0,\"VIDEO_RATE\":495624,\"VIDEO_WIDTH\":320,\"VIDEO_HEIGHT\":240,\"VIDEO_FPS\":30,\"timestamp\":1545648325911},{\"AUDIO_SYNC\":3754637125587,\"AUDIO_CODEC\":111,\"AUDIO_RATE\":33048,\"timestamp\":1545648325921,\"AUDIO_LOST\":21},{\"AUDIO_SYNC\":3754637125707,\"AUDIO_CODEC\":111,\"AUDIO_RATE\":32400,\"timestamp\":1545648326049,\"AUDIO_LOST\":21},{\"VIDEO_SYNC\":3754637125796,\"VIDEO_CODEC\":120,\"VIDEO_NACK\":18,\"VIDEO_PLI\":0,\"VIDEO_RATE\":480224,\"VIDEO_WIDTH\":320,\"VIDEO_HEIGHT\":240,\"VIDEO_FPS\":32,\"timestamp\":1545648326104},{\"AUDIO_SYNC\":3754637125827,\"AUDIO_CODEC\":111,\"AUDIO_RATE\":33048,\"timestamp\":1545648326159,\"AUDIO_LOST\":21}]\u0000" |
or in JSON using STOMP.js library
{ "command": "MESSAGE", "headers": { "content-length": "1282", "message-id": "oilwo0os-926", "subscription": "sub-1", "content-type": "application/json;charset=UTF-8", "destination": "/stream/15/010934f0-0766-11e9-a950-59983a9de3c8" }, "body": [ { "VIDEO_SYNC": 3754637299170, "VIDEO_CODEC": 120, "VIDEO_NACK": 20, "VIDEO_PLI": 0, "VIDEO_RATE": 617024, "VIDEO_WIDTH": 320, "VIDEO_HEIGHT": 240, "VIDEO_FPS": 24, "timestamp": 1545648499723 }, { "AUDIO_SYNC": 3754637299482, "AUDIO_CODEC": 111, "AUDIO_RATE": 30600, "timestamp": 1545648499799, "AUDIO_LOST": 23 }, ... ] } |
The messages contain metric values acquired from the node where the stream is published or played.
To stop receiving metrics in realtime, the following message should be sent to unsubscribe
UNSUBSCRIBE id:/stream/15/010934f0-0766-11e9-a950-59983a9de3c8 ^@ |
Maximum metrics count in one STOMP message is set with the following parameter in wcsoam.properties
stomp_max_metrics=10 |
Connection timeout is set with the following parameter
stomp_max_timeout=1000 |
A different metrics sets can be aquired to backend server with a different rate defined by profile. If metric value, VIDEO_HEIGHT for example, does not change while stream is published, then messages with this metric will be send to subscriber at least as rate defines. If metric value (VIDEO_RATE) changes, messages with this metric can be send to subscriber upon changes.
For example, if stream data are collected by profile including one static metric VIDEO_WIDTH with rate 30
https://hostname:8090/api/profile/create { "name": "profile1", "rate": "30", "metrics": ["1"], "rules": ["1"] } |
and maximum metrics count 1 per one message
stomp_max_metrics=1 |
the messages will be send to subscriber near 1 per second.
When changing rate to 600
https://hostname:8090/api/profile/update { "id": "2", "name": "profile1", "rate": "600", "metrics": ["1"], "rules": ["1"] } |
the messages will be send to subscriber near 1 per 20 seconds.
Now, extending metrics set to 4 static metrics VIDEO_WIDTH, VIDEO_HEIGHT, VIDEO_CODEC, AUDIO_CODEC
https://hostname:8090/api/profile/update { "id": "2", "name": "profile1", "rate": "600", "metrics": ["1","2","8","12"], "rules": ["1"] } |
the messages will be send to subscriber near 1 per 5 seconds.
When stream data are collected by profile including two metrics VIDEO_RATE, AUDIO_RATE with rate 30
https://hostname:8090/api/profile/create { "name": "profile2", "rate": "30", "metrics": ["3","10"], "rules": ["1"] } |
and maximum metrics count 1 per one message
stomp_max_metrics=1 |
for the stream published to WCS using RTMP, the messages will be send to subscriber near 1-2 per second.