2016-07-27 54 views
0

我想在iOS(9.3)与 cordova-plugin-opentokjs( https://www.npmjs.com/package/cordova-plugin-opentokjs cordova-plugin-iosrtc上工作的双向视频聊天。我正在使用cordova 6.3.0和OpenTok 2.8.1。我遇到的问题是,当我开始了我的视频从用户流得到一个错误如下:OpenTok与科尔多瓦错误1013媒体资源不适合

[Error] TypeError: undefined is not a constructor (evaluating 'new global.AudioContext()') 
[Error] OT.exception :: title: Connection Failed (1013) msg: OT.Subscriber PeerConnection Error: There was an unexpected problem with the Video Stream: The media resource indicated by the src attribute was not suitable. 
[Error] No message (2) 
[Error] OT.exception :: title: Unexpected Server Response (2001) msg: Unexpected server response. Try this operation again later. 

出版商流正常工作......至少我可以看到自己(而其他用户看不到我)。有任何想法吗?

下面是一些相关的代码:

this.onDeviceReady = function() { 

    if (window.device.platform === 'iOS') { 
    cordova.plugins.iosrtc.registerGlobals(); 
    } 
}; 

当我转到视频页面怎么办?(打电话initializeSession):

... 
initializePublisher: function() { 
    var self = this; 
    if (Globals.debug) 
    console.log("initializePublisher"); 

    if (!this.videoInputDevices || this.videoInputDevices.length === 0) 
    return; 

    var inputDevice = this.videoInputDevices[this.currentVideoDevice]; 
    if (!inputDevice || !inputDevice.deviceId) 
    return; 

    var $contianer = $('#openTokVideoContainer .mnOpenTokPublisherContainer'); 
    $contianer.empty(); 

    var $div = $('<div id="openTokPublisherStream"></div>'); 
    $contianer.append($div); 

    this.publisher = OT.initPublisher('openTokPublisherStream', { 
    width: '100%', 
    height: '100%', 
    fitMode: 'contain', 
    videoSource: inputDevice.deviceId, 
    mirror: (this.currentVideoDevice === 0) 
    }); 

    this.publisher.on('streamCreated', function(e) { 
    var stream = e.stream, 
     streamId = stream.streamId, 
     $div = $('#openTokVideoContainer .mnOpenTokPublisherContainer > *'); 

    $div.attr('data-stream', streamId); 
    console.log("Publisher stream: ", streamId); 
    }); 

    this.session.publish(this.publisher); 
}, 
initializeSession: function() { 
    var config = this.config, 
     self = this; 

    if (Globals.debug) 
    console.log("initializeSession"); 

    if (Globals.debug) 
    console.log("INIT SESSION " + config.sessionId + " TOKEN" + config.token); 

    this.session = OT.initSession(config.apiKey, config.sessionId); 
    this.session.on('streamCreated', function(e) { 
    var config = self.config; 
    if (Globals.debug) 
     console.log("onSessionConnected"); 

    self.subscribeToStream(e.stream, 'mnOpenTokSubscriberContainer'); 

    if (Globals.debug) 
     console.log("Stream created "); 
    }); 

    this.session.on('streamDestroyed', function(e) { 
    self.closeAllStreamSubscriptions(e.stream); 
    }); 

    this.session.connect(config.token, function (e) { 
    if (!self.publisher) { 
     self.getVideoDevices().then(function() { 
     self.initializePublisher(); 
     }); 
    } 
    }); 

    if (Globals.debug) 
    console.log("initializeSession"); 
},... 

帮助?

编辑:经过大量的头部猛击,插件更新等,我现在已经把它给我下面的错误(和公布的视频不再工作):

[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new t({type:"offer",sdp:l.content.sdp})') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] TypeError: undefined is not a constructor (evaluating 'new u(n.content)') 
[Error] OT.Publisher.onStreamAvailableError TypeError: Unknown Error while getting user media 
[Error] OT.exception :: title: Unable to Publish (1500) msg: GetUserMedia 
[Error] No message (2) 
[Error] No message (2) 
[Error] OT.exception :: title: Unexpected Server Response (2001) msg: Unexpected server response. Try this operation again later. 

回答

0

我认为这个问题是当OpenTok库在该时间点包含在index.html中时,WebRTC API仍未在全局范围内注册。在执行cordova.plugins.iosrtc.registerGlobals()之后,应该加载OpenTok库。

使用在身体的结束下面的脚本中的index.html加载的动态库OpenTok:

<script type="text/javascript"> 
    document.addEventListener("deviceready", function(){ 
    // cordova-plugin-device provides the device object 
    if (device && device.platform === 'iOS') { 
     cordova.plugins.iosrtc.registerGlobals(); 
    } 

    // Insert OpenTok library after the device is ready 
    var s = document.createElement('script'); 
    s.setAttribute('src', 'https://static.opentok.com/v2/js/opentok.min.js'); 
    document.body.appendChild(s); 
    }, false); 
</script>