Click here to Skip to main content
15,886,786 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to Connect all the users in a session by providing them separate token under a sessionId, so that they can view each other's streaming. But users can see only their straming. I just need to allocate div on my page for each user with a token connected to any particular sessionId.

This is the code using which users can see their streaming only

C#
<script src="http://static.opentok.com/webrtc/v2.0/js/TB.min.js" ></script>
    <script src="https://static.opentok.com/webrtc/v2.0/js/TB.min.js" ></script>
   <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
   <script type="text/javascript">

    var publisher;
    var session;

    var apiKey = "44686132";


    var sessionId = "1_MX40NDY4NjEzMn4xMjcuMC4wLjF-V2VkIE1hciAxOSAyMDo1ODozNyBQRFQgMjAxNH4wLjAzMTA3MTAwN34";
    var token = document.getElementById("<%= hdn1.ClientID %>").value;


    publisher = TB.initPublisher(apiKey);

    session = TB.initSession(sessionId);

    session.connect(apiKey, token);
    session.addEventListener("sessionConnected",
                           sessionConnectedHandler);


    session.addEventListener("streamCreated",
                           streamCreatedHandler);


    function sessionConnectedHandler(event) {
        alert("sessionConnectedHandler");


        subscribeToStreams(event.streams);
        session.publish(publisher);

    }
        function subscribeToStreams(streams) {

                if (stream.connection.connectionId
               != session.connection.connectionId) {
                    //var streams = event.streams;
                    for (var i = 0; i < streams.length; i++) {
                        var stream = streams[i];

                        var newDivId = "streams" + stream[i].streamId;
                        var newDiv = $('<div />', { id: newDivId });
                        $('body').append(newDiv);
                        if (stream.connection.connectionId
               != session.connection.connectionId) {
                            session.subscribe(stream[i], newDivId);
                        }

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

        }

</script>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900