sergiopaniego / WebRTCiOS

Small WebRTC app for iOS using Swift
Apache License 2.0
19 stars 18 forks source link
ios swift webrtc

WebRTCiOS

Technologies WebRTCapp is a small elaboration that is part of my final degree project. This app aims to be a small video conference app created using mainly WebRTC technology. With it, you can make calls though a web socket connection.

OpenVidu

The app was built based on connecting to OpenVidu , an open source project that provides several libraries implementations to create video conference apps. For more info on whats the project about I highly recommend you to go and check the following links

WebRTCApp

Libraries in the project

WebRTC Library

You can find the code for the WebRTC library right on WebRTC's organization web. I wrote a briefly post on how WebRTC works internally that you can find here. On WebRTC's web you will find how to compile the binaries and generate the library but I chose an already built library called GoogleWebRTC

WebSocket Starscream Library

This library is a WebSocket client designed for Swift. It implementes the protocol definition allowing us to use a WebSocket without having to implement the whole RFC. Link: Starscream Library

How to download the project and run it

If you want to run the project locally, you can download it using the following command. You will need an actual iOS physical device because the emulator doesn't support the video we need to add.

   git clone https://github.com/sergiopaniego/WebRTCapp

As I mentioned above, the app is part of a final degree project and for that reason the address that comes built in the app points to https://demos.openvidu.io/basic-videoconference/. This URL hosts an OpenVidu's demo app that you can use to test that everything works as expected.

Development Environment

How did I developed the app? Tools I used

XCode 9

This is the most commonly used iOS development IDE. You can download it directly from the AppStore.

iPad

As device to test the app I used an iPad with iOS 10.2 installed.

App Permissions

The first time you open the app, it will ask you to give some permissions to the app. The permissions and the reason why we need the is the following:

Understanding the code

Scheme The code is divided in some packages to make the code easier to mantain.

In this part of the code is where the connecting happens, using the address that is built using the fields above.

Once the connection is established, you need to join a room, what it's made as follows

    var joinRoomParams: [String: String] = [:]
    joinRoomParams["recorder"] = "false"
    joinRoomParams[JSONConstants.Metadata] = "{\"clientData\": \"" + participantName + "\"}"
    joinRoomParams["secret"] = "MY_SECRET"
    joinRoomParams["session"] = sessionName
    joinRoomParams["token"] = token
    sendJson(method: "joinRoom", params: joinRoomParams)

Using a JSON using RPC 2.0 with joinRoom method and the params that are shown here you can connect to the room Same process to leave the room, you just have to send

    self.socket?.sendJson(method: "leaveRoom", params: [:])

a JSON RPC 2.0 with the method leaveRoom and empty params.