Queuing streams and displaying one-by-one?

Ask questions about the JavaScript API here

Queuing streams and displaying one-by-one?

Postby nado » Wed Mar 07, 2012 9:55 pm

Hi

If I wanted a single stream displayed at any one time, in which people queue to publish out... would it be best to recreate the session each time, or is there a way to identify and display a specific stream (from the streams[] array)?

e.g. can I just subscribe to one stream, then unsubscribe, then subscribe again to a different (but specific) stream?

Though are sessions destroyed at some point?

Cheers
Was this post helpful? (0)
nado
 
Posts: 3
Joined: Wed Mar 07, 2012 9:50 pm
Thumbs Up: 0

Re: Queuing streams and displaying one-by-one?

Postby jtsai » Thu Mar 08, 2012 11:33 am

Yes, there are ways to identify a specific stream. Sessions are never destroyed.

There are two properties of a stream that can be used to identify a stream:

stream.streamId and stream.connection

You can select the stream you want to subscribe to based on these. One question from me, how are you going to choose which stream to the user wants to subscribe to next?

John
Was this post helpful? (0)
Very helpful resource: Devs Checklist
Examples with OpenTok: Examples
User avatar
jtsai
 
Posts: 2019
Joined: Wed Sep 14, 2011 3:00 pm
Thumbs Up: 157

Re: Queuing streams and displaying one-by-one?

Postby nado » Thu Mar 08, 2012 3:41 pm

Ah ok thanks. I'm going to pull it from a database.

Does it matter whether I use stream.streamId or stream.connection?

Also, how would I check that a specific stream.connection (or streamId) is still active?
Was this post helpful? (0)
nado
 
Posts: 3
Joined: Wed Mar 07, 2012 9:50 pm
Thumbs Up: 0

Re: Queuing streams and displaying one-by-one?

Postby jtsai » Thu Mar 08, 2012 4:59 pm

I would suggest you use stream.streamId. A connection has the possibility of creating more than one stream. You can check if a stream is still active because you will be keeping a list of all the active streams as a local variable (streams[]).

So here is what you can do:
1. Query your database for a stream ID
2. Check local variables to see if there is still a stream with the streamID.
- If there is, then stream that stream.
- If there isn't anymore, then delete that stream from the database, and request a new one, and goto step 1.

John
Was this post helpful? (1)
Very helpful resource: Devs Checklist
Examples with OpenTok: Examples
User avatar
jtsai
 
Posts: 2019
Joined: Wed Sep 14, 2011 3:00 pm
Thumbs Up: 157

Re: Queuing streams and displaying one-by-one?

Postby nado » Thu Mar 08, 2012 5:07 pm

Thanks John! Yeah it just hit me that everything runs client side (duh). I can work with that - just means there will be a few extra database queries. Would be nice to include some event listeners through the server-side (PHP) API sometime in the future. Will let you know how it goes :)
Was this post helpful? (0)
nado
 
Posts: 3
Joined: Wed Mar 07, 2012 9:50 pm
Thumbs Up: 0

Re: Queuing streams and displaying one-by-one?

Postby jtsai » Thu Mar 08, 2012 5:13 pm

Haha, server-side API may be hard for PHP, since PHP is usually just called when a client loads a page. If it was server-side, then the client will have to be continuously loading the page, unless you set a PHP script to run from server-side forever >_> But yeah, if you run into other problems, feel free to post questions haha.

John
Was this post helpful? (0)
Very helpful resource: Devs Checklist
Examples with OpenTok: Examples
User avatar
jtsai
 
Posts: 2019
Joined: Wed Sep 14, 2011 3:00 pm
Thumbs Up: 157


Return to JavaScript



Who is online

Users browsing this forum: No registered users and 1 guest

cron