OpenTok建议如何开始建立一个应用程序(OpenTok suggestion how to st

2019-10-20 09:23发布

我试图实现一个基于应用opentok。 谁我心目中的项目是一个应用程序,它一些用户,每个用户可以与运营商从他们的应用程序的手机和运营商说话都留在计算机上。 只需将应用程序必须调用操作,并记录在服务器呼叫。 我觉得这是我必须创建两个应用程序:一个从手机拨打电话,并将其连接到会话,另一个也记录呼叫在电脑上已经宣布会议开幕。 或不? 或可替代的会话操作计算机和人们对已打开可以从手机上会话连接? 如何可以建立一对一的视频聊天,只有一个tokenId? 我怎么能创造每有一人呼叫话务员一次新的呼叫? 如果任何人有意见,教程或有关如何启动请回答提示....在此先感谢

I'have创建基于教程科尔多瓦应用与index.js这里面的代码

 onDeviceReady: function() {

  // Getting OpenTokRTC's room's credentials. 
  // To use your own room in opentokrtc, change cordova to room of your choice
  //   -> ie: https://opentokrtc.com/myroom.json
  // To use your own credentials
  //  replace data.apiKey, data.sid, and data.token with your own

  var apiKey = "xxx";
  var sessionId = "xxxx";
  var token = "xxx";

  // Very simple OpenTok Code for group video chat
  var publisher = TB.initPublisher(apiKey,'myPublisherDiv');

  var session = TB.initSession( apiKey, sessionId ); 
  session.on({
    'streamCreated': function( event ){
        var div = document.createElement('div');
        div.setAttribute('id', 'stream' + event.stream.streamId);
        document.body.appendChild(div);
        session.subscribe( event.stream, div.id, {subscribeToAudio: false} );
    }
  });

  session.connect(token, function(){
    session.publish( publisher );
  });

},
   // Update DOM on a Received Event
   receivedEvent: function(id) {
  }

而在我的网页应用程序,我写从opentok教程采取了这种代码

<div id="myPublisherDiv"></div>
    <script type="text/javascript">
      // Initialize API key, session, and token...
      // Think of a session as a room, and a token as the key to get in to the room
      // Sessions and tokens are generated on your server and passed down to the client
      var apiKey = "xxx";
      var sessionId = "xxx";
      var token = "xxx";

      var publisher = TB.initPublisher(apiKey,'myPublisherDiv');
      var session = TB.initSession(sessionId);

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

      function sessionConnectedHandler(event) {
        var publisher = TB.initPublisher(apiKey, 'myPublisherDiv');
        session.publish(publisher);
      }

    </script>

我的问题是:我怎么能建立与iPhone采取的网页应用程序内的视频流的第二个div? 又是谁混淆了我不少另一件事是:在所有的情况下,我必须设置我的服务器与SDK?

Answer 1:

你可以有每个人都连接到同一会话。 当你connectionCreated事件,将其存储在一个对象。 它的一个人的转弯时,信号他开始发布,然后订阅他的流:

例如,运营商的一面:

var connections = {};
session.on('connectionCreated', function(event){
  connections[event.connection.connectionId] = event.connection.connectionId;
  // Create a button for that stream
});

当操作者点击流,他想连接,

// retrieve streamId from button, disconnect from other streams
session.signal(
  {
    type: "publish", 
    data: "operator", 
    to: connections[connectionIdFromButton]
  }, 
  function(){...}
);

当用户得到的信号,开始发布。

session.on("signal:publish", function(event){
  session.publish(...)
});


文章来源: OpenTok suggestion how to start to build an app