# How do AppRTC work in WebRTC mechanism ?

AppRTC is a WebRTC open source repo that implements two clients who can communicate with each other with webcam and voice. That works like a chatting room but only two persons in the room. When there have two clients in the room, they will exchange some messages for building a p2p connection and starting communication.

But it doesn’t the whole WebRTC main mechanism that is only data exchange and manages the connection process. So AppRTC is a sample system when the coder implements WebRTC, help them decrease the development time.

> [AppRTC Repo is here!](https://github.com/webrtc/apprtc) [WebRTC mechanism](https://www.w3.org/TR/webrtc/#peer-to-peer-connections)

**Manipulate AppRTC** First, one client joins a room and waiting for the other client to join. At once, there are two clients in the room, they can chat with each other.

![](https://cdn-images-1.medium.com/max/800/1*SBGnOfjTNDU7TciZLndoLg.gif)

**The AppRTC Implement (not include p2p mechanism)** We divided into two part to illustrate AppRTC work. The first client join room and the second client join room.

The first client join room:

1. Get / for getting AppRTC home page.
2. Post /join/:room\_id for registry room id into AppRTC and getting a Client ID to registry Signal Server.
3. Use Client ID to registry Signal Server (Collider Server)

   send /ws {cmd: "register", "roomid":"", “clientid”: ""}
4. POST /message/:room\_id/:client\_id for storing p2p connection message into AppRTC Server.(About sdp、(ICE) candidate messages)
5. Waiting another sdp and (ICE) Candidate message.

![](https://cdn-images-1.medium.com/max/800/1*d7Ukv4SqzjIzhaqObqWVJA.png)

The second client join room:

1. Get / for getting AppRTC home page.
2. Post /join/:room\_id for registry room id into AppRTC and getting a Client ID to registry Signal Server and **first client p2p connection cache(sdp, (ICE candidate)**
3. According to cache generates a new p2p connection message and send it by WebSocket to the first client
4. Two clients communicate with each other through p2p.

![](https://cdn-images-1.medium.com/max/800/1*6QtDR_rI77tXj4lcQcM5nw.png)

The Collider Server API

The Collider server has two functions. one is HTTP, the other one is WebSocket. The WebSocket API is for the client to communicate with each other like registry and send these actions. The HTTP API is for AppRTC server sync room status.

#### WebSocket API

| numbers | parameters                                                          | illustration                     |
| ------- | ------------------------------------------------------------------- | -------------------------------- |
| 1       | {cmd: "register", "roomid":"", "clientid": ""}                      | join room                        |
| 2       | {cmd: "send", "roomid":"", "clientid": "", "msg":"**JSON string**"} | send message to the other client |

#### HTTP API

| numbers |            parameters            | illustration                |
| :-----: | :------------------------------: | --------------------------- |
|    1    | post /bye/:room\_id:/:client\_id | delete collider room status |

**Conclusion** In the AppRTC demo application, it follows [Broker Architecture](https://medium.com/%E5%BE%AE%E5%B3%AF%E9%A3%9B%E7%BF%94/broker%E5%88%B0%E5%BA%95%E6%98%AF%E4%BB%80%E9%BA%BC-707ddc05268a) to coordinate p2p message exchange. Though the key-point is not **the sdp and (ICE) candidate** message exchanged method, but it still important to manage the exchange process. So if you read AppRTC open source, this article can help you modify this project.
