本文整理汇总了Python中opentok.OpenTok.create_session方法的典型用法代码示例。如果您正苦于以下问题:Python OpenTok.create_session方法的具体用法?Python OpenTok.create_session怎么用?Python OpenTok.create_session使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opentok.OpenTok
的用法示例。
在下文中一共展示了OpenTok.create_session方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from opentok import OpenTok [as 别名]
# 或者: from opentok.OpenTok import create_session [as 别名]
def index(request):
key = "45351832"
secret = "29d4d704b3a28373202c230946bfe91e3e74c4fb"
opentok = OpenTok(key, secret)
if request.method == "POST":
name = request.POST.get('name', '')
role = request.POST.get('role', '')
if role == "": role = "Publisher"
ses_id = request.POST.get('session', '')
try:
if ses_id is "":
ses = "New Session"
session = opentok.create_session()
session_id = session.session_id
token = opentok.generate_token(session_id,role=Roles.publisher)
else:
ses = "Existing Session"
session_id = ses_id
if role == "moderator":
token = opentok.generate_token(session_id,role=Roles.moderator)
elif role == "subscriber":
token = opentok.generate_token(session_id,role=Roles.subscriber)
else:
token = "Wrong Role requested for existing session id"
data = {"user": name, "Session": ses, "role":role, "session:": {"Authentication": token, "Session ID": session_id}}
except Exception as e:
data = {"Exception": e.message, "Type": type(e)}
return JsonResponse(data)
示例2: post
# 需要导入模块: from opentok import OpenTok [as 别名]
# 或者: from opentok.OpenTok import create_session [as 别名]
def post(self):
caller = self.request.get('caller')
callee = self.request.get('callee')
registrations = Registration.query(Registration.uid == callee).order(-Registration.date).fetch(5)
opentok = OpenTok(api_key, secret)
session = opentok.create_session()
token = session.generate_token()
call = {
'caller': caller,
'callee': callee,
'apiKey': api_key,
'sessionId': session.session_id,
'token': token
}
if not registrations:
self.abort(404)
return
logging.info(str(registrations))
for registration in registrations:
self.signal(registration.session_id, call)
self.response.write(json.dumps(call))
示例3: create_session
# 需要导入模块: from opentok import OpenTok [as 别名]
# 或者: from opentok.OpenTok import create_session [as 别名]
def create_session(request):
tbox = TokBox.objects.get(pk=1)
opentok = OpenTok(tbox.api_key, tbox.api_secret)
session = opentok.create_session(media_mode=MediaModes.routed)
session_id = session.session_id
return HttpResponse(session_id)
示例4: generate_session_id
# 需要导入模块: from opentok import OpenTok [as 别名]
# 或者: from opentok.OpenTok import create_session [as 别名]
def generate_session_id():
opentok = OpenTok(api_key, api_secret)
# Create a session that attempts to send streams directly between clients (falling back
# to use the OpenTok TURN server to relay streams if the clients cannot connect):
session = opentok.create_session()
# Store this session ID in the database
session_id = session.session_id
# print("generate session:" + session_id)
return session_id
示例5: get
# 需要导入模块: from opentok import OpenTok [as 别名]
# 或者: from opentok.OpenTok import create_session [as 别名]
def get(self):
template = JINJA_ENVIRONMENT.get_template('index.html')
uid = self.request.get('uid')
if uid:
opentok = OpenTok(api_key, secret)
session = opentok.create_session()
registration = Registration(parent=ndb.Key('Registration', 'poc'))
registration.uid = uid
registration.session_id = str(session.session_id)
registration.put()
logging.info('Register uid: ' + uid + ' sessionId: ' + session.session_id)
self.response.write(template.render({
'uid': uid,
'apiKey': api_key,
'sessionId': session.session_id,
'token': session.generate_token()
}))
else:
self.response.write(template.render({}))
示例6: Exception
# 需要导入模块: from opentok import OpenTok [as 别名]
# 或者: from opentok.OpenTok import create_session [as 别名]
try:
api_key = os.environ['API_KEY']
api_secret = os.environ['API_SECRET']
except Exception:
raise Exception('You must define API_KEY and API_SECRET environment variables')
monkey.patch_all()
app = Flask(__name__)
app.debug=True
app.config['SECRET_KEY']='secret!'
socketio=SocketIO(app)
thread=None
opentok = OpenTok(api_key, api_secret)
toksession = opentok.create_session()
rooms = {}
@app.route("/")
def display_index():
return render_template("index.html")
@app.route("/login", methods=['POST'])
def login():
"""check if user in db, add to session and redirect to profile
if not in db, redirect to index page"""
email = request.form.get("email")
password = request.form.get("password")
示例7: test_timeout
# 需要导入模块: from opentok import OpenTok [as 别名]
# 或者: from opentok.OpenTok import create_session [as 别名]
def test_timeout(self):
with self.assertRaises(RequestError):
opentok = OpenTok(self.api_key, self.api_secret, timeout=5)
opentok.create_session()
示例8: OpenTokSessionCreationTest
# 需要导入模块: from opentok import OpenTok [as 别名]
# 或者: from opentok.OpenTok import create_session [as 别名]
class OpenTokSessionCreationTest(unittest.TestCase):
def setUp(self):
self.api_key = u('123456')
self.api_secret = u('1234567890abcdef1234567890abcdef1234567890')
self.opentok = OpenTok(self.api_key, self.api_secret)
@httpretty.activate
def test_create_default_session(self):
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/session/create'),
body=u('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>'),
status=200,
content_type=u('text/xml'))
session = self.opentok.create_session()
expect(httpretty.last_request().headers[u('x-tb-partner-auth')]).to.equal(self.api_key+u(':')+self.api_secret)
expect(httpretty.last_request().headers[u('user-agent')]).to.contain(u('OpenTok-Python-SDK/')+__version__)
body = parse_qs(httpretty.last_request().body)
expect(body).to.have.key(b('p2p.preference')).being.equal([b('enabled')])
expect(body).to.have.key(b('archiveMode')).being.equal([b('manual')])
expect(session).to.be.a(Session)
expect(session).to.have.property(u('session_id')).being.equal(u('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg'))
expect(session).to.have.property(u('media_mode')).being.equal(MediaModes.relayed)
expect(session).to.have.property(u('location')).being.equal(None)
@httpretty.activate
def test_create_routed_session(self):
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/session/create'),
body=u('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>'),
status=200,
content_type=u('text/xml'))
session = self.opentok.create_session(media_mode=MediaModes.routed)
expect(httpretty.last_request().headers[u('x-tb-partner-auth')]).to.equal(self.api_key+u(':')+self.api_secret)
expect(httpretty.last_request().headers[u('user-agent')]).to.contain(u('OpenTok-Python-SDK/')+__version__)
body = parse_qs(httpretty.last_request().body)
expect(body).to.have.key(b('p2p.preference')).being.equal([b('disabled')])
expect(body).to.have.key(b('archiveMode')).being.equal([b('manual')])
expect(session).to.be.a(Session)
expect(session).to.have.property(u('session_id')).being.equal(u('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg'))
expect(session).to.have.property(u('media_mode')).being.equal(MediaModes.routed)
expect(session).to.have.property(u('location')).being.equal(None)
@httpretty.activate
def test_create_session_with_location_hint(self):
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/session/create'),
body=u('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>'),
status=200,
content_type=u('text/xml'))
session = self.opentok.create_session(location='12.34.56.78')
expect(httpretty.last_request().headers[u('x-tb-partner-auth')]).to.equal(self.api_key+u(':')+self.api_secret)
expect(httpretty.last_request().headers[u('user-agent')]).to.contain(u('OpenTok-Python-SDK/')+__version__)
# ordering of keys is non-deterministic, must parse the body to see if it is correct
body = parse_qs(httpretty.last_request().body)
expect(body).to.have.key(b('location')).being.equal([b('12.34.56.78')])
expect(body).to.have.key(b('p2p.preference')).being.equal([b('enabled')])
expect(session).to.be.a(Session)
expect(session).to.have.property(u('session_id')).being.equal(u('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg'))
expect(session).to.have.property(u('media_mode')).being.equal(MediaModes.relayed)
expect(session).to.have.property(u('location')).being.equal(u('12.34.56.78'))
@httpretty.activate
def test_create_routed_session_with_location_hint(self):
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/session/create'),
body=u('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>'),
status=200,
content_type=u('text/xml'))
session = self.opentok.create_session(location='12.34.56.78', media_mode=MediaModes.routed)
expect(httpretty.last_request().headers[u('x-tb-partner-auth')]).to.equal(self.api_key+u(':')+self.api_secret)
expect(httpretty.last_request().headers[u('user-agent')]).to.contain(u('OpenTok-Python-SDK/')+__version__)
# ordering of keys is non-deterministic, must parse the body to see if it is correct
body = parse_qs(httpretty.last_request().body)
expect(body).to.have.key(b('location')).being.equal([b('12.34.56.78')])
expect(body).to.have.key(b('p2p.preference')).being.equal([b('disabled')])
expect(session).to.be.a(Session)
expect(session).to.have.property(u('session_id')).being.equal(u('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg'))
expect(session).to.have.property(u('media_mode')).being.equal(MediaModes.routed)
expect(session).to.have.property(u('location')).being.equal(u('12.34.56.78'))
@httpretty.activate
def test_create_manual_archive_mode_session(self):
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/session/create'),
body=u('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>'),
status=200,
content_type=u('text/xml'))
session = self.opentok.create_session(media_mode=MediaModes.routed, archive_mode=ArchiveModes.manual)
expect(httpretty.last_request().headers[u('x-tb-partner-auth')]).to.equal(self.api_key+u(':')+self.api_secret)
expect(httpretty.last_request().headers[u('user-agent')]).to.contain(u('OpenTok-Python-SDK/')+__version__)
body = parse_qs(httpretty.last_request().body)
expect(body).to.have.key(b('p2p.preference')).being.equal([b('disabled')])
expect(body).to.have.key(b('archiveMode')).being.equal([b('manual')])
expect(session).to.be.a(Session)
expect(session).to.have.property(u('session_id')).being.equal(u('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg'))
#.........这里部分代码省略.........
示例9: OpenTokSessionCreationTest
# 需要导入模块: from opentok import OpenTok [as 别名]
# 或者: from opentok.OpenTok import create_session [as 别名]
class OpenTokSessionCreationTest(unittest.TestCase):
def setUp(self):
self.api_key = os.environ.get('API_KEY') or u('123456')
self.api_secret = (os.environ.get('API_SECRET') or
u('1234567890abcdef1234567890abcdef1234567890'))
self.api_url = os.environ.get('API_URL')
self.mock = not (os.environ.get('API_MOCK') == 'FALSE')
if self.mock or self.api_url is None:
self.opentok = OpenTok(self.api_key, self.api_secret)
else:
self.opentok = OpenTok(self.api_key, self.api_secret, api_url = self.api_url)
def httpretty_enable(self):
if self.mock:
httpretty.enable()
def httpretty_disable(self):
if self.mock:
httpretty.disable()
def test_create_default_session(self):
self.httpretty_enable()
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/session/create'),
body=u('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>'),
status=200,
content_type=u('text/xml'))
session = self.opentok.create_session()
if self.mock:
expect(httpretty.last_request().headers[u('x-tb-partner-auth')]).to.equal(self.api_key+u(':')+self.api_secret)
expect(httpretty.last_request().headers[u('user-agent')]).to.contain(u('OpenTok-Python-SDK/')+__version__)
expect(httpretty.last_request().body).to.equal(b('p2p.preference=enabled'))
expect(session).to.be.a(Session)
if self.mock:
expect(session).to.have.property(u('session_id')).being.equal(u('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg'))
expect(session).to.have.property(u('media_mode')).being.equal(MediaModes.relayed)
expect(session).to.have.property(u('location')).being.equal(None)
self.httpretty_disable()
def test_create_routed_session(self):
self.httpretty_enable()
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/session/create'),
body=u('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>'),
status=200,
content_type=u('text/xml'))
session = self.opentok.create_session(media_mode=MediaModes.routed)
if self.mock:
expect(httpretty.last_request().headers[u('x-tb-partner-auth')]).to.equal(self.api_key+u(':')+self.api_secret)
expect(httpretty.last_request().headers[u('user-agent')]).to.contain(u('OpenTok-Python-SDK/')+__version__)
expect(httpretty.last_request().body).to.equal(b('p2p.preference=disabled'))
expect(session).to.be.a(Session)
if self.mock:
expect(session).to.have.property(u('session_id')).being.equal(u('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg'))
expect(session).to.have.property(u('media_mode')).being.equal(MediaModes.routed)
expect(session).to.have.property(u('location')).being.equal(None)
self.httpretty_disable()
def test_create_session_with_location_hint(self):
self.httpretty_enable()
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/session/create'),
body=u('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>'),
status=200,
content_type=u('text/xml'))
session = self.opentok.create_session(location='12.34.56.78')
if self.mock:
expect(httpretty.last_request().headers[u('x-tb-partner-auth')]).to.equal(self.api_key+u(':')+self.api_secret)
expect(httpretty.last_request().headers[u('user-agent')]).to.contain(u('OpenTok-Python-SDK/')+__version__)
# ordering of keys is non-deterministic, must parse the body to see if it is correct
body = parse_qs(httpretty.last_request().body)
expect(body).to.have.key(b('location')).being.equal([b('12.34.56.78')])
expect(body).to.have.key(b('p2p.preference')).being.equal([b('enabled')])
expect(session).to.be.a(Session)
if self.mock:
expect(session).to.have.property(u('session_id')).being.equal(u('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg'))
expect(session).to.have.property(u('media_mode')).being.equal(MediaModes.relayed)
expect(session).to.have.property(u('location')).being.equal(u('12.34.56.78'))
self.httpretty_disable()
def test_create_routed_session_with_location_hint(self):
self.httpretty_enable()
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/session/create'),
body=u('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>'),
status=200,
content_type=u('text/xml'))
session = self.opentok.create_session(location='12.34.56.78', media_mode=MediaModes.routed)
if self.mock:
expect(httpretty.last_request().headers[u('x-tb-partner-auth')]).to.equal(self.api_key+u(':')+self.api_secret)
expect(httpretty.last_request().headers[u('user-agent')]).to.contain(u('OpenTok-Python-SDK/')+__version__)
# ordering of keys is non-deterministic, must parse the body to see if it is correct
#.........这里部分代码省略.........
示例10: OpenTok
# 需要导入模块: from opentok import OpenTok [as 别名]
# 或者: from opentok.OpenTok import create_session [as 别名]
from opentok import OpenTok
opentok = OpenTok(45391562, ad29bbb303526b268937e661ae51dfdaf88a8307)
# Create a session that attempts to send streams directly between clients (falling back
# to use the OpenTok TURN server to relay streams if the clients cannot connect):
session = opentok.create_session()
from opentok import MediaModes
# A session that uses the OpenTok Media Router:
session = opentok.create_session(media_mode=MediaModes.routed)
# A session with a location hint
session = opentok.create_session(location=u'12.34.56.78')
# An automatically archived session:
session = opentok.create_session(media_mode=MediaModes.routed, archive_mode=ArchiveModes.always)
# Store this session ID in the database
session_id = session.session_id
# Generate a Token from just a session_id (fetched from a database)
token = opentok.generate_token(session_id)
# Generate a Token by calling the method on the Session (returned from create_session)
token = session.generate_token()
from opentok import Roles
# Set some options in a token
token = session.generate_token(role=Roles.moderator,
expire_time=int(time.time()) + 10,
data=u'name=Johnny')
示例11: Exception
# 需要导入模块: from opentok import OpenTok [as 别名]
# 或者: from opentok.OpenTok import create_session [as 别名]
from flask import Flask, render_template, request, redirect, url_for
from opentok import OpenTok, MediaModes, OutputModes
from email.utils import formatdate
import os, time
try:
api_key = os.environ['API_KEY']
api_secret = os.environ['API_SECRET']
except Exception:
raise Exception('You must define API_KEY and API_SECRET environment variables')
app = Flask(__name__)
opentok = OpenTok(api_key, api_secret)
session = opentok.create_session(media_mode=MediaModes.routed)
@app.template_filter('datefmt')
def datefmt(dt):
return formatdate(time.mktime(dt.timetuple()))
@app.route("/")
def index():
return render_template('index.html')
@app.route("/host")
def host():
key = api_key
session_id = session.session_id
token = opentok.generate_token(session_id)
return render_template('host.html', api_key=key, session_id=session_id, token=token)
@app.route("/participant")
示例12: OpenTokSessionCreationTest
# 需要导入模块: from opentok import OpenTok [as 别名]
# 或者: from opentok.OpenTok import create_session [as 别名]
class OpenTokSessionCreationTest(unittest.TestCase):
def setUp(self):
self.api_key = u("123456")
self.api_secret = u("1234567890abcdef1234567890abcdef1234567890")
self.opentok = OpenTok(self.api_key, self.api_secret)
@httpretty.activate
def test_create_default_session(self):
httpretty.register_uri(
httpretty.POST,
u("https://api.opentok.com/session/create"),
body=u(
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>'
),
status=200,
content_type=u("text/xml"),
)
session = self.opentok.create_session()
validate_jwt_header(self, httpretty.last_request().headers[u("x-opentok-auth")])
expect(httpretty.last_request().headers[u("user-agent")]).to(contain(u("OpenTok-Python-SDK/") + __version__))
body = parse_qs(httpretty.last_request().body)
expect(body).to(have_key(b("p2p.preference"), [b("enabled")]))
expect(body).to(have_key(b("archiveMode"), [b("manual")]))
expect(session).to(be_a(Session))
expect(session).to(
have_property(
u("session_id"), u("1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg")
)
)
expect(session).to(have_property(u("media_mode"), MediaModes.relayed))
expect(session).to(have_property(u("location"), None))
@httpretty.activate
def test_create_routed_session(self):
httpretty.register_uri(
httpretty.POST,
u("https://api.opentok.com/session/create"),
body=u(
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>'
),
status=200,
content_type=u("text/xml"),
)
session = self.opentok.create_session(media_mode=MediaModes.routed)
validate_jwt_header(self, httpretty.last_request().headers[u("x-opentok-auth")])
expect(httpretty.last_request().headers[u("user-agent")]).to(contain(u("OpenTok-Python-SDK/") + __version__))
body = parse_qs(httpretty.last_request().body)
expect(body).to(have_key(b("p2p.preference"), [b("disabled")]))
expect(body).to(have_key(b("archiveMode"), [b("manual")]))
expect(session).to(be_a(Session))
expect(session).to(
have_property(
u("session_id"), u("1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg")
)
)
expect(session).to(have_property(u("media_mode"), MediaModes.routed))
expect(session).to(have_property(u("location"), None))
@httpretty.activate
def test_create_session_with_location_hint(self):
httpretty.register_uri(
httpretty.POST,
u("https://api.opentok.com/session/create"),
body=u(
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>'
),
status=200,
content_type=u("text/xml"),
)
session = self.opentok.create_session(location="12.34.56.78")
validate_jwt_header(self, httpretty.last_request().headers[u("x-opentok-auth")])
expect(httpretty.last_request().headers[u("user-agent")]).to(contain(u("OpenTok-Python-SDK/") + __version__))
# ordering of keys is non-deterministic, must parse the body to see if it is correct
body = parse_qs(httpretty.last_request().body)
expect(body).to(have_key(b("location"), [b("12.34.56.78")]))
expect(body).to(have_key(b("p2p.preference"), [b("enabled")]))
expect(session).to(be_a(Session))
expect(session).to(
have_property(
u("session_id"), u("1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg")
)
)
expect(session).to(have_property(u("media_mode"), MediaModes.relayed))
expect(session).to(have_property(u("location"), u("12.34.56.78")))
@httpretty.activate
def test_create_routed_session_with_location_hint(self):
httpretty.register_uri(
httpretty.POST,
u("https://api.opentok.com/session/create"),
body=u(
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>'
),
status=200,
#.........这里部分代码省略.........
示例13: test_timeout
# 需要导入模块: from opentok import OpenTok [as 别名]
# 或者: from opentok.OpenTok import create_session [as 别名]
def test_timeout(self):
opentok = OpenTok(self.api_key, self.api_secret, timeout=1)
opentok.create_session()