Sessions in WebRTC HelloWorld

Ask any questions or talk about OpenTok here!

Sessions in WebRTC HelloWorld

Postby geoff » Thu Nov 22, 2012 1:57 pm

Hi,

I am trying to implement the OpenTok WebRTC APIs, as described in the HelloWorld tutorial, but am running into issues when trying to create sessions. What is the best way to do this? I am running Python on Google App Engine and have installed the Python OpenTokSDK.

Right now I am trying to create the session in my Python script with the following code, and pass the session ID, but it is not returning anything:

import OpenTokSDK

jinja_environment = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))

api_key = '99999999' # Replace with your OpenTok API key.
api_secret = 'lasjflksjadfjasldjfasjkldfjklsdf' # Replace with your OpenTok API secret.
session_address = '8.8.8.8' # Replace with the representative URL of your session.

opentok_sdk = OpenTokSDK.OpenTokSDK(api_key, api_secret)
session = opentok_sdk.create_session(session_address)

class MainPage(webapp2.RequestHandler):
def get(self):
template = jinja_environment.get_template('test.html')
self.response.out.write(template.render({ 'var1': session }))

app = webapp2.WSGIApplication([('/test', MainPage)],
debug=True)



Thanks for your help,
Geoff
Was this post helpful? (0)
geoff
 
Posts: 3
Joined: Thu Nov 22, 2012 12:20 pm
Thumbs Up: 0

Re: Sessions in WebRTC HelloWorld

Postby adam » Thu Nov 22, 2012 5:34 pm

Hi Geoff,

It sounds like you're probably getting an error. I'm not super familiar with app engine. Is there a way to look into error logs to see if any exceptions are being raised? If you use invalid key and secret as above you'll get an error something like:
OpenTokSDK.RequestError: Failed to send request: HTTP Error 403: Forbidden
Was this post helpful? (0)
adam
 
Posts: 65
Joined: Thu May 05, 2011 8:35 pm
Thumbs Up: 3

Re: Sessions in WebRTC HelloWorld

Postby geoff » Fri Nov 23, 2012 6:39 am

Hi Adam,

I just put the random API key and secret in there so that I could post on this forum; in my actual code I'm using the correct values. I think that my problem is that I don't understand the OpenTok sessions and tokens; do you have documentation that describe these?

Should my server side python script create the session and pass the session ID to the javascript, and then I can use the session ID to generate a token?

Thanks,
Geoff
Was this post helpful? (0)
geoff
 
Posts: 3
Joined: Thu Nov 22, 2012 12:20 pm
Thumbs Up: 0

Re: Sessions in WebRTC HelloWorld

Postby geoff » Fri Nov 23, 2012 7:53 am

Ignore that last message, I actually found all of the documentation about sessions and tokens, but I do have one more quick question:
In the WebRTC HelloWorld example, does each user need their own token, or can they both use the same one? If I want 2 clients to be able to connect with each other, how can I keep track of the first client's session ID to make sure that I pass the second client the same session?

Thanks,
Geoff
Was this post helpful? (0)
geoff
 
Posts: 3
Joined: Thu Nov 22, 2012 12:20 pm
Thumbs Up: 0

Re: Sessions in WebRTC HelloWorld

Postby adam » Fri Nov 23, 2012 2:23 pm

You don't necessarily have to generate a new token for each user. Each token has an expiration period and as long as it's used within that period it can be used multiple times by multiple different individuals. Sometimes it's easier to just generate a new token for everyone though which brings me to your next question.

You will need to figure out a way to pass the session ID between the users in your own application. Depending on the application you may do this in different ways. If there is just a one off application on a page you could just generate the session id once and hard code it into the page. Then you would just generate a new token for every load of the page and then anyone that lands on the page will connect to the same session.

In a one-to-one call which it sounds like you have you would probably generate the sessionId for whoever initiated the call and then pass it to the other user somehow. This could either be as a get parameter to a URL that they copy and paste, as we do in our tutorials. Or you could store the sessionId in your system and pass it to the other user somehow. It really depends on the logic of your application. But basically it's up to you to share the sessionId between the users and we take care of the rest.

Adam
Was this post helpful? (0)
adam
 
Posts: 65
Joined: Thu May 05, 2011 8:35 pm
Thumbs Up: 3


Return to Discussion and Questions



Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest

cron