About using socket, io for socket connection in webrtc


Sats17

I'm working on peer-to-peer video chat and I'm following Google Codelab to learn. I just read the theoretical part about webrtc from the html 5 rock site, so I don't know much about the encoding part of the socket connection.

The link to the codelab is https://codelabs.developers.google.com/codelabs/webrtc-web/#2, please visit step 05.

And I don't understand the following in the "main.js" file.

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();
  }
});

So my question is

1) What is message.type === 'offer' and what kind of string is offered? Same goes for "answer" and "candidate".

Can you tell me how this code works?

video room

WebRTC uses signaling to create connections. Signaling is basically messages sent back and forth between peers via websockets. You can use something like sockets.io for this.

Signaling helps to establish a connection and keep it connected. Signaling sends Session Description Protocol information back and forth.

Signaling or socket messages used to establish a connection consist of an offer and an answer.

It looks like this:

  • Participant 1 (P1) joins to let people know they are above the socket
  • Participant 2 (P2) responds to the offer sent over the socket
  • P1 receives the offer and stores P2's details as remote description
  • P1 sends back an answer with its details P2 receives this answer and stores P1's details as a remote description
  • connected!

This information is called Session Description Protocol (SDP). It contains the following information:

  • Multimedia type (audio, video, screen sharing)
  • Media Capability
  • Shipping address
  • metadata

If you are interested, there is a detailed explanation on my blog.

https://blog.videorooms.io/2018/05/mesh-architecture.html

Sockets just send JSON back and forth between two people trying to connect to each other.

Hope that helps.

Related


About using socket, io for socket connection in webrtc

Sats17 I'm working on peer-to-peer video chat and I'm following Google Codelab to learn. I just read the theoretical part about webrtc from the html 5 rock site, so I don't know much about the encoding part of the socket connection. The link to the codelab is

About using socket, io for socket connection in webrtc

Sats17 I'm working on peer-to-peer video chat and I'm following Google Codelab to learn. I just read the theoretical part about webrtc from the html 5 rock site, so I don't know much about the encoding part of the socket connection. The link to the codelab is

About using socket, io for socket connection in webrtc

Sats17 I'm working on peer-to-peer video chat and I'm following Google Codelab to learn. I just read the theoretical part about webrtc from the html 5 rock site, so I don't know much about the encoding part of the socket connection. The link to the codelab is

Authenticate socket io connection using JWT

el_pup_le : How to verify socket.io connection? My application uses the login endpoint from another server (python) to get the token, how can I use that token whenever the user opens a socket connection on the node side? io.on('connection', function(socket) {

Authenticate socket io connection using JWT

el_pup_le : How to verify socket.io connection? My application uses the login endpoint from another server (python) to get a token, how can I use that token whenever the user opens a socket connection on the node side? io.on('connection', function(socket) {

Authenticate socket io connection using JWT

el_pup_le : How to verify socket.io connection? My application uses the login endpoint from another server (python) to get a token, how can I use that token whenever the user opens a socket connection on the node side? io.on('connection', function(socket) {

Android socket connection using socket.io version 0.9.0

h_patel I'm having trouble connecting to a socket server. I am currently working on an android project in which I need to connect a socket server in the application. I'm currently referencing the ios app code so it's easy to build the android version of the ap

Android socket connection using socket.io version 0.9.0

h_patel I'm having trouble connecting to a socket server. I am currently working on an android project in which I need to connect a socket server in the application. I'm currently referencing the ios app code so it's easy to build the android version of the ap

Replacing Socket io with Pubnub (WebRTC)

Jerry Fox I'm looking into using Pubnub's service to establish a WebRTC connection between video peers. I'd like to avoid using the socket io I'm currently using, although I just can't find any good examples of how to do this. Now socket io is handling events

Screen sharing issue in WebRTC/nodejs using socket.io

Thibaud I'm working on a video conferencing application and I can't seem to get screen sharing to work, getting the error "mediaTypeError: Cannot read property of undefined (reading 'getSender')". Screen sharing starts, but nothing is shared Here is my server

Socket IO connection fails on Android

marsupial I am trying to create a simple chat using Socket IO, Android and Node. When I run the app and try to connect to the server it always fails with a timeout error and I can't figure out why. Here is the node code: app = require('express')() http = requi

Socket IO connection fails on Android

marsupial I am trying to create a simple chat using Socket IO, Android and Node. When I run the app and try to connect to the server it always fails with a timeout error and I can't figure out why. Here is the node code: app = require('express')() http = requi

Unwanted Socket.IO connection

Brandon Blackwell My socket.io server is running the connect module for the index page when I navigate to a subpage of the site. Here is the full console log for navigating to www.example.com/query authenticated updated ==> { GbLZ5jxHz0S5uyNNAAAA: { user: 'yrn

Socket.IO connection not established

Rahul I am unable to establish a connection to Socket.IO in node server. My server is successfully started using Socket.IO, but during the connection to the Socket, I am not getting the console log. this.server.listen(this.port, () => { console.log(`S

Socket IO connection fails on Android

marsupial I am trying to create a simple chat using Socket IO, Android and Node. When I run the app and try to connect to the server it always fails with a timeout error and I can't figure out why. Here is the node code: app = require('express')() http = requi

Unwanted Socket.IO connection

Brandon Blackwell My socket.io server is running the connect module for the index page when I navigate to a subpage of the site. Here is the full console log for navigating to www.example.com/query authenticated updated ==> { GbLZ5jxHz0S5uyNNAAAA: { user: 'yrn

Socket IO connection fails on Android

marsupial I am trying to create a simple chat using Socket IO, Android and Node. When I run the app and try to connect to the server it always fails with a timeout error and I can't figure out why. Here is the node code: app = require('express')() http = requi

Socket.IO connection not established

Rahul I am unable to establish a connection to Socket.IO in node server. My server is successfully started using Socket.IO, but during the connection to the Socket, I am not getting the console log. this.server.listen(this.port, () => { console.log(`S

Socket IO connection fails on Android

marsupial I am trying to create a simple chat using Socket IO, Android and Node. When I run the app and try to connect to the server it always fails with a timeout error and I can't figure out why. Here is the node code: app = require('express')() http = requi

Socket IO connection fails on Android

marsupial I am trying to create a simple chat using Socket IO, Android and Node. When I run the app and try to connect to the server it always fails with a timeout error and I can't figure out why. Here is the node code: app = require('express')() http = requi

Unwanted Socket.IO connection

Brandon Blackwell My socket.io server is running the connect module for the index page when I navigate to a subpage of the site. Here is the full console log for navigating to www.example.com/query authenticated updated ==> { GbLZ5jxHz0S5uyNNAAAA: { user: 'yrn

socket io complains about CORS

Tomar 99 I started with the netty socketio demo. The demo works locally. However, if I run it on the server, it doesn't work anymore (even if the client and server are on the same machine). Chrome, FF and IE complain Cross-Origin Request Blocked: Same Origin P

socket io complains about CORS

Tomar 99 I started with the netty socketio demo. The demo works locally. However, if I run it on the server, it doesn't work anymore (even if the client and server are on the same machine). Chrome, FF and IE complain Cross-Origin Request Blocked: Same Origin P

socket io complains about CORS

Tomar 99 I started with the netty socketio demo. The demo works locally. However, if I run it on the server, it doesn't work anymore (even if the client and server are on the same machine). Chrome, FF and IE complain Cross-Origin Request Blocked: Same Origin P

socket io complains about CORS

Tomar 99 I started with the netty socketio demo. The demo works locally. However, if I run it on the server, it doesn't work anymore (even if the client and server are on the same machine). Chrome, FF and IE complain Cross-Origin Request Blocked: Same Origin P

socket io complains about CORS

Tomar 99 I started with the netty socketio demo. The demo works locally. However, if I run it on the server, it doesn't work anymore (even if the client and server are on the same machine). Chrome, FF and IE complain Cross-Origin Request Blocked: Same Origin P

webRTC socket.io error Transport unknown

xylan I am getting the following error from socket.io server. "Transportation unknown" Can you tell me why this error occurs? I use this signaling server Connection.socketURL = ' https://rtcmulticonnection.herokuapp.com:443/ '; My code used to work before but

webRTC socket.io error Transport unknown

xylan I am getting the following error from socket.io server. "Transportation unknown" Can you tell me why this error occurs? I use this signaling server Connection.socketURL = ' https://rtcmulticonnection.herokuapp.com:443/ '; My code used to work before but

webRTC socket.io error Transport unknown

xylan I am getting the following error from socket.io server. "Transportation unknown" Can you tell me why this error occurs? I use this signaling server Connection.socketURL = ' https://rtcmulticonnection.herokuapp.com:443/ '; My code used to work before but