Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenTok Api Broadcasted video placement in web page

I am using opentok and connected to the broadcast service and getting object of flash player at the bottom of the page.

How can i place it in a particular div..

This is the code i am using to connect to 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>

I have taken a div to show all the progress.

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

It connect me to my videos and ask for the permission but it takes its own place not according to my design.

like image 737
Tarun Gupta Avatar asked Nov 02 '22 21:11

Tarun Gupta


1 Answers

I think you should add the parameter replaceElementId and set its value to a div's id that should be replaced with the player. Example: If you want to load the player inside the #container div you define a div #replaceElementId inside the #container that will be replaced with the player:

<div id="container">
  <div id="replaceElementId"></div>
</div>
like image 62
sjkm Avatar answered Nov 11 '22 06:11

sjkm