【发布时间】:2018-05-24 16:33:14
【问题描述】:
我正在研究点对点视频聊天,我关注谷歌 Codelab 进行学习。我只是从 html 5 Rocks 网站阅读了关于 webrtc 的理论部分,所以我不太了解套接字连接的编码部分.
代码实验室的链接是 https://codelabs.developers.google.com/codelabs/webrtc-web/#2 请访问步骤 05。
我不明白“main.js”文件中的以下部分。
socket.on('message', function(message) {
console.log('Client received message:', message);
if (message === 'got user media') {
maybeStart();
} else if (message.type === 'offer') {
if (!isInitiator && !isStarted) {
maybeStart();
}
pc.setRemoteDescription(new RTCSessionDescription(message));
doAnswer();
} else if (message.type === 'answer' && isStarted) {
pc.setRemoteDescription(new RTCSessionDescription(message));
} else if (message.type === 'candidate' && isStarted) {
var candidate = new RTCIceCandidate({
sdpMLineIndex: message.label,
candidate: message.candidate
});
pc.addIceCandidate(candidate);
} else if (message === 'bye' && isStarted) {
handleRemoteHangup();
}
});
所以我的问题是
1)什么是message.type === 'offer' 什么是offer 它是什么类型的字符串? 'answer' 和 'candidate' 也一样。
你能告诉我这段代码是如何工作的吗?
【问题讨论】:
标签: javascript node.js socket.io