当订户加入Opentok.js中的聊天时,session.on(“StreamCreated”,functon())不会被触发

时间:2015-12-17 04:47:17

标签: javascript php opentok

我正在使用下面视频会议的Opentok.js库是Js代码。 但是Session.on(“streamCreated”,function(event){});订户加入会议室时不会触发。

我正在使用中转基础聊天。

感谢任何形式的帮助。提前致谢 。

<script src="http://static.opentok.com/webrtc/v2.2/js/opentok.js"></script>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>

<script>
var ping=function(pid){$.ajax({type:'POST',url:'https://hlg.tokbox.com/prod/logging/ClientEvent',
data:JSON.stringify({action:'sk_init',partner_id: pid,payload:{id:'link',l:'php',v:'1.0.0'}}),
processData:false, contentType: 'application/json'});};
</script>
<script>

var apiKey = "<?php echo $data['apiKey']?>",
session_id = "<?php echo $data['sessionId']?>",
token = "<?php echo $data['token'] ?>",
property = { insertMode: "append" },
publisher = OT.initPublisher("myPublisher", property),
session = OT.initSession(apiKey, session_id);

session.connect( token, function(err) {
  if(!err) { session.publish(publisher); }
  //userType = session.connection.data;

});

console.log("before stream created for subscriber",session.on());

session.on("streamCreated", function(event) {
  alert("stream" + event.stream);
  session.subscribe(event.stream, 'subscriber',  property);
});

console.log("after stream created for subscriber");

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

ping(apiKey);

和Php服务器端

$opentok = new OpenTok('45433942', 'f4c2aa60dc4febfb78fc5eead865adb46c613035');
    $session = $opentok->createSession();
    $sessionId = $session->getSessionId();
    $token = $opentok->generateToken($sessionId);

    $data = array(
            'apiKey'=>'45433942',
            'token'=>$token,
            'sessionId'=>$sessionId
        );
    return View::make('opentok/index')->with('data',$data);

0 个答案:

没有答案