我正在使用angular 4并试图创建一对多的屏幕共享功能,但我无法让单个广播工作。我创建了一个chrome扩展来从desktopCapture获取媒体流。该提议正在从广播公司发送给请求通过node / express通过socket.io加入流的用户。 offer对象使请求用户没有问题(我可以看到),但当我在提供上调用signal时,我收到以下错误。
我正在使用simple-peer。
我的错误是Error: signal() called with invalid signal data
at u.signal
来自广播公司的代码:
selectScreen() {
this._window.postMessage('get-sourceId', 'http://localhost:4200/*');
this._window.addEventListener('message', (event) => {
if (event.data.hasOwnProperty('sourceId')) {
localStorage.setItem('DT_SourceId', event.data.sourceId); // now add to items constraints in getUserMedia()
this.screenId = localStorage.getItem('DT_SourceId');
}
else {
//console.log(event.data);
}
});
}
testScreenShare() {
let peerx: any;
let constraints = {
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: this.screenId
}
}
};
this.n.getUserMedia = (this.n.getUserMedia || this.n.webKitGetUserMedia || this.n.mozGetUserMedia || this.n.msGetUserMedia);
this.n.getUserMedia(constraints, (stream) => {
this.stream = stream;
this.video.src = URL.createObjectURL(stream);
this.video.play();
peerx = new SimplePeer({
initiator: location.hash === '#vidInit',
trickle: false,
stream: stream
});
peerx.on('signal', (data) => {
this.targetPeer = data;
localStorage.setItem('offer', JSON.stringify(data)); //used for testing
});
this.peer = peerx;
console.log(this.peer);
}, (err) => {
console.error('failed to get stream', err);
});
}

用户在优惠上调用signal()的代码:
ngAfterViewInit(){
this.socketService.onRecieveFeedOffer().subscribe(offer => {
this.offer = offer;
console.log(offer);
this.peer = new SimplePeer({
initiator: location.hash === '#vidInit',
trickle: false
});
this.peer.on('signal', (data) => {
console.log(data);
});
this.peer.on('stream', (stream) => {
this.stream.src = URL.createObjectURL(stream);
this.stream.play();
console.log('stream: ' + stream);
});
});
console.log(this.peer);
}
connect(){
console.log(JSON.stringify(this.offer));
this.peer.signal(this.offer);
}

此帖子中为了易读性而提供字符串化的商品对象:
{"offer":"{\"type\":\"offer\",\"sdp\":\"v=0\\r\\no=- 4425143461398787910 2 IN IP4 127.0.0.1\\r\\ns=-\\r\\nt=0 0\\r\\na=group:BUNDLE video data\\r\\na=msid-semantic: WMS d35381fe-536d-42e6-a265-a832569174f3\\r\\nm=video 64059 UDP/TLS/RTP/SAVPF 96 98 100 102 127 97 99 101 125\\r\\nc=IN IP4 174.19.208.27\\r\\na=rtcp:9 IN IP4 0.0.0.0\\r\\na=candidate:3519778999 1 udp 2122255103 2001::9d38:90d7:8f5:37b4:3f57:fe83 64058 typ host generation 0 network-id 2 network-cost 50\\r\\na=candidate:1174899823 1 udp 2122194687 192.168.1.124 64059 typ host generation 0 network-id 1\\r\\na=candidate:3343878875 1 udp 1685987071 174.19.208.27 64059 typ srflx raddr 192.168.1.124 rport 64059 generation 0 network-id 1\\r\\na=candidate:2672323655 1 tcp 1518275327 2001::9d38:90d7:8f5:37b4:3f57:fe83 9 typ host tcptype active generation 0 network-id 2 network-cost 50\\r\\na=candidate:142897311 1 tcp 1518214911 192.168.1.124 9 typ host tcptype active generation 0 network-id 1\\r\\na=ice-ufrag:vsZ8\\r\\na=ice-pwd:ZGZ14zkaV4S5F2ScB2SjFpxZ\\r\\na=fingerprint:sha-256 FC:20:BD:29:12:1B:9D:7C:D2:D0:C5:F5:F1:7E:F4:72:C8:CF:4A:71:C1:79:42:29:5A:B6:E6:F8:FE:72:3F:CD\\r\\na=setup:actpass\\r\\na=mid:video\\r\\na=extmap:2 urn:ietf:params:rtp-hdrext:toffset\\r\\na=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\\r\\na=extmap:4 urn:3gpp:video-orientation\\r\\na=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\\r\\na=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay\\r\\na=sendrecv\\r\\na=rtcp-mux\\r\\na=rtcp-rsize\\r\\na=rtpmap:96 VP8/90000\\r\\na=rtcp-fb:96 ccm fir\\r\\na=rtcp-fb:96 nack\\r\\na=rtcp-fb:96 nack pli\\r\\na=rtcp-fb:96 goog-remb\\r\\na=rtcp-fb:96 transport-cc\\r\\na=rtpmap:98 VP9/90000\\r\\na=rtcp-fb:98 ccm fir\\r\\na=rtcp-fb:98 nack\\r\\na=rtcp-fb:98 nack pli\\r\\na=rtcp-fb:98 goog-remb\\r\\na=rtcp-fb:98 transport-cc\\r\\na=rtpmap:100 H264/90000\\r\\na=rtcp-fb:100 ccm fir\\r\\na=rtcp-fb:100 nack\\r\\na=rtcp-fb:100 nack pli\\r\\na=rtcp-fb:100 goog-remb\\r\\na=rtcp-fb:100 transport-cc\\r\\na=fmtp:100 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f\\r\\na=rtpmap:102 red/90000\\r\\na=rtpmap:127 ulpfec/90000\\r\\na=rtpmap:97 rtx/90000\\r\\na=fmtp:97 apt=96\\r\\na=rtpmap:99 rtx/90000\\r\\na=fmtp:99 apt=98\\r\\na=rtpmap:101 rtx/90000\\r\\na=fmtp:101 apt=100\\r\\na=rtpmap:125 rtx/90000\\r\\na=fmtp:125 apt=102\\r\\na=ssrc-group:FID 2041336394 3480224473\\r\\na=ssrc:2041336394 cname:zKUDUdcCRunL6cDe\\r\\na=ssrc:2041336394 msid:d35381fe-536d-42e6-a265-a832569174f3 cd05cea6-a836-4386-862c-dc83953dba02\\r\\na=ssrc:2041336394 mslabel:d35381fe-536d-42e6-a265-a832569174f3\\r\\na=ssrc:2041336394 label:cd05cea6-a836-4386-862c-dc83953dba02\\r\\na=ssrc:3480224473 cname:zKUDUdcCRunL6cDe\\r\\na=ssrc:3480224473 msid:d35381fe-536d-42e6-a265-a832569174f3 cd05cea6-a836-4386-862c-dc83953dba02\\r\\na=ssrc:3480224473 mslabel:d35381fe-536d-42e6-a265-a832569174f3\\r\\na=ssrc:3480224473 label:cd05cea6-a836-4386-862c-dc83953dba02\\r\\nm=application 64061 DTLS/SCTP 5000\\r\\nc=IN IP4 174.19.208.27\\r\\na=candidate:3519778999 1 udp 2122255103 2001::9d38:90d7:8f5:37b4:3f57:fe83 64060 typ host generation 0 network-id 2 network-cost 50\\r\\na=candidate:1174899823 1 udp 2122194687 192.168.1.124 64061 typ host generation 0 network-id 1\\r\\na=candidate:3343878875 1 udp 1685987071 174.19.208.27 64061 typ srflx raddr 192.168.1.124 rport 64061 generation 0 network-id 1\\r\\na=candidate:2672323655 1 tcp 1518275327 2001::9d38:90d7:8f5:37b4:3f57:fe83 9 typ host tcptype active generation 0 network-id 2 network-cost 50\\r\\na=candidate:142897311 1 tcp 1518214911 192.168.1.124 9 typ host tcptype active generation 0 network-id 1\\r\\na=ice-ufrag:vsZ8\\r\\na=ice-pwd:ZGZ14zkaV4S5F2ScB2SjFpxZ\\r\\na=fingerprint:sha-256 FC:20:BD:29:12:1B:9D:7C:D2:D0:C5:F5:F1:7E:F4:72:C8:CF:4A:71:C1:79:42:29:5A:B6:E6:F8:FE:72:3F:CD\\r\\na=setup:actpass\\r\\na=mid:data\\r\\na=sctpmap:5000 webrtc-datachannel 1024\\r\\n\"}"}
为了节省空间,我不会发布socket.io通信,但是商品对象被成功传送给请求用户。谢谢!