当前位置: 首页>>代码示例>>Python>>正文


Python opentok.OpenTok类代码示例

本文整理汇总了Python中opentok.OpenTok的典型用法代码示例。如果您正苦于以下问题:Python OpenTok类的具体用法?Python OpenTok怎么用?Python OpenTok使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OpenTok类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: index

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)
开发者ID:raghavtan,项目名称:chat_server,代码行数:28,代码来源:views.py

示例2: post

    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))
开发者ID:ggarber,项目名称:opentok-telephony,代码行数:26,代码来源:web.py

示例3: create_session

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)
开发者ID:fahyik,项目名称:interprefy,代码行数:7,代码来源:views.py

示例4: setUp

    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)
开发者ID:eauge,项目名称:Opentok-Python-SDK,代码行数:11,代码来源:test_session_creation.py

示例5: generate_session_id

    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
开发者ID:laughingwb,项目名称:CloudClass,代码行数:13,代码来源:models.py

示例6: gen_token

def gen_token(request, session_pk=None):
    # make curl to create session
    # 	requrl = request.build_absolute_uri(reverse("tbox:create_session"))
    # 	req = urllib2.Request(requrl)
    # 	res = urllib2.urlopen(req)
    # 	session_id = res.read()
    # GET has to pass the session_pk or passed from room view
    if request.method == "GET" or session_pk:
        res = {}
        if request.GET or session_pk:
            if request.GET:
                session = Session.objects.get(pk=request.GET["session_pk"])
            else:
                session = Session.objects.get(pk=session_pk)

            session_id = session.session_id
            print "token request for session and session id:"
            print session, session_id
            tbox = TokBox.objects.get(pk=1)
            opentok = OpenTok(tbox.api_key, tbox.api_secret)

            # set token parameters: role and data
            print "request by user:"
            print request.user.username
            userprofile = UserProfile.objects.get(username=request.user.username)
            params = {"role": None, "data": "name=" + request.user.username}

            if userprofile.function == "Mod":
                params["role"] = Roles.moderator
            elif userprofile.function == "Pub":
                params["role"] = Roles.publisher
            elif userprofile.function == "Sub":
                params["role"] = Roles.subscriber

            token = opentok.generate_token(session_id, **params)
            print token
            res["token"] = token
            res["success"] = {"status": True, "error": None}
            if request.GET:
                return HttpResponse(json.dumps(res))
            else:
                return json.dumps(res)
        else:
            res["success"] = {"status": False, "error": "no GET data"}
            return HttpResponse(json.dumps(res))

    elif request.method == "POST":
        # need to update session table with connection count
        # need to update connection table with connection id and data
        # will be done through ajax post/tokbox js on room view
        pass
开发者ID:fahyik,项目名称:interprefy,代码行数:51,代码来源:views.py

示例7: get_token_id

    def get_token_id(self, username, role=ROLE_STUDENT):
        opentok = OpenTok(api_key, api_secret)
        session_id = self.session_id

        if not session_id:
            return None

        # Generate a Token from just a session_id (fetched from a database)
        connectionMetadata = '{"role":"' + role + '", "username":"' + username + '"}'

        if role == self.ROLE_TUTOR:
            token_id = opentok.generate_token(session_id, Roles.moderator, None, connectionMetadata)
        else:
            token_id = opentok.generate_token(session_id, Roles.publisher, None, connectionMetadata)
        return token_id
开发者ID:laughingwb,项目名称:CloudClass,代码行数:15,代码来源:models.py

示例8: setUp

    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')

        self.opentok = OpenTok(self.api_key, self.api_secret)
        self.session_id = u('SESSIONID')
开发者ID:eauge,项目名称:Opentok-Python-SDK,代码行数:9,代码来源:test_archive_api.py

示例9: get

    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({}))
开发者ID:ggarber,项目名称:opentok-telephony,代码行数:22,代码来源:web.py

示例10: setUp

 def setUp(self):
     self.api_key = u('123456')
     self.api_secret = u('1234567890abcdef1234567890abcdef1234567890')
     self.session_id = u('1_MX4xMjM0NTZ-flNhdCBNYXIgMTUgMTQ6NDI6MjMgUERUIDIwMTR-MC40OTAxMzAyNX4')
     self.opentok = OpenTok(self.api_key, self.api_secret)
开发者ID:opentok,项目名称:Opentok-Python-SDK,代码行数:5,代码来源:test_token_generation.py

示例11: OpenTokTokenGenerationTest

class OpenTokTokenGenerationTest(unittest.TestCase):
    def setUp(self):
        self.api_key = u('123456')
        self.api_secret = u('1234567890abcdef1234567890abcdef1234567890')
        self.session_id = u('1_MX4xMjM0NTZ-flNhdCBNYXIgMTUgMTQ6NDI6MjMgUERUIDIwMTR-MC40OTAxMzAyNX4')
        self.opentok = OpenTok(self.api_key, self.api_secret)

    def test_generate_plain_token(self):
        token = self.opentok.generate_token(self.session_id)
        assert isinstance(token, text_type)
        assert token_decoder(token)[u('session_id')] == self.session_id
        assert token_signature_validator(token, self.api_secret)

    def test_generate_role_token(self):
        token = self.opentok.generate_token(self.session_id, Roles.moderator)
        assert isinstance(token, text_type)
        assert token_decoder(token)[u('role')] == Roles.moderator.value
        assert token_signature_validator(token, self.api_secret)
        token = self.opentok.generate_token(self.session_id, role=Roles.moderator)
        assert isinstance(token, text_type)
        assert token_decoder(token)[u('role')] == Roles.moderator.value
        assert token_signature_validator(token, self.api_secret)

    def test_generate_expires_token(self):
        # an integer is a valid argument
        expire_time = int(time.time()) + 100
        token = self.opentok.generate_token(self.session_id, expire_time=expire_time)
        assert isinstance(token, text_type)
        assert token_decoder(token)[u('expire_time')] == text_type(expire_time)
        assert token_signature_validator(token, self.api_secret)
        # anything that can be coerced into an integer is also valid
        expire_time = text_type(int(time.time()) + 100)
        token = self.opentok.generate_token(self.session_id, expire_time=expire_time)
        assert isinstance(token, text_type)
        assert token_decoder(token)[u('expire_time')] == expire_time
        assert token_signature_validator(token, self.api_secret)
        # a datetime object is also valid
        if PY2:
            expire_time = datetime.datetime.fromtimestamp(time.time(), pytz.UTC) + datetime.timedelta(days=1)
        if PY3:
            expire_time = datetime.datetime.fromtimestamp(time.time(), datetime.timezone.utc) + datetime.timedelta(days=1)
        token = self.opentok.generate_token(self.session_id, expire_time=expire_time)
        assert isinstance(token, text_type)
        assert token_decoder(token)[u('expire_time')] == text_type(calendar.timegm(expire_time.utctimetuple()))
        assert token_signature_validator(token, self.api_secret)


    def test_generate_data_token(self):
        data = u('name=Johnny')
        token = self.opentok.generate_token(self.session_id, data=data)
        assert isinstance(token, text_type)
        assert token_decoder(token)[u('connection_data')] == data
        assert token_signature_validator(token, self.api_secret)

    def test_generate_initial_layout_class_list(self):
        initial_layout_class_list = [u('focus'), u('small')];
        token = self.opentok.generate_token(self.session_id, initial_layout_class_list=initial_layout_class_list)
        assert isinstance(token, text_type)
        assert sorted(token_decoder(token)[u('initial_layout_class_list')].split(u(' '))) == sorted(initial_layout_class_list)
        assert token_signature_validator(token, self.api_secret)

    def test_generate_no_data_token(self):
        token = self.opentok.generate_token(self.session_id)
        assert isinstance(token, text_type)
        assert u('connection_data') not in token_decoder(token)
        assert token_signature_validator(token, self.api_secret)

    @raises(TypeError)
    def test_does_not_generate_token_without_params(self):
        token = self.opentok.generate_token()

    @raises(TypeError)
    def test_does_not_generate_token_without_session(self):
        token = self.opentok.generate_token(role=Roles.subscriber)

    @raises(OpenTokException)
    def test_does_not_generate_token_invalid_session(self):
        token = self.opentok.generate_token(u('NOT A REAL SESSIONID'))

    @raises(OpenTokException)
    def test_does_not_generate_token_without_api_key_match(self):
        # this session_id has the wrong api_key
        session_id = u('1_MX42NTQzMjF-flNhdCBNYXIgMTUgMTQ6NDI6MjMgUERUIDIwMTR-MC40OTAxMzAyNX4')
        token = self.opentok.generate_token(session_id)
开发者ID:opentok,项目名称:Opentok-Python-SDK,代码行数:84,代码来源:test_token_generation.py

示例12: OpenTokBroadcastTest

class OpenTokBroadcastTest(unittest.TestCase):
    def setUp(self):
        self.api_key = u('123456')
        self.api_secret = u('1234567890abcdef1234567890abcdef1234567890')
        self.opentok = OpenTok(self.api_key, self.api_secret)
        self.session_id = u('2_MX4xMDBfjE0Mzc2NzY1NDgwMTJ-TjMzfn4')

    @httpretty.activate
    def test_start_broadcast(self):
        """
        Test start_broadcast() method
        """
        httpretty.register_uri(
            httpretty.POST,
            u('https://api.opentok.com/v2/project/{0}/broadcast').format(self.api_key),
            body=textwrap.dedent(u("""\
                {
                    "id": "1748b7070a81464c9759c46ad10d3734",
                    "sessionId": "2_MX4xMDBfjE0Mzc2NzY1NDgwMTJ-TjMzfn4",
                    "projectId": 100,
                    "createdAt": 1437676551000,
                    "updatedAt": 1437676551000,
                    "resolution": "640x480",
                    "status": "started",
                    "broadcastUrls": {
                        "hls" : "http://server/fakepath/playlist.m3u8",
                        "rtmp": {
                            "foo": {
                                "serverUrl": "rtmp://myfooserver/myfooapp",
                                "streamName": "myfoostream"
                            },
                            "bar": {
                                "serverUrl": "rtmp://mybarserver/mybarapp",
                                "streamName": "mybarstream"
                            }
                        }
                    }
                }""")),
            status=200,
            content_type=u('application/json')
        )

        options = {
            'layout': {
                'type': 'custom',
                'stylesheet': 'the layout stylesheet (only used with type == custom)'
            },
            'maxDuration': 5400,
            'outputs': {
                'hls': {},
                'rtmp': [{
                    'id': 'foo',
                    'serverUrl': 'rtmp://myfooserver/myfooapp',
                    'streamName': 'myfoostream'
                }, {
                    'id': 'bar',
                    'serverUrl': 'rtmp://mybarserver/mybarapp',
                    'streamName': 'mybarstream'
                }]
            },
            'resolution': '640x480'
        }

        broadcast = self.opentok.start_broadcast(self.session_id, options)
        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__))
        expect(httpretty.last_request().headers[u('content-type')]).to(equal(u('application/json')))
        expect(broadcast).to(be_an(Broadcast))
        expect(broadcast).to(have_property(u('id'), u('1748b7070a81464c9759c46ad10d3734')))
        expect(broadcast).to(have_property(u('sessionId'), u('2_MX4xMDBfjE0Mzc2NzY1NDgwMTJ-TjMzfn4')))
        expect(broadcast).to(have_property(u('projectId'), 100))
        expect(broadcast).to(have_property(u('createdAt'), 1437676551000))
        expect(broadcast).to(have_property(u('updatedAt'), 1437676551000))
        expect(broadcast).to(have_property(u('resolution'), u('640x480')))
        expect(broadcast).to(have_property(u('status'), u('started')))
        expect(list(broadcast.broadcastUrls)).to(have_length(2))
        expect(list(broadcast.broadcastUrls['rtmp'])).to(have_length(2))

    @httpretty.activate
    def test_start_broadcast_only_one_rtmp(self):
        """
        Test start_broadcast() method with only one rtmp
        """
        httpretty.register_uri(
            httpretty.POST,
            u('https://api.opentok.com/v2/project/{0}/broadcast').format(self.api_key),
            body=textwrap.dedent(u("""\
                {
                    "id": "1748b7070a81464c9759c46ad10d3734",
                    "sessionId": "2_MX4xMDBfjE0Mzc2NzY1NDgwMTJ-TjMzfn4",
                    "projectId": 100,
                    "createdAt": 1437676551000,
                    "updatedAt": 1437676551000,
                    "resolution": "640x480",
                    "status": "started",
                    "broadcastUrls": {
                        "hls" : "http://server/fakepath/playlist.m3u8",
                        "rtmp": {
                            "foo": {
#.........这里部分代码省略.........
开发者ID:opentok,项目名称:Opentok-Python-SDK,代码行数:101,代码来源:test_broadcast.py

示例13: OpenTokArchiveApiTest

class OpenTokArchiveApiTest(unittest.TestCase):
    def setUp(self):
        self.api_key = u('123456')
        self.api_secret = u('1234567890abcdef1234567890abcdef1234567890')
        self.session_id = u('SESSIONID')
        self.opentok = OpenTok(self.api_key, self.api_secret)

    @httpretty.activate
    def test_start_archive(self):
        httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/partner/{0}/archive').format(self.api_key),
                               body=textwrap.dedent(u("""\
                                       {
                                          "createdAt" : 1395183243556,
                                          "duration" : 0,
                                          "id" : "30b3ebf1-ba36-4f5b-8def-6f70d9986fe9",
                                          "name" : "",
                                          "partnerId" : 123456,
                                          "reason" : "",
                                          "sessionId" : "SESSIONID",
                                          "size" : 0,
                                          "status" : "started",
                                          "hasAudio": true,
                                          "hasVideo": true,
                                          "outputMode": "composed",
                                          "url" : null
                                        }""")),
                               status=200,
                               content_type=u('application/json'))

        archive = self.opentok.start_archive(self.session_id)

        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().headers[u('content-type')]).to.equal(u('application/json'))
        # non-deterministic json encoding. have to decode to test it properly
        if PY2:
            body = json.loads(httpretty.last_request().body)
        if PY3:
            body = json.loads(httpretty.last_request().body.decode('utf-8'))
        expect(body).to.have.key(u('name')).being.equal(None)
        expect(body).to.have.key(u('sessionId')).being.equal(u('SESSIONID'))
        expect(archive).to.be.an(Archive)
        expect(archive).to.have.property(u('id')).being.equal(u('30b3ebf1-ba36-4f5b-8def-6f70d9986fe9'))
        expect(archive).to.have.property(u('name')).being.equal(u(''))
        expect(archive).to.have.property(u('status')).being.equal(u('started'))
        expect(archive).to.have.property(u('session_id')).being.equal(u('SESSIONID'))
        expect(archive).to.have.property(u('partner_id')).being.equal(123456)
        if PY2:
            created_at = datetime.datetime.fromtimestamp(1395183243, pytz.UTC)
        if PY3:
            created_at = datetime.datetime.fromtimestamp(1395183243, datetime.timezone.utc)
        expect(archive).to.have.property(u('created_at')).being.equal(created_at)
        expect(archive).to.have.property(u('size')).being.equal(0)
        expect(archive).to.have.property(u('duration')).being.equal(0)
        expect(archive).to.have.property(u('has_audio')).being.equal(True)
        expect(archive).to.have.property(u('has_video')).being.equal(True)
        expect(archive).to.have.property(u('url')).being.equal(None)

    @httpretty.activate
    def test_start_archive_with_name(self):
        httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/partner/{0}/archive').format(self.api_key),
                               body=textwrap.dedent(u("""\
                                       {
                                          "createdAt" : 1395183243556,
                                          "duration" : 0,
                                          "id" : "30b3ebf1-ba36-4f5b-8def-6f70d9986fe9",
                                          "name" : "ARCHIVE NAME",
                                          "partnerId" : 123456,
                                          "reason" : "",
                                          "sessionId" : "SESSIONID",
                                          "size" : 0,
                                          "status" : "started",
                                          "hasAudio": true,
                                          "hasVideo": true,
                                          "outputMode": "composed",
                                          "url" : null
                                        }""")),
                               status=200,
                               content_type=u('application/json'))

        archive = self.opentok.start_archive(self.session_id, name=u('ARCHIVE NAME'))

        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().headers[u('content-type')]).to.equal(u('application/json'))
        # non-deterministic json encoding. have to decode to test it properly
        if PY2:
            body = json.loads(httpretty.last_request().body)
        if PY3:
            body = json.loads(httpretty.last_request().body.decode('utf-8'))
        expect(body).to.have.key(u('sessionId')).being.equal(u('SESSIONID'))
        expect(body).to.have.key(u('name')).being.equal(u('ARCHIVE NAME'))
        expect(archive).to.be.an(Archive)
        expect(archive).to.have.property(u('id')).being.equal(u('30b3ebf1-ba36-4f5b-8def-6f70d9986fe9'))
        expect(archive).to.have.property(u('name')).being.equal(u('ARCHIVE NAME'))
        expect(archive).to.have.property(u('status')).being.equal(u('started'))
        expect(archive).to.have.property(u('session_id')).being.equal(u('SESSIONID'))
        expect(archive).to.have.property(u('partner_id')).being.equal(123456)
        if PY2:
            created_at = datetime.datetime.fromtimestamp(1395183243, pytz.UTC)
#.........这里部分代码省略.........
开发者ID:Armin-Smailzade,项目名称:Opentok-Python-SDK,代码行数:101,代码来源:test_archive_api.py

示例14: test_timeout

 def test_timeout(self):
     with self.assertRaises(RequestError):
         opentok = OpenTok(self.api_key, self.api_secret, timeout=5)
         opentok.create_session()
开发者ID:wyzantinc,项目名称:Opentok-Python-SDK,代码行数:4,代码来源:test_session_creation.py

示例15: OpenTokSessionCreationTest

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'))
#.........这里部分代码省略.........
开发者ID:wyzantinc,项目名称:Opentok-Python-SDK,代码行数:101,代码来源:test_session_creation.py


注:本文中的opentok.OpenTok类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。