2017-06-06 232 views
1

假設我們有webRTC從A到B的連接。 B在窗戶中看到他自己的攝像頭。 是否可以在顯示自己的網絡攝像頭的B窗口上查看A鼠標箭頭? (所以如果Alice與Bob連接,Alice可以使用他的指針向Bob表明Bob在Bob的廚房裏的勺子在哪裏)。WebRTC鼠標指針

+0

WebRTC沒有定義這一點,您必須在單獨的頻道中共享這些數據。 – deceze

+0

這個問題與WebRTC無關,你的解決方案可以用Javascript來實現。恐怕這將很難實施。你到目前爲止嘗試了什麼? –

+0

我只是想知道是否有可能,還沒有開發出來...我認爲開發它很簡單,只是爲了好玩... – Diego

回答

0

這個問題與WebRTC無關:您的解決方案可以使用Javascript實現,但恐怕很難實現。

我會建議打開另一個同行或通道從一個客戶端到另一個,併發送鼠標指針座標在canvas.onmousemove事件。

1

使用一個data channel發送鼠標指針的座標,從A到B:

var pc1 = new RTCPeerConnection(), pc2 = new RTCPeerConnection(); 
 

 
pc1.onicecandidate = e => pc2.addIceCandidate(e.candidate); 
 
pc2.onicecandidate = e => pc1.addIceCandidate(e.candidate); 
 
pc1.onnegotiationneeded = e => 
 
    pc1.createOffer().then(d => pc1.setLocalDescription(d)) 
 
    .then(() => pc2.setRemoteDescription(pc1.localDescription)) 
 
    .then(() => pc2.createAnswer()).then(d => pc2.setLocalDescription(d)) 
 
    .then(() => pc1.setRemoteDescription(pc2.localDescription)) 
 
    .catch(e => console.log(e)); 
 

 
var dc = pc1.createDataChannel("mouse position"); 
 
document.onmousemove = e => dc.send(e.x + ", " + e.y); 
 

 
pc2.ondatachannel = ({channel}) => channel.onmessage = e => console.log(e.data);
<div id="div"></div> 
 
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>

然後使其在JavaScript上的另一端。低延遲在同伴交互中很重要。