MediaStream未处理的承诺拒绝:[object DOMError](在Safari 11中) [英] MediaStream Unhandled Promise Rejection: [object DOMError] (in Safari 11)

查看:282
本文介绍了MediaStream未处理的承诺拒绝:[object DOMError](在Safari 11中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面的方法中在Safari Tech Preview 11中获得了未处理的承诺拒绝以初始化WebRTC。具体来说,当我将 MediaStream 分配给视频元素时会发生这种情况: video.srcObject = event.stream; - 堆栈跟踪显示此行是抛出异常的行。我无法使用 try / catch来捕获异常。

I am getting an Unhandled Promise Rejection in Safari Tech Preview 11 in my method below to initialize WebRTC. Specifically, it occurs when I assign the MediaStream to the video element like this: video.srcObject = event.stream; - the stack trace shows that this line is the one that threw the exception. I have not been able to catch the exception using try/catch.

异常仅发生在Safari 11中(在Chrome中不会出现。)

The exception is only occurring in Safari 11 (does not occur in Chrome).

以下是方法:

initWebRTC(p){
    var self = this;
    return new Promise((resolve, reject) => {

      self.state.connection = new RTCMultiConnection();
      self.state.connection.socketMessageEvent = 'webrtc-firebase';
      self.state.connection.setCustomSocketHandler(FirebaseConnection);
      self.state.connection.firebase = 'webrtc-firebase'; 
      self.state.connection.enableFileSharing = true; 
      self.state.connection.session = {
        audio: true,
        video: true,
        data: true
      };
      self.state.connection.sdpConstraints.mandatory = {
        OfferToReceiveAudio: true,
        OfferToReceiveVideo: true
      };
      self.state.connection.onstream = function(event) {
          console.log('event.mediaElement',event.mediaElement);
          console.log('event.stream',event.stream);

          var videoContainer = document.getElementById('videoContainer');
          var video = event.mediaElement;
          if (!window.safari){
            var source = document.createElement("source");
            source.srcObject = event.stream;
            video.appendChild(source);
          } else { // Safari
            try{
              video.srcObject = event.stream; // this is the line that throws the exception
            }catch(e){ //unable to catch the exception
              console.log('exception',e);
            }
          }
          videoContainer.appendChild(video);

          var playPromise = video.play();
          if (playPromise !== undefined) { // not a Promise in some browsers
            playPromise.catch(function(error) {
            });
          }
          setTimeout(function() {
            var playPromise = video.play();
            if (playPromise !== undefined) {
              playPromise.catch(function(error) {
              });
            }
          }, 5000);
      };
      resolve();
    });
  }

不确定这是否有帮助,但这里有追踪:

Not sure if this helps, but here is the trace:

[Error] Unhandled Promise Rejection: [object DOMError]
    (anonymous function)
    rejectPromise
    onstream (index.js:5787) // this is the video.srcObject = event.stream; line
    (anonymous function) (RTCMultiConnection.js:4092)
    getRMCMediaElement (RTCMultiConnection.js:1113)
    onGettingLocalMedia (RTCMultiConnection.js:4064)
    onGettingLocalMedia (RTCMultiConnection.js:4984)
    streaming (RTCMultiConnection.js:3289)
    (anonymous function) (RTCMultiConnection.js:3358)
    promiseReactionJob

任何帮助将不胜感激。谢谢!

Any help would be appreciated. Thanks!

推荐答案

我不知道这是否适合你,但我有类似的问题,修复是添加了视频标签的静音属性,之后一切都恢复正常,希望它有所帮助。

I don't know if this can work for you but I had a similar issue, the fix was add the 'muted' attribute to the video tag, after that everything is working again, hope it helps.

这篇关于MediaStream未处理的承诺拒绝:[object DOMError](在Safari 11中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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