Signaling

To implement signaling we will use socket.io. In this case we have to consider who is starting a call.

Request call

  • Only a teacher can start a call to a student.

To do that the teacher will emit an event request-call to a server. The server will save their offer and forward this offer to the target student using the same event name.

// RECEIVE
{
    "callID": "string",
    "sdp": {
        "type": "offer",
        "sdp": "string containing session configuration"
    }
}

Respond call

  • When a student receives a request call a student shoud return an answer with respond-call event.
// SEND
{
    "callID": "string",
    "sdp": {
        "type": "answer",
        "sdp": "string containing session configuration"
    }
}

New ICE candidate

  • When a remote peer sends to you a new ICE candidate you will receive an event named new-ice-candidate.
// RECEIVE
{
    "candidate": "string",
    "sdpMid": "string",
    "sdpMLineIndex": "number",
    // ... More information about ice candidates
}

*For Unity check types

Call created

  • When offerer and requested client shared offer and answer SDP then the server emits an event named call-created.
// RECEIVE
{
    "callID": "uuid string"
}

New answer ICE candidate

  • To send a new ICE candidate use this event new-answer-ice-candidate.
// EMIT
{
    "callID": "string",
    "candidate": {
        "candidate": "string",
        "sdpMid": "string",
        "sdpMLineIndex": "number",
        // ... More information about ice candidates
    }
}

Steps to stablish a webrtc connection

sequenceDiagram participant C1 as Client1 participant S as Server participant C2 as Client2 C1->>+S: Request call to C2 S->>+C2: Send request call C2->>-S: Send response to C1 S->>-C1: Send response S->>C1: Call created S->>C2: Call created C2-->C1: Exchange ICE candidate

1- Teacher request to a user to start a call

First a teacher sends to a student a request to start a call using the event request-call. The students receives and offer SDP.

2- Student accepts the call

Then the student should create a RTCPeerConnection and attach a media streamt to it. Then with offer SDP should create an answer and send this answer using the event respond-call.

Note

Before create the answer is important to attach a stream to RTC connection. If you don’t do that is possible that ICE candidates cannot be created.

3- Call is created now can share ICE candidates

Once student and teacher shared SDPs the server will notify both using call-created event that a call is created then student and teacher can set local descriptions and share incoming ICE candidates.