Tinode supports peer to peer video calls over WebRTC. The diagram below illustrates a call establishment flow between two users Alice
and Bob
. The flow is conceptually similar to SIP, but uses native Tinode messages for transport.
Notes:
- All communication is proxied by the Tinode server.
- Client-to-server events are dispatched in
{note}
messages with the call'stopic
andseq
fields set. - Server-to-client data are routed in
{info}
messages onme
topic with the call'ssrc
(call topic) andseq
fields set (and/or in data push notifications). - It's assumed that both Alice and Bob may have multiple devices.
The flow may be broken down into 4 phases:
- Steps 1-5: call initiation
- Steps 6-7: call acceptance
- Steps 8-15: metadata exchange
- Steps 16-17: call termination
sequenceDiagram
participant A as Alice
participant S as Tinode Server
participant B as Bob
rect rgb(212, 242, 255)
Note over A: Alice initiates a call
A->>S: 1. {pub head:webrtc=started}
S->>A: 2. {ctrl params:seq=123}
S->>+B: 3. {info seq=123 event=invite}
S-->>B: or {data seq=123 head:webrtc=started} <br/> push notification
B->>-S: 4. {note seq=123 event=ringing}
S->>A: 5. {info seq=123 event=ringing}
end
Note over S: Bob's client ringing<br/>waiting for Bob to accept
rect rgb(212, 242, 255)
Note over B: Bob accepts the call
B->>S: 6. {note seq=123 event=accept}
S->>A: 7a. {info seq=123 event=accept}
S->>B: 7b. {info seq=123 event=accept}
S-->>B: {data seq=124 head:webrtc=accepted,replace=123}
S-->>A: {data seq=124 head:webrtc=accepted,replace=123}
end
Note over S: Call accepted, peer metadata exchange
A->>S: 8. {note seq=123 event=offer}
S->>+B: 9. {info seq=123 event=offer}
B->>-S: 10. {note seq=123 event=answer}
S->>A: 11. {info seq=123 event=answer}
rect rgb(212, 242, 255)
Note over S: ICE candidate exchange
loop
A->>S: 12. {note seq=123 event=ice-candidate}
S->>B: 13. {info seq=123 event=ice-candidate}
B->>S: 14. {note seq=123 event=ice-candidate}
S->>A: 15. {info seq=123 event=ice-candidate}
end
end
Note over S: Call established<br/>conversation in progress
rect rgb(212, 242, 255)
Note over S: Call termination
alt
A->>S: 16a. {note seq=123 event=hang-up}
B->>S: 16b. {note seq=123 event=hang-up}
end
alt
S->>B: 17a. {info seq=123 event=hang-up}
S->>A: 17b. {info seq=123 event=hang-up}
end
S-->>B: {data seq=125 head:webrtc=finished,replace=123}
S-->>A: {data seq=125 head:webrtc=finished,replace=123}
end
Alice
initiates a call by posting a video call message (withwebrtc=started
header)- Server replies with a
{ctrl}
message containing theseq
id of the call. - Server routes an
invite
event message toBob
(all clients).
- Additionally, server sends data push notifications containing a
webrtc=started
field toBob
. - Upon receiving either of the above,
Bob
displays the incoming call UI.
Bob
replies with aringing
event.- Server relays the
ringing
event toAlice
. The latter now plays the ringing sound.
- Note that
Alice
may receive multipleringing
events as each separate instance ofBob
acknowldges receipt of the call invitation separately. Alice
and server will wait for up to a server configured timeout forBob
to accept the call and then hang up.- At this point, the call is officially initiated.
Bob
accepts the call by sending anaccept
event.- (a) and (b): Server routes
accept
event toAlice
andBob
.
- Additionally, the server broadcasts a replacement for the call data message with
webrtc=accepted
header. - Push notifications for the replacement message are sent as well.
Bob
's sessions except the one that accepted the call may silently dismiss the incoming call UI.- At this point, the call is officially accepted.
Alice
sends anoffer
event containing an SDP payload.- Server routes the
offer
toBob
. - Upon receiving the
offer
,Bob
replies with ananswer
event containing an SDP payload. - Server forwards
Bob
'sanswer
event toAlice
.
Steps 12-15 are Ice candidate exchange between Alice
and Bob
.
At this point the call is officially established. Alice
and Bob
can see and hear each other.
Alice
sends ahang-up
event to server.- Server routes a
hang-up
event toBob
.
Additionally, the server broadcasts a replacement for the call data message with webrtc=finished
header.
Push notifications for the replacement message are sent as well.