2014-02-07 44 views
1

下面的代碼完全可以在桌面瀏覽器上正常工作,但不適用於我的手機縫隙/ cordova應用程序。我的輸出說連接和iOS接收流,但沒有任何顯示在我的應用程序的正文。這是我index.js文件:爲什麼在我的科爾多瓦/ phonegap應用程序中不顯示用戶視頻opentok?

var app = { 
initialize: function() { 
    this.bindEvents(); 
}, 

bindEvents: function() { 
    document.addEventListener('deviceready', this.onDeviceReady, false); 
}, 
onDeviceReady: function() { 
    app.receivedEvent('deviceready'); 

//////////////////////////////// 
//////Start of my opentok code//////////// 

    var apiKey = '21692492'; 

    var sessionId = '2_MX4yMTY5MTQ5Mn5-RnJpIEZlYiAwNyAwODozMjozOSBQU1QgMjAxNH4wLjIwMzc2MDV-'; 

    var token = 'T1==cGFydG5lcl9pZD0yMTY5MTQ5MiZzaWc9ZWUxMTNjNjZiYjlkNWI4NTkwZTE2MDZiMjM0MzFkOWYyMzhiYzgxNjpzZXNzaW9uX2lkPTJfTVg0eU1UWTVNVFE1TW41LVJuSnBJRVpsWWlBd055QXdPRG96TWpvek9TQlFVMVFnTWpBeE5INHdMakl3TXpjMk1EVi0mY3JlYXRlX3RpbWU9MTM5MTc5MDgwNSZyb2xlPXB1Ymxpc2hlciZub25jZT0xMzkxNzkwODA1LjIzMzk0MTE4MzcyJmV4cGlyZV90aW1lPTEzOTQzODI4MDU='; 


    function connectedHandler(event) { 
     for (var i = 0; i < event.streams.length; i++) { 
      var newDiv = $('<div />', {id:event.streams[i].streamId}); 
      $('body').append(newDiv); 
      session.subscribe(event.streams[i], event.streams[i].streamId,{}); 
     } 
    } 


    var session = TB.initSession(sessionId); 

    session.addEventListener('sessionConnected', connectedHandler); 

    session.connect(apiKey, token); 

//////End of my opentok code//////////// 
//////////////////////////////////////////////// 
}, 

receivedEvent: function(id) { 
    var parentElement = document.getElementById(id); 
    var listeningElement = parentElement.querySelector('.listening'); 
    var receivedElement = parentElement.querySelector('.received'); 

    listeningElement.setAttribute('style', 'display:none;'); 
    receivedElement.setAttribute('style', 'display:block;'); 

    console.log('Received Event: ' + id); 
} 
}; 

這是輸出我得到:

2014-02-07 11:44:19.407 HelloCordova[2377:60b] iOS Connected to Session 
2014-02-07 11:44:19.408 HelloCordova[2377:60b] object for session is { 
connection =  { 
    connectionId = "4B191468-46D5-4414-A46A-5C97376D6F2E"; 
    creationTime = 1391791459; 
}; 
connectionCount = 0; 
environment = production; 
sessionConnectionStatus = OTSessionConnectionStatusConnected; 
sessionId = "2_MX4yMTY5MTQ5Mn5-RnJpIEZlYiAwNyAwODozMjozOSBQU1QgMjAxNH4wLjIwMzc2MDV-"; 
streams =  (
); 
} 
2014-02-07 11:44:19.456 HelloCordova[2377:60b] iOS Received Stream 

有誰知道這是爲什麼不工作,我需要改變嗎?

回答

0

Cordova插件是在OpenTok JS 2.2之後建模的。在這個新版本中,有幾個變化。首先,'addEventListener'已被重命名爲'on'。要添加事件,你可以這樣做:

session.on({ 
    'sessionConnected': function(event){ 
    session.publish(publisher); 
    }, 
    'streamCreated': function(event){ 
    var newDiv = $('<div />', {id:event.stream.streamId}); 
    $('body').append(newDiv); 
    session.subscribe(event.stream, event.stream.streamId, {}); 
    } 
}) 

注意以下變化:
*的addEventListener不再存在
*上sessionConnected事件,您不再獲取會話中現有流的數組。會話中的每個流都將觸發一個streamCreated事件。
* streamCreated事件回調參數只有1個流元素。本次活動將再次爲每個流

這裏被觸發的來臨V2.2更改的列表:http://labs.tokbox.com/javascript-2.2

我增加了一些工作示例代碼,供你參考:https://github.com/songz/cordova-plugin-opentok/blob/master/README.md#sample-code

相關問題