當前位置: 首頁>>代碼示例>>Python>>正文


Python OpenTok.start_broadcast方法代碼示例

本文整理匯總了Python中opentok.OpenTok.start_broadcast方法的典型用法代碼示例。如果您正苦於以下問題:Python OpenTok.start_broadcast方法的具體用法?Python OpenTok.start_broadcast怎麽用?Python OpenTok.start_broadcast使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在opentok.OpenTok的用法示例。


在下文中一共展示了OpenTok.start_broadcast方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: OpenTokBroadcastTest

# 需要導入模塊: from opentok import OpenTok [as 別名]
# 或者: from opentok.OpenTok import start_broadcast [as 別名]
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,代碼行數:103,代碼來源:test_broadcast.py


注:本文中的opentok.OpenTok.start_broadcast方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。