Filter Rest API Streams & Terminate by Custom Data

Hi,

In backend with Rest API I want to query & terminate streams by custom data as posted from client side while creating session or creating stream.

I want to implement a security where with 1 token only 1 session is going on (1 token = 1 viewer), above will help in that.

Ideally wouldn't like to query streams based on available filters (/stream/find) and than filter them out based on this custom data via code as that could be a lengthy task if connected clients are large in numbers.

Querying at /stream/find_all , i can see data is there but cannot find a way to query more specifically based on custom data (custom.token) at /stream/find endpoint

1680958648509.png


Please help in this. Thanks.
 
Good day.
The custom fiels is intended to use in REST hooks, not in REST API filters. Please look at this use case: Authentication.
So you should set up REST hook /publishStream (see the example of /connect REST hook setup), collect a stream descriptions including tokens on your backend and then select streams to terminate from this collection.
Hi,

I am using & talking about hooks only.

Scenario is, i am generating & caching 1 unique token for each user for 1 particular stream, no more than 1 token is sent to frontend to user to access 1 particular stream even if same user account is logined elsewhere.

Whenever that user tries to play 1 particular streaming with 1 unique assigned to him for that particular stream, i want to close all existing sessions playing streaming with that particular token.

This is to prevent account sharing, 1 paid user account shared by user with family/friends, if only 1 token is sent to user to frontend with 1 user account for 1 stream and with 1 token only 1 session can play 1 stream, it will prevent, it will help me achieve that.

Now issue is lets say another user trying to play same stream with same token elsewhere and /playstream hook is called, in which i have custom.token available, i want to close all existing sessions (streaming being played), which are being played using same token, for this i planned to query all streams being played with same token from rest api (should not be more than 1), and than terminate that using rest api & upon successfull termination authorize/allow /playstream hook by sending 200 status.

That querying about streams playing/sessions/connections (maybe it is fetched from /connection/find not /stream/find , i mentioned it wrong, i got confused) & terminating stream playing/sessions/connections ( /connection/terminate ) should be done via rest api inside hook, right ?

But how can i filter sessions/connections by token (custom.token) ? Or best if with 1 request to /connection/terminate we could terminate based on other fields too not just sessionId, but also custom.token etc
 

Max

Administrator
Staff member
cannot download OBS WebRTC Client 1.0 from
Fixed, it is available again. But we do not test it with latest WCS builds, and do not recommend to use it due to codec limitations (VP8 only). Please use MPEG-TS over SRT publishing instead (ffmpeg, OBS, Gstreamer support this).
Whenever that user tries to play 1 particular streaming with 1 unique assigned to him for that particular stream, i want to close all existing sessions playing streaming with that particular token.
When receiving a /playStream hook, you have a stream name, a token and a sessionId:
Code:
URL:http://localhost:8081/apps/EchoApp/playStream
OBJECT:
{
   ...,
  "sessionId" : "/192.168.23.83:58106/192.168.130.39:8443-38968b0d",
  ...,
  "name" : "test",
  ...,
  "custom": {
      "token": "1234567890"
  }
}
You should put them to your custom backend database using a pair "stream name + token" as a key.
Then, if someone else tries to play the same stream from another session
Code:
URL:http://localhost:8081/apps/EchoApp/playStream
OBJECT:
{
   ...,
  "sessionId" : "/192.168.25.85:55000/192.168.130.39:8443-ee7f70403c0c",
  ...,
  "name" : "test",
  ...,
  "custom": {
      "token": "1234567890"
  }
}
you can select all the records with {name: "test", token: "1234567890"} from your database, and terminate all the sessions selected by sessionId using /connection/terminate REST API query.
Using this approach you do not have to query /stream/find at all.
 
Fixed, it is available again. But we do not test it with latest WCS builds, and do not recommend to use it due to codec limitations (VP8 only). Please use MPEG-TS over SRT publishing instead (ffmpeg, OBS, Gstreamer support this).

When receiving a /playStream hook, you have a stream name, a token and a sessionId:
Code:
URL:http://localhost:8081/apps/EchoApp/playStream
OBJECT:
{
   ...,
  "sessionId" : "/192.168.23.83:58106/192.168.130.39:8443-38968b0d",
  ...,
  "name" : "test",
  ...,
  "custom": {
      "token": "1234567890"
  }
}
You should put them to your custom backend database using a pair "stream name + token" as a key.
Then, if someone else tries to play the same stream from another session
Code:
URL:http://localhost:8081/apps/EchoApp/playStream
OBJECT:
{
   ...,
  "sessionId" : "/192.168.25.85:55000/192.168.130.39:8443-ee7f70403c0c",
  ...,
  "name" : "test",
  ...,
  "custom": {
      "token": "1234567890"
  }
}
you can select all the records with {name: "test", token: "1234567890"} from your database, and terminate all the sessions selected by sessionId using /connection/terminate REST API query.
Using this approach you do not have to query /stream/find at all.
Hi,

Custom development i know can be achieved with own database but isn't REST API too limited ?

Maybe something like GraphQL will make Flashphoner REST API much more powerfull for custom development suting various use cases. Hope you consider.

Thanks for your time.
 

Max

Administrator
Staff member
Custom development i know can be achieved with own database but isn't REST API too limited ?
REST API queries support filtering by mandatory fields, but custom object is optional. Also, we can't make a supposition about custom object contents, every customer may use its own form.
 
Hi,

I was able to terminate connections which i wanted to with custom logic & in-memory database/object using /connection/terminate endpoint of Rest API.

Now i need to know in the frontend at client side that connection has been closed/disconnected/failed whatever, due to above code, my custom code above keeps track of {user_id : last_session_id} and whenever any streaming is played from that user_id, i terminates (/connection/terminate) last_session_id and assign current_session_id to last_session_id of that user_id. Its working fine.

Now how to get to know about this at client side ? The use case is if reason of close/disconnection/failure is above than i won't be automatic retrying streaming playback at client side which i do in all cases, instead will show them the error that streaming has been stopped because same account been used to play stream elsewhere, click to play again.
 

Max

Administrator
Staff member
Now how to get to know about this at client side ?
You should establish your own websocket connection to your custom backend and send appropriate message to the client. Then in client code you can display the message.
Another option is to form a web page on custom backend and periodically check it from a client.
 
Top