2017-07-25 10 views
4

WebRTCを初期化するために私の方法でSafari Tech Preview 11で未処理のプロミス拒否を取得しています。具体的には、ビデオ要素にMediaStreamを割り当てたときに発生します。video.srcObject = event.stream; - スタックトレースは、この行が例外をスローしたことを示しています。私は例外をキャッチできませんでしたtry/catch.MediaStream未処理プロミス拒否:[オブジェクトDOMError](Safari 11)

例外はSafari 11でのみ発生します(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(); 
    }); 
    } 

わからないが、ここではトレースです:ここで

はメソッドである任意の助けをいただければ幸いです

[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 

。ありがとう!

答えて

2

Safari 11ブロックは、デフォルトで音声付きの動画を自動再生できません(source)。

video要素にautoplay属性が付いていると思います。 srcObjectに設定すると、ビデオが再生され、Safariによってブロックされます。そのため、エラーが表示されます。

autoplayを動画要素から削除すると、playPromise.catchにキャッチすることができます。

1

これがうまくいくかどうかわかりませんが、同様の問題がありました。修正がビデオタグに「ミュート」属性を追加しました。

+0

ありがとうございます。それは働いている。しかし、まだエラーがあります:) –

関連する問題