Open sandabu opened 2 years ago
I think it's general to omit px
and muted
property is boolean type so you can also omit the value.
<video id="user-video" width="500" height="500" muted></video>
These variables also should be declared with const
.
https://github.com/riad-binary/webrtc_p2p_basic_app/blob/c80bc879e49e28c448c86e93c65f8a077c037e73/public/chat.js#L1-L7
I prefer to declare DOM selector variable appended with prefix $
like jQuery.
const $lobby = document.getElementById("video-chat-lobby");
It's easier to understand this variable is DOM.
Good validation.
I think it's better to check also empty string(" "
) here.
https://github.com/riad-binary/webrtc_p2p_basic_app/blob/c80bc879e49e28c448c86e93c65f8a077c037e73/public/chat.js#L30-L31
There is no logic when creator
is false
so you can use Return Early Pattern
https://medium.com/swlh/return-early-pattern-3d18a41bba8
if(!creator) {
return;
}
RTCPeerConnectrion.setLocalDescription(offer)
returns Promise.
It's better to complete setting local description before emitting.
rtcPeerConnection
.createOffer()
.then((offer) => {
return rtcPeerConnection.setLocalDescription(offer);
})
.then(() => {
socket.emit("offer", offer, roomName);
})
And async/await
way can make it simple.
try{
const offer = await rtcPeerConnection.createOffer();
await rtcPeerConnection.setLocalDescription(offer);
socket.emit("offer", offer, roomName);
}catch(e){
console.error(e);
}
You did a good job!
On starting new web project next time, please install a linter such as eslint via npm.
const
is better here because this variable is not reassigned and redefined and we often use() => {}
(arrow-functions) on arguments. https://github.com/riad-binary/webrtc_p2p_basic_app/blob/c80bc879e49e28c448c86e93c65f8a077c037e73/index.js#L7