我正在尝试使用此库(RTCMulticonnection)实现WebRTC,并且在尝试设置' srcObject时遇到Type Error
。在Safari Tech Preview 11中的视频mediaElement上。
相关代码:
if (isSafari) {
//I've tried the 4 ways below to set the srcObject but all cause a Type Error
// mediaElement['srcObject'] = window.URL.createObjectURL(stream); throws type error
// mediaElement['srcObject'] = stream; throws type error
// mediaElement['src'] = window.URL.createObjectURL(stream);
// mediaElement.srcObject = stream; // throws type error
}
当我打印mediaElement
时,我得到:<video></video>
当我打印stream
时,我会得到一个MediaStream
对象。
MediaStream {streamid: "722cfcc7-0687-4265-b266-e81b2abf8398", idInstance: "{\"audio\":{\"mandatory\":{},\"optional\":[{\"bandwidth\":…\":[{\"bandwidth\":4194304},{\"facingMode\":\"user\"}]}}", isVideo: 1, isAudio: false, type: "local", …}
错误
TypeError: Type error
[Error] No message (2)
TypeError: Type error — RTCMultiConnection.js:4089
Object audio: {mandatory: {}, optional: [{bandwidth: 1048576}]}
video: {mandatory: {}, optional: [{bandwidth: 4194304}, {facingMode: "user"}]}
Object Prototype
onMediaError (RTCMultiConnection.js:5215)
onLocalMediaError (RTCMultiConnection.js:806)
onLocalMediaError (RTCMultiConnection.js:4995)
(anonymous function) (RTCMultiConnection.js:3365)
promiseReactionJob
此Type Error
中包含then/catch
:
navigator.mediaDevices.getUserMedia(options.localMediaConstraints).then(function(stream) {
stream.streamid = stream.streamid || stream.id || getRandomString();
stream.idInstance = idInstance;
streaming(stream);
}).catch(function(error) {
options.onLocalMediaError(error, options.localMediaConstraints });