OpenTok建议如何开始构建应用 [英] OpenTok suggestion how to start to build an app

查看:92
本文介绍了OpenTok建议如何开始构建应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现基于opentok的应用. 我想到的项目是一些订阅者使用的应用程序,每个订阅者都可以通过其应用程序电话与运营商交谈,而该运营商必须留在计算机上. 简单地,该应用程序必须呼叫运营商并在服务器中记录该呼叫. 我认为我必须创建两个应用程序:一个可以通过电话拨打电话并将其连接到会话,另一个可以在计算机上打开该会话并记录通话的应用程序.或不? 或者,会话已经在操作员计算机上打开,人们可以通过电话在会话上进行连接? 如何仅使用一个tokenId创建一对一的视频聊天?每当有人呼叫接线员时,我如何创建新呼叫? 如果有人对如何开始有任何建议,教程或技巧,请回答.... 预先感谢

I'm trying to achieve an app opentok based. The project who i have in mind is an app which some subscribers, every subscriber can talk with an operator from their app phone and the operator have to stay on computer. Simply the app have to call an operator and record the call in server. I think which i have to create two apps: one which make the call from the phone and connect it to the session and another with the session already opened on the computer which also record the call. Or not? Or alternatively the session already open on the operator computers and the people can connect at the session from the phone? How is possible to create an one to one videochat with only one tokenId? How i can create a new call every time which one person call an operator? If anyone have suggestion, tutorial or tips about how to start please answer.... Thanks in advance

我已经基于教程创建了cordova应用,并在index.js中包含了这段代码

I'have create the cordova app based on tutorial with this code inside the 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教程

And in my web page app i've write this code taken from the opentok tutorial

<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来设置服务器吗?

My question is: how i can build a second div with the video stream taken from iphone inside the web page app? And another thing who confuse me a lot is: in all case i have to setup my server with the SDK?

推荐答案

您可以让每个人都连接到同一会话.当您获得connectionCreated事件时,将其存储在一个对象中.轮到一个人时,指示他开始发布,然后订阅他的信息流:

You can have everybody connect to the same session. When you get connectionCreated event, store it in an object. When its a person's turn, signal him to start publishing and then subscribe to his stream:

例如,在操作员方面:

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

操作员单击要连接的流时,

When operator clicks on the stream that he wants to connect to,

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

当用户收到信号后,就开始发布.

When user gets the signal, start publishing.

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

这篇关于OpenTok建议如何开始构建应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆