5

我正在使用 opentok 并连接到广播服务并在页面底部获取 Flash 播放器的对象。

我怎样才能把它放在一个特定的div..

这是我用来连接到 opentol API 的代码

function initiatecall() {
            if (session != undefined) {
                if (!iscalled) {
                    session.addEventListener("sessionConnected", sessionConnectedHandler);
                    session.addEventListener("streamCreated", streamCreatedHandler);
                    session.connect("21457612", token_id); // Replace with your API key and token. See https://dashboard.tokbox.com/projects
                    // and https://dashboard.tokbox.com/projects
                    iscalled = true;

                    $.ajax({
                        data: '{"ChatId":"' + chat_id + '","NurseId":"' + nurse_id + '","DeviceType":"Browser"}',
                        type: "POST",
                        dataType: "json",
                        contentType: "application/json;charset=utf-8",
                        url: "someurl.asmx/MakeCall",
                        success: function (data) { initiatecall(chat_id, session_id, token_id); },
                        eror: function (a, b, c) { alert(a.responseText); }
                    });

                }
            } else {
                alert("Session Expired!!");
            }
        }

        function sessionConnectedHandler(event) {
            subscribeToStreams(event.streams);
            session.publish();
        }

        function streamCreatedHandler(event) {
            subscribeToStreams(event.streams);
        }

        function subscribeToStreams(streams) {
            for (i = 0; i < streams.length; i++) {
                var stream = streams[i];
                if (stream.connection.connectionId != session.connection.connectionId) {
                    session.subscribe(stream);
                }
            }
        }

        function exceptionHandler(event) {
            alert("Exception: " + event.code + "::" + event.message);
        }


        </script>
    <!--End of code-->
    <!--Signal R-->
    <script type="text/javascript">
        $(function () {

            //$.hubConnection.app.MapHubs(new HubConfiguration { EnableCrossDomain = true });
            // Proxy created on the fly
            var chat = $.connection.chat
            //var chat = $.connection.WebPushNotification;
            //alert(chat);
            // Start the connection
            //            $.connection.hub.start();
            //port 1935
            $.connection.hub.start({ transport: 'auto' }, function () {
                //alert('connected');
                $("#info").append("<br/>Hub Started..");
                initiatecall();
                $("#info").append("<br/>Call Initiated..");
                chat.send(chat_id + ',' + session_id + ',' + token_id + ',' + '<%=Session["UserId"].ToString() %>');
                $("#info").append("<br/>Broadcasted Message..");
                //$('#MainContent_connected').text('Connected to chat room');
            });

            // Declare a function on the chat hub so the server can invoke it
            chat.addMessage = function (message) {
                //alert(message);
                //$('#messages').append('<li>' + message + '</li>');
            };
        });

    </script>

我采取了一个 div 来显示所有进度。

 <div id="info">
        </div>

它将我连接到我的视频并请求许可,但它占据了自己的位置,而不是根据我的设计。

4

2 回答 2

2

我认为您应该添加参数replaceElementId并将其值设置为应该替换为播放器的 div id。示例:如果要在#container div 中加载播放器,则在#container 中定义一个div #replaceElementId,它将被播放器替换:

<div id="container">
  <div id="replaceElementId"></div>
</div>
于 2013-06-03T18:03:50.240 回答
0

您必须包含将在您的 DOM 中替换的元素的 ID(例如replaceElementId

<div id="container">
   <div id="replaceElementId"></div>
</div>

修改你的session.subscribe

function subscribeToStreams(streams) {
    for (i = 0; i < streams.length; i++) {
        var stream = streams[i];
        if (stream.connection.connectionId != session.connection.connectionId) {
            //This is where you have to make changes
            //session.subscribe(stream);

              session.subscribe(stream, "replaceElementId", 
                  { width:640, height:480 } );
        }
    }
}

如您所见,您甚至可以定义自己的视频流大小或其他 GUI 更改。

更多信息在官方文档TokBox API:Session

于 2013-12-08T20:26:10.603 回答