2015-04-16 29 views
0

我正試圖在瀏覽器之間進行1:1的opentok對接。與OpenTok 1:1對話出現的問題

有兩個角色:
一個發佈者邀請和一個被邀請者。目的是讓這兩個人進行1:1的對話。

會話正確進行,被邀請者連接到流。被邀請者接收發布者的視頻流並將其添加到其容器中。然後他開始發佈到同一個會話。 (yay)...

但是,發佈者只能看到他自己的視頻。我根本無法檢測到被邀請者發佈的流。

繼承人的出版商功能:

function startVideoHost(sessionId, apiKey, token) { 
    var replacementElementId = "localVideo"; 
    if (OT.checkSystemRequirements() == 1) { 
    publisher = OT.initPublisher(replacementElementId); 
    publisher.on({ 
     streamCreated: function (event) { 
      $('.videoWindow').show(); 
      console.log("Publisher started streaming."); 
     }, 
     streamDestroyed: function (event) { 
      console.log("Publisher stopped streaming. Reason: " 
       + event.reason); 
     } 
    }); 

// this is kinda where id hope the publisher would detect the guest stream 

    session = OT.initSession(apiKey, sessionId); 
    session.on("streamCreated", function(event) { 
    session.subscribe(event.stream, remoteVideos); 
    }); 
    session.connect(token, function (error) { 
     if (session.capabilities.publish == 1) { 
      session.publish(publisher); 
     } else { 
      console.log("You cannot publish an audio-video stream."); 
     } 
    }); 
} else { 
    console.log("The client does not support WebRTC."); 
} 
} 

而且繼承人受邀功能:

function startVideoGuest(sessionId, apiKey, token) { 
    if (OT.checkSystemRequirements() == 1) { 
    var session = OT.initSession(apiKey, sessionId); 
    session.on("streamCreated", function(event) { 
    session.subscribe(event.stream, remoteVideos); 
    }); 
    session.connect(token, function(error) { 
    if (error) { 
     console.log("Error connecting: ", error.code, error.message); 
    } else { 
     $('.videoWindow').show(); 
     var replacementElementId = "localVideo"; 
     publisher = OT.initPublisher(replacementElementId); 
     publisher.on({ 
      streamCreated: function (event) { 
      console.log("Publisher started streaming."); 
     }, 
     streamDestroyed: function (event) { 
      console.log("Publisher stopped streaming. Reason: " 
       + event.reason); 
     } 
    }); 
     console.log("Connected to the session."); 
    } 
    }); 
} 

} 

沒有人有任何想法,爲什麼我不是讓被邀請者視頻流返回給發佈者?

回答

1

我能看到的一個問題是,'被邀請者'調用OT.initPublisher(),它觸發被邀請者網絡攝像頭開始錄製視頻並在被邀請者的DOM中顯示該流,但被邀請者從未真正將該網絡攝像頭髮布到會話中。這就是被邀請者可以在瀏覽器中看到視頻的原因,但「主持人」從未在會話中看到該視頻。

一個解決方案是撥打session.publish(publisher)裏面的session.connect回調,你的function startVideoGuest。我已修改您的代碼如下:

//..... 
streamDestroyed: function (event) { 
     console.log("Publisher stopped streaming. Reason: " 
      + event.reason); 
    } 
}); 
    console.log("Connected to the session."); 
    //I have added the line below 
    session.publish(publisher); 
//...... 

一個說明:任何時候會話中的客戶端發送視頻和/或音頻,他們是發佈者。因爲您似乎需要「受邀者」將視頻發送給「主持人」,「受邀者」也是發佈商,因此必須致電session.publish。客戶可以同時成爲發佈者和訂閱者。它們是可選屬性,而不是獨佔角色。

+0

現貨,謝謝一堆:) – Havihavi