The Design and Architecture of a Webrtc Application
Total Page:16
File Type:pdf, Size:1020Kb
Bachelor Thesis 15 credits The design and architecture of a WebRTC application Simon Holm Alexander Lööf Degree: Bachelor’s degree 180 hp Supervisor: Mia Persson Field: Computer science Examiner: Joseph Bugeja Program: Information architecture & Computer science Date of final seminar: 4/6/2019 Abstract The aim of this thesis is to investigate existing design patterns for WebRTC applications in order to achieve a scalable, performant and efficient WebRTC application that keeps streams unique. Further, this thesis shows how these can be implemented using JavaScript technologies. Through a literature study, we conclude that the design patterns full mesh using a signaling server and star topology with a media server that relays streams, called Selective Forwarding Unit (SFU). Both these design patterns have quality attributes that are desirable. We propose an approach of combining these patterns in the same application in order to achieve a scalable application that can fit a broad spectrum of use cases while being efficient. As full mesh is performant and cost-effective in comparison to an SFU but does not scale well with increasing number of participants, we investigate ways to optimize a full mesh session to use it as long as possible before converting a session to using an SFU. We came up with a way to optimize a full mesh session by limiting the bandwidth used for the media streams which reduces the CPU usage for the clients. The proposed approach of combining full mesh and an SFU is implemented based on a previous WebRTC application and a high-level description of how that was achieved is included in this thesis. We perform an experiment where we measure the client’s CPU usage using the above-mentioned approaches in order to reinforce our findings. The result show that limiting the bandwidth of media streams can increase the possible number of participants in a full mesh session and that it is possible to transfer an ongoing session from full mesh to an SFU and back again. We conclude that combining these patterns in the same application is a viable strategy when creating a WebRTC application. Keywords: Real-time communication, WebRTC, peer to peer, performance, scalability, efficiency, design patterns, architecture. 2 List of Acronyms WebRTC - Web Real-time Communication. A framework that provides browsers and mobile applications with Real-Time Communications via simple APIs. SDP - Session Description Protocol. A protocol to negotiate sessions parameters, typically used in WebRTC. NAT - Network Address Translation. A method of remapping one IP address space into another by modifying network address information in the IP header of packets while they are in transit across a traffic routing device. Used for conserving global address space due to IPv4 address exhaustion. STUN - Session Traversal Utilities for NAT. A standardized set of methods, including a network protocol, for traversal of network address translator (NAT) gateways in applications of real-time voice, video, messaging, and other interactive communications. TURN - Traversal Using Relays around NAT. A protocol that assists in a traversal of network address translators (NAT) or firewalls for multimedia applications. ICE - Interactive Connectivity Establishment. A technique used in computer networking to find ways for two computers to talk to each other as directly as possible in peer-to-peer networking. WebSocket - A protocol that provides full-duplex communication channels over a single TCP connection. SFU - Selective Forwarding Unit. A media server that relays streams. REST - Representational State Transfer. An architecture style for designing networked applications. MCU - Multipoint Control Unit. A device commonly used to bridge videoconferencing connections. QoE - Quality of Experience. VOIP - short for “Voice over I.P” SDK - Software development kit. A set of software development tools for a certain software package. API - Application programming interface. A set of subroutine definitions, communication protocols and tools for building software. Table of Contents 1 INTRODUCTION ....................................................................................................... 1 1.1 MOTIVATION ............................................................................................................................................. 1 1.2 AIM AND RESEARCH QUESTIONS .................................................................................................................... 1 1.3 APPROACH AND LIMITATIONS ....................................................................................................................... 2 1.4 STRUCTURE ............................................................................................................................................... 3 2 THEORETICAL BACKGROUND ............................................................................ 4 2.1 AN INTRODUCTION TO WEBRTC ................................................................................................................... 4 2.1.1 What is WebRTC ................................................................................................................................ 4 2.1.2 Requirements for WebRTC from a developer perspective ............................................................ 4 2.1.3 A generic WebRTC application flow .............................................................................................. 6 3 METHOD ..................................................................................................................... 9 3.1 LITERATURE STUDY ...................................................................................................................................... 9 3.2 IMPLEMENTATION....................................................................................................................................... 9 3.3 EXPERIMENT AND IMPLEMENTATION EVALUATION ........................................................................................... 11 4 RESULTS................................................................................................................... 12 4.1 LITERATURE STUDY .................................................................................................................................... 12 4.1.1 Full mesh - Peer to Peer .............................................................................................................. 12 4.1.2 MCU ............................................................................................................................................ 13 4.1.3 SFU .............................................................................................................................................. 13 4.1.4 Overview comparing the discovered design patterns ..................................................................... 14 4.1.5 Proposing a combined pattern .................................................................................................... 15 4.2 DESIGN AND IMPLEMENTATION ................................................................................................................... 15 4.3 EXPERIMENT ............................................................................................................................................ 20 5 ANALYSIS AND DISCUSSION .............................................................................. 22 5.1 ANALYSIS ................................................................................................................................................ 22 5.1.1 Literature study ............................................................................................................................... 22 5.1.2 Implementation ............................................................................................................................... 22 5.1.3 Experiment ...................................................................................................................................... 23 5.2 DISCUSSION ............................................................................................................................................. 24 6 CONCLUSION AND FURTHER RESEARCH ..................................................... 26 6.1 CONCLUSION ........................................................................................................................................... 26 6.2 FURTHER RESEARCH .................................................................................................................................. 26 7 REFERENCES .......................................................................................................... 27 8 LIST OF ACRONYMS .............................................................................................. 29 9 APPENDIX ................................................................................................................ 30 9.1 EXPERIMENT CALCULATIONS ....................................................................................................................... 30 1 Introduction 1.1 Motivation The internet and modern information technology enable individuals and businesses to stay connected with each other and work together remotely using online meeting and collaborative applications. WebRTC is a technology that enables such applications to be developed for modern browsers by allowing the browser to communicate in real time utilizing peer