Full text
MASTER THESIS TITLE: Study, design and implementation of WebRTC for a real-time multimedia messaging application MASTER DEGREE: Master in Science in Telecommunication Engineering & Management AUTHOR: Xavier Lagunas Calpe DIRECTOR: Juan López Rubio DATE: February, 17th 2017
Tirol: Study, design and implementation of WebRTC for a real-time multimedia messaging application Autor: Xavier Lagunas Calpe Director: Juan López Rubio Data: 17 de Febrer de 2017 Resum Les xarxes socials ja han deixat de ser un fenomen, i són, avui dia, no tan sols una realitat sinó quelcom indispensable. Durant el seu creixement i consolidació internet ha patit una gran transformació degut al tipus de continguts més demandats. Compartir imatges, vídeos o fins i tot establir una trucada amb una altra persona són tasques que un usuari normal pot fer diverses vegades al dia. Aquesta transició només pot anar de la mà de noves tecnologies que no només simplifiquin aquestes tasques sinó que, degut a la irrupció dels smartphones, a més treballin sota unes condicions determinades com consum de dades i bateria moderat. Les videoconferències a la xarxa, i en general, l’enviament de fluxos de data multimèdia ha anat sempre lligat de la mà de tecnologies de software tancat, com ara Macromedia Flash que requerien per part de l’usuari consumidor de la instal·lació d’un connector al seu navegador web. Sota aquestes premisses, aquest projecte es centra en la investigació de WebRTC com a tecnologia capaç de realitzar vídeo conferencies entre usuaris sense la necessitat de cap connector al navegador. Per contrastar els coneixements obtinguts a l’estudi es proposa addicionalment, el disseny, arquitectura i implementació d’una aplicació que sigui capaç de dur a terme aquesta tasca.
Title: Study, design and implementation of WebRTC for a real-time multimedia messaging application Author: Xavier Lagunas Calpe Director: Juan López Rubio Date: February, 17th 2017 Overview Social networks are no longer a phenomenon; nowadays it is not that they are a reality but have become something indispensable. During its growth and consolidations period internet has suffered a great transformation due to the new kind of most demanded content. Sharing images, videos or even making calls with another user are tasks that an average user would make several times a day. This transition could only happen thanks to new technologies that not only simplify those tasks but, due to handheld devices’ irruption, would work successfully under reasonable data and battery consumption rates. Videoconferences over the network and multimedia data streams in general have always gone hand in hand of closed software products like Macromedia Flash, for instance, that required of a plugin installation on the browser by the end user. Under those premises, this project will focus on the investigation of WebRTC as a technology capable of successfully achieving videoconferences between users without the need of any browser plugin. In order to verify the knowledge gathered through the study of the technology, the design, architecture and implementation of an application capable of doing so will be proposed.
A Raquel: per recolzar-me sempre i fer que aquest treball arribés a bon port. A Juan López: per la seva ajuda i bona disposició tot i la llarga durada del projecte. A la meva família: per portar-me fins on sóc i per seguir ser sempre al meu costat.
ÍNDEX INTRODUCTION ................................................................................................. 1! CHAPTER 1. WEBRTC ...................................................................................... 2! 1.1.!What is WebRTC ................................................................................................................ 2! 1.2.!A brief history of WebRTC ................................................................................................ 3! 1.3.!State of the art ................................................................................................................... 5! CHAPTER 2. ACQUIRING AND BROADCASTING MULTIMEDIA STREAMS WITH WEBRTC ................................................................................................... 8! 2.1.!Acquiring media streams through MediaStream API ..................................................... 8! 2.1.1.!MediaStream API internals .................................................................................... 9! 2.1.2.!MediaConstraints ................................................................................................. 12! 2.1.3.!Security concerns ................................................................................................. 14! 2.1.4.!Playing media streams through Blob-URLs ......................................................... 15! 2.2.!Broadcasting multimedia streams through PeerConnection API ............................... 16! Javascript Session Establishment Protocol ....................................................................... 17! CHAPTER 3. DESIGNING AND ARCHITECTING A WEBRTC-BASED MESSAGING WEB APPLICATION .................................................................. 22! 3.1.!Defining a videoconference web application ................................................................ 22! 3.2.!Defining the use cases for a videoconference web application ................................. 23! 3.2.1.!Authorization and authentication related uses cases ........................................... 23! 3.2.2.!Videoconference related use cases ..................................................................... 23! 3.2.3.!Roster related use cases ..................................................................................... 24! 3.2.4.!Meeting related use cases ................................................................................... 25! 3.3.!Architecting a videoconference web application ......................................................... 25! 3.3.1.!Centralized or decentralized server architecture .................................................. 27! 3.3.2.!Dynamic web pages: Compiled or Single-Page applications ............................... 27! 3.3.3.!Stateless or Full-duplex communication protocol ................................................. 29! 3.3.4.!Data persistence .................................................................................................. 31! CHAPTER 4. VIV, THE MULTIMEDIA AND MULTI-CONFERENCE WEB APPLICATION .................................................................................................. 35! 4.1.!Server components ......................................................................................................... 35! 4.1.1.!The MEAN stack .................................................................................................. 35! 4.1.2.!Extending the MEAN stack: adding websocket connection ................................. 38! 4.2.!Client components .......................................................................................................... 40! 4.2.1.!AngularJS ............................................................................................................. 40! 4.2.2.!Architecting the client-side browser app .............................................................. 41! 4.3.!Analysing end-to-end components ............................................................................... 42!
CHAPTER 5. CONCLUSIONS .......................................................................... 48! 5.1.!Objectives achieved ........................................................................................................ 48! 5.2.!Future improvements ...................................................................................................... 49! 5.3.!Environmental study ....................................................................................................... 49! 5.4.!Personal conclusions ..................................................................................................... 50! BIBLIOGRAPHY AND REFERENCES ............................................................. 51! BIBLIOGRAPHY ......................................................................................................................... 51! ANNEX A.!FULL APPLICATION USE CASE SCENARIO ............................ 55!
6 Study, design and implementation of WebRTC for a real-time multimedia messaging application Fig. 1.2 WebRTC comparison table In order to understand the table, the green fields mean that the specification is fully implemented, yellow ones mean that there is partial or that it’s not fully adhering to the specification and finally, red ones mean that there’s no implementation that cover that area yet. With a quick look at the table, several things can be spotted easily: • Safari (Apple’s browser) still has not implemented any of the APIs that WebRTC provides which means that real interoperability is not possible at this point provided how much market share this browser has. • Microsoft is developing its own standard, ORTC. They state that it is a wrapper around WebRTC and that will provide an easier API for the developers to interact with but, as can be seen in the table, none of the other browsers are implementing it. • Most of the open-sourced browsers (or at least those whose engine is open-sourced, like chromium for chrome) have already implemented most of the APIs being cross-compatible between them. Next chapter will be an in deep jump into the APIs and components that have been used in the development of the proof of concept application.
WebRTC 7
8 Study, design and implementation of WebRTC for a real-time multimedia messaging application CHAPTER 2. Acquiring and broadcasting multimedia streams with WebRTC As explained in the previous chapter, WebRTC is a framework with lots of different functionalities and services, which are provided by a set of APIs. Of all its functionalities, this project will explore those that enable the possibility to achieve a videoconference successfully. At first glance, it seems reasonable to break a videoconference in three independent chunks, first one, acquire both local audio and video streams from the user, and after that, connect with the other end, where the other user will do the same and, after that, cross-share those streams with each other. Finally once both ends have all the streams (audio and video) for both parties, they have to be played back, in this case in a web page, so it will be done inside some HTML5 <video> tag. WebRTC provides two APIs that help fulfilling these requirements, GetUserMedia (or MediaStream) and PeerConnection APIs. Guessing by its names seems clear that the first one will provide means to obtain video/audio streams and the second one will help connecting both endpoints or users. 2.1. Acquiring media streams through MediaStream API This is the API that provides the user with the streams that he wants to acquire. It’s the simplest and most elementary API on WebRTC. The current implementation status is focused only on providing webcam and microphone hardware access through an interface called MediaStream; each MediaStream is comprised of 1 or more streams or MediaStreamTracks from different types. This last point is related to the synchronicity needed between the different streams, for instance, if a user wants to acquire one type of either audio or video streams, there is not any synchronisation problems to be considered, but on the other hand, if a user wants to perform a videoconference, it is important than both audio and video streams are synchronized. It seems obvious that even though those streams are from different hardware sources, they are related and to solve that the MediaStream API bundles both streams together inside the returned MediaStream object.
Acquiring and broadcasting multimedia streams with WebRTC 9 Fig. 2.1 GetUserMediaAPi internal calls for videoconference scenario The graph above shows the flow a request takes starting at the point where access to one or several hardware streams is requested until the point it is granted. There are 3 important aspects highlighted in the graph that need to be looked more in depth: the internals of MediaStream, MediaConstraints and security validation. 2.1.1. MediaStream API internals As told before, MediaStream API is the entry point from a developer point of view to the WebRTC framework. Starting from this call and obtaining one or several streams, will be able to manipulate them, send them, or modify them (for instance running some computer vision framework to work with a video stream or to apply audio effects to a given audio stream). To start understanding this API, first step is to go to the core of its functionalities, that is, what is the main issue it addresses, and in this case is provide the user of media streams. To do so, there needs to be an architectural abstraction that is able to handle all kinds of different media streams regardless of what source they come from, or what characteristics they have. This means that this API has to work exactly the same way either for Audio or Video streams, and to do so, as its been said earlier in this chapter, there is an abstraction of a stream called MediaStreamTrack. Below are the details of what this data structure holds.
10 Study, design and implementation of WebRTC for a real-time multimedia messaging application Fig. 2.2 MediaStreamTrack data structure according to W3C Taking a look at the definition, first thing that comes to mind is that this interface inherits from EventTarget which is an interface implemented by objects that can receive events and may have listeners for them. Reason is simple, this MediaStreamTrack is going to be having to react to different events like, pausing the stream whenever the user asks for it, or cleaning resources when there’s some error that makes that the stream is no longer valid (for instance, when accidentally disconnecting a webcam it is needed), it is important to provide the developer of some ways to gracefully handle this cases so it could recover (maybe the preference is to switch from a videoconference to an audio call without needing to break the call). Looking into the attributes and functions that this class exposes, an interesting fact is that most of the attributes are read-only; those are the ones that characterizes the stream, they give information about what kind of stream it is (video or audio), the id to uniquely identify them and the label field to give a brief description of what type of source it comes from, for example, internal microphone. The two other fields are muted, which means that there are no live samples of the stream and, finally, state, which is simply a flag to indicate if a stream is either live or ended. On the other side, there are also read-only helper functions to characterize in more detail the given stream such as getCapabilities(), which returns a list of the exact features of the current media stream. Explanation is simple, once the user pass its MediaConstraints request, as will be shown later, there’s no guarantee that the requested conditions are exactly met so, with this information, a user can understand what exactly is being delivered. Things like frame rate, width, height, volume, etc. The idea is that MediaConstraints should almost match 1-to-1 all this features, so that the user could fine-tune the stream as much as needed. Other fields, simply are exposed for the internals of the API to work with, but are of no use for the developer or the web application.
Acquiring and broadcasting multimedia streams with WebRTC 11 Now that the smallest data structure that characterizes the streams have been explained, it is time to talk about how does the developer interact with the API. It is, actually, quite simple. Once a valid request to GetUserMedia() is done, the returned value is an object of class MediaStream which holds the following structure: Fig. 2.3 MediaStream interface according to W3C specification Flow since the user request a stream until it is obtained is as follows: 1. Analyse media constraints and check how many different streams are requested and its specific requirements 2. Create a MediaStream object 3. For each of the type of streams stated in the Media Constraints JSON, check if there is some hardware or software sensor that matches the required stream, if there is no source that matches the mandatory requirements, send an error exception and exit, otherwise proceed with step 3. 4. Generate a MediaStreamTrack from the hardware/software’s sensor that satisfies the specifications 5. Add this MediaStreamTrack to the MediaStream object 6. Once a track has been added, trigger the onaddtrack EventHandler, which is a callback function 7. Finally back the MediaStream object as a result to the requested call At the end of the day, MediaStream object is just a wrapper that holds a list of MediaStreamTracks that work together, synchronously. It is bundled with utility functions to help make searching for a specific track faster. For instance it has a method that simply returns all the collected MediaStreamTracks without any distinction of type, getTracks(), while it has as well, utility methods to filter by audio or video tracks, getAudioTracks() and getVideoTracks() respectively, this filter is done taking into account to the read-only type attribute of the MediaStreamTrack. Finally, there are two callback functions that are triggered whenever a control event occurs, such as adding or removing a track to help the user wire together a stream with its corresponding HTML5 tag (either <video> or <audio>) so that
12 Study, design and implementation of WebRTC for a real-time multimedia messaging application it could start being played. This will be explained with more detail in the subsection called playing media streams through Blob-URLs 2.1.2. MediaConstraints If the MediaStream API can provide any type of stream from a single API call, there has to be a way to address which kind of stream is being requested, that’s what MediaConstraints are for. The constraints parameter is at the end of the day a JSON object with two members: video and audio, describing the media types requested. Either or both must be specified. The idea behind this is that if the browser cannot find all media tracks with the specified types that meet the constraints given, then an error will be thrown to notify the user. MediaConstraints, in its simplest form look like this: Whenever any media type is flagged as true means that the resulting MediaStream is required to have a MediaStreamTrack of that type in it. The example above is, thus, the required for a videoconference but this is only the mandatory part of the MediaConstraints. As stated into the introductory chapter, WebRTC was designed taking into account security as one of the main concerns, having said that, one of the main implications to this, is the fact that there’s no access to the underlying hardware information, either cameras or microphones. That means that given the wide range of devices and different capabilities, some way to add some fine-grained constrains should be added. With the previous JSON snippet, the user is requesting a preferred resolution to work with. This is a blind guess, since there’s no way that the API provides him with some of the available capabilities of the current devices he is using (actually there’s not even any guarantee the computer or laptop has camera built-in), so in this scenario the framework chooses the resolution that could match in a better way the requested one but in any case this mean that if this resolution was not supported in the provided hardware then an error would be thrown. { audio : true, video: true } { audio: true, video: { width: 1920, height: 1080 } }
Acquiring and broadcasting multimedia streams with WebRTC 13 Obviously, there are another scenarios where a given resolution is mandatory. There are some fields, like medical, where some minimal resolution quality must be met in order to be able to, for instance, perform some remote diagnostics. For this type of scenarios, there is another approach to ask for a required resolution: With the addition of min, ideal and max keywords, the user is able to state a range of resolutions that could fit the scenario he is on. In this case, the user will meet the opposite behaviour to the previous one, in case that there’s no resolution that matches this constraints, an error will be thrown and no stream will be returned. Analogously, the use of max constraint will produce the same behaviour but on the opposite constraint. This could be useful when dealing with streams on lowend devices or on 4G scenarios, where sending high quality streams could lead to a bad user experience due to lack of fluidness in the videoconference or running out of user’s 4G data plan. Finally, to close this series of resolution specification examples, there’s the case were a user can specify a range of resolutions as well as they use of the keyword ideal, where as one can imagine, states which is the preferred of the range. In case the ideal resolution can’t be fulfilled, then the one that will be used will be the closest one to the desired: On the other side, there is a last consideration to be made. Nowadays, smartphones and tablets sport fully capable browsers, so as it is expected, those browsers are also supporting WebRTC. As a result, those handheld devices have certain specs that the standard laptop or desktop computers doesn’t meet, for instance, they have 2 cameras, so there needs to be some constraint to deal with the ambiguity of which camera does the user refer to. Using the keywords user or environment inside the member facingMode will achieve the desired effect: user for front-facing and environment for the back camera. { audio: true, video: { width: { min: 1920 }, height: { min: 1080 } } } { audio: true, video: { width: {min: 1024, ideal: 1280, max: 1920}, height: {min: 776, ideal: 720, max: 1080} } } 8+----------------5 { audio: true, video: { facingMode: ‘user’ } }
14 Study, design and implementation of WebRTC for a real-time multimedia messaging application Using the keyword exact to require in a similar way as min or max, so if the device doesn’t have the required camera, it will fail. 2.1.3. Security concerns Regarding security, there are two different aspects to talk about regarding the MediaStream API. First topic to discuss is relating the nature of WebRTC on browsers. Nowadays, browsers are powerful environments that can perform almost as native applications on a laptop or computer. The days were browser were only static HTML and CSS have gone and now the user finds himself at the era of the webapps, which blur the lines between laptops, desktop computers or handheld devices. At the end of the day, front-end programming on web applications is being done in javascript, which is a runtime programming language that runs on the client’s computer. Obviously it has lots of benefits, but what concerns in this chapter is security and in that matter there are things to take into account. A user which browses the internet, in not aware of the scripts that every page is running as long as they don’t update the UI and, generally, is not really interested in knowing how things work. If a webpage has a nice animation, it does not matter how it is done, the only thing that matters is the result, and dealing with the kind of contents that MediaStream API is handling, some measures had to be taken. It is easy to imagine a scenario where this is a real thread. If no security is taken into account, suffices to think about a malicious webpage which taking advantage of this API silently requests the user to remotely turn on the webcam in order to spy him. How does the user know that someone is remotely tracking him? After all, the user only browsed through a webpage and he did not notice anything strange. That scenario highlights why this API and WebRTC as a broad term had to be designed with security as one of the key pillars. The solution to this scenario is really simple and it comes out of the box: { audio: true, video: { facingMode: ‘environment’ } }
Acquiring and broadcasting multimedia streams with WebRTC 15 Fig. 2.4 Chrome browser asking user’s permission to use some stream Whenever a user lands on a web page which makes a request to use MediaStream API, he will be showed a popup in the navigation screen making him chose whether he wants to allow the use of the API and show any stream or not; only when the user answers the popup, the request finishes returning back its output to the API caller. Chrome development team raised the second issue and all the other browsers are willing, if not already done, to follow the same restrictions. It is called Secure Context and MediaStream API has to comply with it. As the web platform is extended to enable more useful and powerful applications, it becomes increasingly important to ensure that the features, which enable those applications, are enabled only in contexts that meet a minimum security level, accessing personal image/audio data is considered one of the most private actions that can be taken care of in a web so that’s why it is considered that MediaStream API has to be called from a trusted source. The most obvious of the requirements discussed here is that application code with access to sensitive or private data be delivered confidentially over authenticated channels that guarantee data integrity. Delivering code securely cannot ensure that an application will always meet a user’s security and privacy requirements, but it is a necessary precondition so to sum up, if the web doesn’t have a valid ssl certificate, it won’t be able to make use of MediaStream API. 2.1.4. Playing media streams through Blob-URLs This is the last section that covers the MediaStream API. It has been discussed how to acquire one stream, how to specify which type of stream and how to query and adjust the settings for the hardware sensor that the user wants to work with, as well as the security implications wrapped around WebRTC but so far, there is no way to actually see or hear any of the streams the API is providing.
22 Study, design and implementation of WebRTC for a real-time multimedia messaging application CHAPTER 3. Designing and architecting a WebRTC- based messaging Web application Previously, the first 2 chapters have explained the theoretical aspects regarding WebRTC and all its capabilities but as stated in the introduction, this second part of the document will deal with how to take advantage of those concepts that have been showed in order to successfully build a videoconference application. It has also been explained that the main goal is to develop a web application solution that leverages the power of WebRTC and this chapter will explain the foundations of the application that has been developed. This chapter will focus on two different things; on one hand, it will describe what will the application do by splitting it into different use cases so it is easier to understand. Afterwards, the second part will deal with designing the application architecture that will support the solution. The detailed implementation details will be explained on the next chapter 3.1. Defining a videoconference web application First step in order to architect some application is having a clear idea of what is it that wants to be achieved. In this case it is quite simple; the aim is to create a web application that works well on handheld and desktop devices, that does not require of any extra plugins for the user and with which he can make videoconferences or audio calls. Even though the main focus of the application is to be able to do videoconferencing, there are a lot of things that are not explicitly related with that matter but that must be done in order to have a successful application. For instance, the user should only be able to call contacts he trusts and that are previously authorized by himself to be part of the roster, or list of contacts, and on top of that, due to the nature of the platform that is being used (a web browser), calls can only be made between 2 users that are connected at same time, and that means that there has to be a way to handle and track that scenario. On other order of things, a user should also have the chance to schedule a videoconference with another user in the event that the latter is no present at the time he wants to call him. As nice to have features, there should be the possibility to make multiconference calls and share rich-media content between the users inside of a call, from text to imagine or binary files. Those are the initial requirements that the application should cover which are the standard ones in any messaging application such as Skype, and that is exactly one of the goals of this thesis, to determine if a white-labelled
Designing and architecting a WebRTC-based messaging Web application 23 messaging application can be done sporting the functionalities of the most downloaded communication applications. 3.2. Defining the use cases for a videoconference web application This section will define the different use cases found on the application. There are several areas those use cases can be grouped by, according to the area of their functionality. The different areas are: authorization and authentication, videoconference, roster and meeting scheduling. 3.2.1. Authorization and authentication related uses cases Authorization and authentication use cases are those who are related with providing access to the platform in a customised way. Authorization could mean who can or cannot access to the application or also a means of providing scoped access to given areas of the app. Authentication on the other hand is the ability to identify a given user. There is no need to state how important that is; without a way of identifying users there’s no way to customise content, monetize and app, or keep usage statistics. Inside this category, there are two different use cases: registration and login. Regarding registration a user has to be able to create an account on the platform. This account has to provide user details so that later on this user can be searched and identified uniquely. The fields that are going to be required are, username, full name and profile image. Regarding login, there is really not much to say, it is the entrance on the application for a user. It has to provide a way of assessing that a user is who he blames he is, so there is the need of a password secure enough to prove it. 3.2.2. Videoconference related use cases This is the core functionality of the app. There are a lot of actions regarding the videoconference section, so the better way to put them together is through a list: 1. A user has to be able to make a videoconference call. 2. A user has to be able to accept a videoconference call. 3. A user has to be able to reject a videoconference call. 4. A video or voice call will be rejected if the callee does not answer in less than 20 seconds. 5. A user has to be able to add more users to a running conference. 6. A user has to be able to finish a videoconference. 7. A videoconference room has to be able to resize or adjust to fit all the participants on the screen on a responsible way.
24 Study, design and implementation of WebRTC for a real-time multimedia messaging application 8. A videoconference call has to keep running until only one participant is in the room. 9. A user has to be able to chat with the other users on the same call. 10. A user has to be able to send binary data to the users on the same call. 11. A user has to be able to send picture to the users on the same call. First 4 points on the list are related to two or more users agreeing to have a call between them. The reason is obvious, although the app could technically have the ability to avoid that point, there are privacy and security implications that make this the starting point of every call, only if both parties agreed to have a conversation should go further, otherwise nothing will happen and both users will return to their previous state. Points 5 to 8 gravitate towards another concept as well, multi-conference. Although it is clear that a simple call between 2 users ends when any of them leaves or hangs up, that’s not the case on videoconference. In this case, and taking into account that the app is rendered in a browser, it should have to be able to resize each of the streams in the screen so they all fit nicely. That implies that the calls have to be dynamic and not only set up from the beginning, making space for more users through the course of the same. Finally, points 9 to 11 are support functions to make easier the communications between end users. It’s important to understand that due to the nature of WebRTC, those files are not stored in any server but sent directly to all the parties. That makes the app avoid privacy-related security problems. The idea behind this last point is to make the application not only useful for maintaining a conversation but to make it a complete collaborative workstation area. 3.2.3. Roster related use cases Every user should be only reachable to the users that he knows and trusts. This will be the basis of the communication in the application. Every user will have a list of contacts to call and he will only be able to call those who are online. That implies that there has to be a mechanism to flag all the users that are available, connected, at the time the user is. On the other hand, a discovery-acceptance process is needed as well; one user searches for a contact and, once found, sends him a friendship request. After that, in the other end, is the requested user who decides whether to accept or decline the offering. Although this sounds trivial, truth is, there are certain things that have to be taken into consideration and most of them are related to the fact that this mutual acceptance of friendship could change with time. There are two approaches to support this appropriately. First approach is simpler but aggressive in the sense that both parties will know that the friendhsip situation has changed. Applications like Instagram follow this pattern, an on-off approach. If two users are following each other and one block the
Designing and architecting a WebRTC-based messaging Web application 25 other, both users won’t become friends anymore and that means that the blocked user will notice that he has been blocked. This could be valid on some occasions, but in others, that is not an option. To solve that problem, there’s another way to handle that situation which is having a friendship status per user. If user A requests a friendship to user B and this one accepts, both users will have added to its unique list of contacts the other user and the status of the relationship which means user A will have a relation with user B with accepted status and the other way around. If any of those users, say user B at some point changes his mind, he can do two different options: block the user or delete the user. The benefit of this approach is that those changes are only affecting one side of the relationship without the other party being aware of that change; to user A, the situation has not changed since the beginning; the only thing that he could possibly realise is that user B will never be online. Obviously, following this schema, user B can change this status back whenever he wants in a safe way. If what he wants to do is just un-friend the other user, same will happen, user B will never appear connected to user A and more important, user A will not be able to ask for again for friendship. This is the pattern that will be used on the application. Obviously, last mandatory use case, is to be able to handle the status of all the current friendships a user has, other way there is no possibility to change them at a given point in time. 3.2.4. Meeting related use cases The last group of use cases are related to the ability to schedule meetings in advance with a user. This functionality exists to cover the case where a user wants to talk to another but this last one is not available at the moment. There needs to be some kind of way to make the other user know of the intentions of the former. Those meetings can have a title so it is up to the user who requests it to leave a note. 3.3. Architecting a videoconference web application At the time of architecting a software solution, there had to be several considerations taken into account. First one, obviously, is that the chosen architecture has to be able to provide a reliable solution for all the problems proposed, the use cases, and another one is to take into account that this solution should provide access to thousands of concurrent users not all
26 Study, design and implementation of WebRTC for a real-time multimedia messaging application necessarily in a browser environment (there should be room for native handheld devices as well). Having to develop for multiple types of clients has some implications that affect directly to the architecture. That is, that all the logic regarding the application has to be centralised in the server in order to not repeat that logic in the client. A scenario where 3 different client platforms would be targeted, for instance, would imply rewriting same code 3 times which is, at least, time consuming (by 3 times) and 3 times error prone as well. The rule of thumb should be to use a server to orchestrate all the application related logic, not videoconference, and delegate to the client the responsibility of representing the data that the server provides. Another problem that should be taken into account is that every different client platform can be written in its own programming language, which implies that the server has to provide an agnostic way of communicating between the different clients. Fig. 3.1 Overall application architecture Above can be seen an architectural overview diagram. This diagram shows the network architecture rather than the application architecture. As every aspect regarding software, there are multiple ways to solve a given problem in a proper way, and, regarding architecting a web application, it applies as well. In the following sections there will be a discussion regarding which kind of solution will be applied comparing multiple approaches that could be taken, or if in any case, a trade-off or hybrid between those solutions are needed. Those decisions are: • Centralized or decentralized architecture • Compiled or Single-page dynamic web applications
Designing and architecting a WebRTC-based messaging Web application 27 • Stateless or full-duplex communication protocols • SQL or NON-SQL database 3.3.1. Centralized or decentralized server architecture On previous chapters it was stated that the application was going to be a decentralized, peer-to-peer, videoconference application to maximize the number of concurrent connections available and, as can be on Fig. 3.1, there are, in fact, client-server connections. At the end of the day, the proposed architecture is a client-server, peer-to-peer hybrid: It is client-server oriented because there has to be one place where the app holds the information regarding current state of each user inside the application, and this is responsibility of the main server. All persistence and business logic has been isolated and handled inside that server so, as stated before, there is no duplication of logic across different clients using different technologies. And obviously, it is peer-to-peer, for all the sensible streaming communications between users. 3.3.2. Dynamic web pages: Compiled or Single-Page applications Web ecosystem has been always split into 2 types of web pages, static and dynamic web pages. Static web pages are those whose content never changes, and offer exactly the same content to all the users, while dynamic web pages are those whose content will change, showing a custom experience for every user. Dynamic web pages have been around for quite some time, and there are multiple subtypes of them as well. For instance there are types of dynamic web pages that only rely on making changes at runtime, that is, provided some programmed functions inside the HTML code, those are triggered at certain points obtaining information from servers and updating the status of a given page. There have also been, in the other hand, tailored HTML web pages that are obtained from the server already with the customization code in it as well. That is, they are pre-generated or compiled and then served; an example of that type of web pages is the ones based on JSP (JavaServer Pages). Depending on which kind of webpage is desired, a different kind of server is needed; each has its trade-offs, essentially, throughput-wise. Seems quite evident that if a server has to provide each client with a different version of a webpage, it’s going to take more time than another who simply has to serve the same content over and over again and that can benefit of caching strategies that could relieve that work. Obviously the more time a server needs to spend in each request, the lesser requests it could attend per second. In the field of dynamic web pages, there has been a rising trend these last years: single-page web applications. They appeared in order to fix several of the problems that dynamic pages suffer: slow responsiveness and scalability,
28 Study, design and implementation of WebRTC for a real-time multimedia messaging application tight coupling code and standardization regarding data consumption from the server. Fig. 3.2 Dynamic web pages: single page vs compiled applications It is known that HTTP protocol is a request-response protocol, conceived to bring content at each request. The latency between the instant that a client makes a request until the response is being obtained and processed determines the idle time a user will have to wait to see the contents updated (or being redirected to the next web page). Desktop applications behave in the opposite way; all the client content is already in the application, so if a server is needed, it only needs to get certain state information and this operation is very likely to be happening on the background so the user is presented with proper handling of this idling times with page loaders or the so called, empty states. Single-page web applications are an attempt to bring those desktop app capabilities to the web. On a first request to the server, the client downloads all the client-side specific content needed to navigate through the different states (a concept analogous to a page) of the web, which will be static. This has a great impact in user experience; there are no waiting times bound to the request-response latency inherent to the http protocol; instead, the client can gracefully switch directly to the next state and be ready when the server data arrives and just show that new data at the very moment it is obtained, without having to wait for new CSS, HTML or Javascript to be loaded and executed. This targets two of the important benefits of single-page web application, slow responsiveness and scalability: Slow responsiveness in the sense that user now does not have to wait to be redirected between pages because he already has downloaded them previously, and scalability because now that the client code is completely static, it could be cached and that will free the server and make room to support higher traffic loads. Another of the problems regarding dynamic web pages and web application servers lies in the fact that there is not a clear separation of concerns, which is a hint of clean code and therefore, a cleaner architecture. Both client code and server code are coupled. In the case of compiled dynamic web applications, there are server variables and methods (tied to the request or the session, for instance) that have to be added inside the HTML client code. That is problematic in multi-disciplinary
Designing and architecting a WebRTC-based messaging Web application 29 teams where pure backend developers and pure front-end developers are forced to work together because they are dependent on each other. This last problem is solved gracefully thanks to single-page applications, enabling web applications to be treated as a first-citizen client, like mobile clients for instance. They can even be hosted independently from the applications server. And finally, is also a benefit for backend developers regarding maintainability. Before SPA, or single-page wen applications, they were usually forced to maintain two different endpoints for providing services to the different clients, one, at least, for web applications, that run directly from the same server and have access to the server variables and another one to provide service to external clients, like handheld devices, through, typically, REST or SOAP endpoints. With this approach, SPA, both type of clients are fed through the same standardized endpoints thus simplifying the number of code to maintain and clearly isolating each member’s responsibility. With all this information, seems quite clear that SPA is the way this project will be implemented. 3.3.3. Stateless or Full-duplex communication protocol As said previously, there are certain restrictions when building up a system that has to be thought as scalable and ready to work with any kind of client, even those that will be created in the future with technology that currently is nonexistent. At the end of the day, scalability means being able to give service to a higher number of clients at same time, and this, can only be achieved with more servers working all together. There is only one constraint that must be fulfilled, each server has to be able to provide seamless service to any user regardless of what server had previously answered previous requests that one client could have made. Fig. 3.3 Load distribution between servers
30 Study, design and implementation of WebRTC for a real-time multimedia messaging application Taking as an example Fig. 3.3, there are two different scenarios explained. Scenario A consist of an application which is being served by a server and its at its 90% of capacity. That means that the server is about to reach a point of full load and will not be able to provide service to newer clients. That would be the maximum throughput that this example application could achieve. Now, scenario B is an example of how to try to scale this architecture to reach more concurrent clients; the idea is simple: try to divide the work of one server by adding another one thus creating a server cluster. Theoretically, this means that once this scenario has been set up, each of the servers would be working approximately at 50% of its capacity and neither one of them would not be stressed. Well it turns out, that depending on which type of connection protocol is taken, that will not happen. Turns out that web servers are designed to work on top of HTTP protocol, which as stated before, is by design stateless, but at the end of the day, plain users of web applications do not care about this and rely only on the scope of a session in a page. We could define a session as the whole interaction process since the user logs into a web page until it closes the session or leaves the page. Dynamic web applications that have an authentication mechanism just ask for the user credentials one single time and once users are granted the access are not required to login again at each step they do, until they log out. This session scope at application-level has to be tracked at transport level through the HTTP protocol so at the end of the day, there has to be a way to cheat that statelessness of the protocol and there are two main strategies to do so, a stateless one and stateful one. If at application level there is a stateful communication protocol, it means that the server that accepts the first request of a given user will have to deal with all the other requests of that user during that session so that the data exchanged keeps being consistent. For example, for J2EE and a Tomcat web server, whenever a new session is created, the server creates a JSESSIONID cookie that keeps track of the user activity. Going back to scenario B on Fig. 3.3, if that user keeps sending each request randomly to both servers, only the server who started the communication will be able to react appropriately since it is the only one who internally keeps track of that session value. On the other hand, there are the stateless protocols, which are the current trend in the industry. The idea behind them is to provide all the information needed by the server at every request. Recovering the analogy of the user who wants to navigate through an authenticated web application, using this stateless approach, once the user has successfully authenticated, it will be given a user token that it should keep adding (typically on the headers) at each request. With that change, it does not care which server inside the cluster handles each request.
Designing and architecting a WebRTC-based messaging Web application 31 With the information of both modes, and taking a final look at Fig. 3.3, scenario B should only be achieved by the stateless server architecture because with the stateful architecture even though any number of new servers were added to the cluster, the first server would keep having the same 90% load of traffic since all the sessions are bound to it. Only clients starting fresh sessions would benefit of multiple servers. There is also a final consideration related to handheld devices and real-time applications: due to battery consumption restrictions, it is considered a bad practice for those systems to keep persistent connections with the servers. If no persistent connection, or at least the minimum possible persistent connections had to be used on this platforms then only REST like endpoints are valid connection options but main drawback from them is that connections can only be started from the client-side to the server side. That means that if real-time event has to be sent to a client it could only be achieved by implementing a polling system where those clients are systematically asking for new data. This obviously affects the scalability of the system drastically so, at this point, a trade-off decision has to be taken. The final architectural decision is for the second time, a mix of both solutions. On one hand, browser clients can benefit of real-time persistent connections so all the traffic between the app and the server will go through that interface. At the same time, all the non real-time communication traffic on handheld devices will be exposed through a REST API while all the real-time traffic will be held through a persistent connection. That way the best of both worlds is taken into consideration in the platform while minimizing the potential high-battery consumption on handheld devices. 3.3.4. Data persistence After talking about scalability issues in the previous section there is only on topic to decide on architecture-wise: data persistence. It is obvious that if multiple servers can be dynamically spawn and shut down according to traffic loads and that each client could potentially reach any server for any given request, the data that keeps the state of the application has to be kept in another isolated environment that all the servers could reach in a reliable way, that means that regardless of what server is reached, the information has to be consistent. In the case of this application, since data is stored in a structured way, the only way to achieve that is through a database server. Turns out that database are split into two different types of them: relational and non-relational databases. Relational databases organize data into one or more tables or relations of columns and rows, with a unique key identifying each row. Rows are also called records or tuples. Generally, each table/relation represents one entity type (for instance a customer or a product). The rows represent instances of that type of entity and the columns represent values attributed to that instance
38 Study, design and implementation of WebRTC for a real-time multimedia messaging application Fig. 4.2 MEAN stack on VIV application To complete the backend functionalities, there is another interface that needs to be exposed for the clients to consume data. A full-duplex persistent connection. To achieve that, the MEAN stack will need to be extended. 4.1.2. Extending the MEAN stack: adding websocket connection REST interfaces are actually the common way to expose any service for its consumption regardless of which kind of client is consuming it. It’s cheap, quick and quite performing but has a big problem when dealing with real-time applications: connections can only be initiated from the client. In the context of a videoconference, there are, at least, two users with different roles that need to cooperate in a short window of time: the caller, with an active role, and the callee with a passive one. In this scenario in a REST environment, the callee simply can’t be reached by the server and thus, the videoconference will never happen. There are several solutions to resolve that problem in a REST-only environment, but none of them are optimal. On one side there are polling
VIV, the multimedia and multi-conference web application 39 techniques and on another side, if dealing with handheld devices, there are push notifications. Polling is simply, querying continuously the server so the moment the new information is available, it could be obtained. That obviously comes as a tradeoff for scalability issues. Imagine a polling rate of 250 milliseconds with 500 users simultaneously. That adds up to 4 polling request per second per user, which adds up to 1000 request per second. That simply doesn’t scale. There are 2 alternatives to this: First one are the SSE, server sent events (which means, keep a connection-opened with the server so whenever there is a new event that involves a given user, the server could rely on this connection and send an event through that). It would be a half-duplex solution since this connection can’t be used for the client to inform of real-time events the server on the other way around. The second ones are Websockets. Websockets are simply put, TCP sockets that work on the browser. It is a persistent, full-duplex and low-latency solution to communicate both ends. Unfortunately, not all the clients at this point support them so if there is not a reliable way to take advantage of them it cannot became a real solution. Fortunately, another NodeJS framework comes to the rescue: Socket.io. Socket.io is an event driven communication protocol. What makes socket.io special is that even though it is designed to be used over websockets, it can gracefully change the transport protocol used underlying according at the browser specifications, from preferred way to worst case scenario. That means that per instance, socket.io could have a configuration where it is stated that thee list of connectivity strategies are ordered: websockets, long polling, polling or error if none of that works. The important piece is that this will work transparently for the user, which will have the same experience regardless of how what protocol is being used. Fig. 4.3 Full backend architecture for VIV application
40 Study, design and implementation of WebRTC for a real-time multimedia messaging application As explained before, websockets main purpose is to provide a bidirectional way of interacting with the other end (the server in this case) from the browser and on top of that, it has the benefit of being a raw TCP connection, so there is no overhead due to HTTP headers being sent. On the other hand, that is a drawback per se, because it means that its completely up to the developer to create a control logic to be able to issue different types of information, otherwise, there would not be a way to distinguish the kind of data being sent through it. That’s where Socket.IO is handy. It is designed as an event-driven data channel, which allows sending different events with its related data thus making quite easy the task to identify what is being sent. Another powerful feature that Socket.IO has are the rooms concept. Imagine three Websocket connections from three different clients. This will be expanded later on this chapter on the roster implementation details. 4.2. Client components 4.2.1. AngularJS AngularJS is the last letter in the MEAN stack acronym that needs to be explained. It is quite different than the other parts of the stack; while all the other parts relate to the server, this part deals with the client side of the application, that is, what the user will interact with. As explained before, the fact that using AngularJS (or any other framework that allows the developer to completely separate the client logic from the server one) is one of the main reasons why it has become a big player in the industry, but it is not the only one. There are several great improvements that AngularJS brings to the web development that justify its big adoption rate; there are enforcement of design patterns like MVC, MVVM, Single responsibility or observer pattern (applied in the star feature double-binding), dependency injection enforcement and testability. To sum up, it makes writing client side code in a maintainable and robust way: MVC (Model-View-Controller) and MVVM (Model-View-ViewModel) patterns, enforce the single responsibility law, each part is only responsible of one thing, for instance, the model holds the information that wants to be dealt with, the view holds responsibility of how this information should be rendered and the controller is the one who holds the logic to adapt the data from the model to make it suitable for the view.
VIV, the multimedia and multi-conference web application 41 On the other side MVVM implements the observer pattern, where the view registers itself to receive any kind of change in the model object so it could be updated instantly. Greatest benefit of this pattern is that it goes bi-directionality, that’s why it is called double-binding, because it could be as well that the view updates the model as well, and everything would be synchronised. For instance, typical example scenario to understand that are the HTML forms. Once the form is presented to the user, the model will have the previous information of the user, so it would be pre-filled (that’s the ViewModel updating the view), the moment the user updates one of the fields, it is being updated the other way around, the View interacting with the ViewModel. As can be imagined, having the state of objects synchronised directly while preserving separation of concerns principle is a huge benefit that not only makes code better and more understandable but also enforces testability. Finally, last topic, dependency injection. That’s arguably the best feature that this framework provides; The AngularJS injector subsystem is in charge of creating components, resolving their dependencies, and providing them to other components as requested which means that there is no need to share instances of objects on shared scopes and on top of that, makes components modular. That means simply put, that as a developer, components –that are well architectured because the framework enforces to do socan be created modularized, and externalized as a library, which means that every application can benefit from them. 4.2.2. Architecting the client-side browser app The fact that AngularJS enforces and benefits at same time of building modular application has a counter effect, what if a legacy application relies on several external modules that after a while have been updated with new features and deprecated features that where relevant to the application? It would end up breaking the application and not being usable anymore. Other systems have solved that problem several years ago with dependency management software, as mentioned before, Java has maven for instance. The point is that, this could be a real problem for mid and long-term applications and therefore, a solution is needed. In other words, AngularJS has to rely on other external tools that solve this kind of problems as other technologies do. To solve this and other similar problems, there are tools that helps setting up the environment for this Single-Page applications to work; in this section a brief description of all of them will be made: The dependency management is done by BowerJS. BowerJS is a NodeJS utility that simply keeps track of each external module needed to successfully build the AngularJS application as well as the version being used. That way, as Maven, it will keep track of all the dependencies thus fixing the previously described problem. GruntJS is a Javascript task runner. It deals with automation and orchestration of tasks for the client application. For instance, it can create a local server to
42 Study, design and implementation of WebRTC for a real-time multimedia messaging application test the client directly without the need to deploy it to any place, the execution of unit tests, minifying (obfuscating the code as well as merging all the Javascript different files into a single one to increment performance) and all this kind of tasks that are needed for a healthy application development environment. Finally, the last important tool used is Yeoman. Yeoman is a scaffolding framework designed for AngularJS based applications. Simply put, is tool that according to user preferences creates a base application with all the resources needed. Essentially, if GruntJS mission is to keep a healthy environment, Yeoman creates the environment. It allows the user to select which AngularJS version to start from (some of them are quite different from the others, like branch 1 to 1.5.x from 2), which SCSS to use, if any, in this case Bootstrap 3 as well as generate the initial bower dependencies file, grunt configuration file and ready to work hello world app, all of this within a minute, really convenient. With the help of all those technologies, the client side application can be easy and enjoyable to work with, maintainable and robust, because with a simple check after downloading it from the repository can be built and verified. 4.3. Analysing end-to-end components Roster component Roster component is one of the key components in the application. It is needed in order to search users and also displays an indicator showing the current state of a user, if it is connected, disconnected or on a handheld device. Fig. 4.4 Roster component view This is one of the components that need a persistent connection because it is mandatory to track as accurate as possible the status of a user so that it could be called, otherwise, the UX, user experience would not be satisfactory. To do so, as explained earlier, this component will need to interact with the Socket.IO interface from the server. This component needs two different sets of information; on one side, the list of users that have a relation with the logged in client: username, image and full name. On the other hand, it will need the connection status.
VIV, the multimedia and multi-conference web application 43 To illustrate how this works, consider a scenario where there are 3 clients, A, B and C. To simplify things, consider as well that all of them are already friends with each other and that B and C had already been logged in the application. This whole example starts from the moment where A logs in and has to build his roster; Fig. 4.5 on the next page show schematically the process about to be described. This task, that could be really complicated gets quite simple thanks to Socket.IO’s built in functionalities. When client A gets on the landing page of the application, it triggers a websocket call to retrieve his list of contacts. When that event reaches the server, this one does a set of actions: first queries the users from the database and right after that sends back that information through client A’s websocket. At this point, client A will have a list of all his contacts but won’t have any information about the state of each particular user so by default all of them will be shown as disconnected. Fig. 4.5 Roster update logic On the other hand, the server after sending client A’s list of contacts still has a couple of things to do: first, registers the socket from client A to client B and C’s rooms; from that point onwards client A will be aware of any event broadcasted on any of those rooms. Finally once the server has registered client A to all his contact rooms, it broadcasts a message to client A’s room announcing a roster:update event with the status of the new connection user.
44 Study, design and implementation of WebRTC for a real-time multimedia messaging application Since client B and C were connected prior to A’s connection and being contacts of A, they were previously registered into room A (followed this exact process before) so they will receive that broadcasted event from the server and therefore, update client A status to reflect that now is online. Last step happens on the client, once they process the roster:update event, in this case, B and C will answer back sending a roster:ack event message informing of its own status that will be delivered back to client A. Finally client A will receive a roster:ack message from each of the clients thus will update the status of the connection for each of them. At this point all the clients have an updated and synchronised version of the status of their rosters. Handle this without Socket.IO functionalities would be way much harder than having 3 different events. Same benefits are used for the signalling channel when a user wants to initialise a videoconference with another one. Videoconference component This is the other component that is going to be explained because it’s the core functionality of the application. The biggest issue is to create a communication protocol between a client, user A, the server and another client, user B that on the other hand could be extensible to multiple users in order to achieve a multivideoconference. The problem can be split in two halves. First half is dealing with the request of the call; an analogy in standard non-VOIP calls would be the dialling and ringing state. The other half is the signalling process inside the conference page. First part involves, conceptually, two steps; First step is when user A at any given point, calls user B. From a UX point of view, the sequence should be as follows: User A selects User B from his roster and presses the call button. That opens a confirmation dialog that if confirmed, initializes de call with User B. At this point, User B displays a call dialog screen prompting him to accept or deny the call. If no answer is provided, in order to avoid lockdown states in both ends, a countdown of 15 seconds is added as a ringing limit. If User B accepts the call is brought to the conference page where he will wait for User A. User B is on the second step. Meanwhile, User A is given the confirmation back from User B so he enters as well at the conference room. To achieve this use case Socket.IO, will be used as the previous use case. Below can be found the call request flow explained:
VIV, the multimedia and multi-conference web application 45 Fig. 4.6 Call request flow The UX flow explained above is summed up on the first round-time trip composed by the call:invite method sent by user A and the call:accept sent by user B. Visually, once user B receives the call:invite event, shows a popup with caller information (username and picture, so that he would be able to identify who is calling). Upon acceptance, user B goes directly to the conference page and at same time, sends back the call:accept event to user A who does the same. At this point both users are in the conference room and are ready to start the create offer/send answer WebRTC protocol through but none of them has information about which role has to play and, as said before, this can’t be limited to 2 users, so if more users later want to join, it should be possible. As explained before, main problem here is the race condition that incurs on who has to start the process and who needs to passively wait without doing any action in a way that if later another user arrives, it would perform the same way. The race condition happens because first thing the user has to do once it has landed in conference page is request permission for the local streams through the GetUserMedia API. It is not as simple as stating that the first user who reaches the page would be the initiator (in this case User B because he accepts the call and once he does that he’s brought to that page while User A still has to wait for the event emitted by user B to propagate through the network, receive it and process it) but who is the first who grants access to the resources. Once the webcam and or audio devices has been requested and granted, then the process starts. It is the same process for both parties so this way it could be repeated no matter how many times or when a new user could reach the conference and goes as follows:
46 Study, design and implementation of WebRTC for a real-time multimedia messaging application First the user after having their local resources allocated sends a call:register with his id and the room’s id (generated by the server when the call was created during the call:invite process). Once this event arrives to the server, the user is registered in the virtual conference room created by that call and at that point, server broadcast at that conference room a slightly different message, call:addUser with user details. Main benefit this message broadcasting provides is that this will fix the race conditions problem because If User A and User B where to send this message at same time, since the server is single threaded, request should have to be queued thus at the time the first user would be registered, say user A for example, there wouldn’t be any other client registered in the virtual conference room so even though the server throws a broadcast message, it simply won’t have any socket to send it through. It is only after the second user, user B is registered, that the message call:addUser would be broadcasted to the user A. The biggest problem is fixed and on top of that, this scales to any number of users so the multi-conference challenge will be solved as well! After that, the events are quite simple, whomever user receive the call:addUser with the information of the other client, will have to answer with its details with a call:userDetails message so that both ends have full information regarding each other. Those messages will be broadcasted so that if there would be, say 3 users in a conference, same message would be delivered to all parties, again, except the sender. At this point each user knows how many participants are in the call: as much as call:addUser plus call:userDetails are thus each user knows how many resources need to allocate (number of <video> html tags needed to be rendered in the conference, one per participant plus the local stream). There is one last issue that needs to be taken care of. The fact that the call could be for more than a user, and that each user has to keep track of each user’s offer/answer flow (a multi-conference is at the end of the day a set of one to one conferences between all the elements of the call, so if there is a 3 people multi-conference, each user will make 2 videoconference, one with each of the other users and will all be rendered at same time). The easiest way to solve this is send inside the room a direct message just for one client, not broadcasted like the others. This way, server will have to handle the right delivery according to the message he receives. Taking a look at the graph below will help understanding it:
VIV, the multimedia and multi-conference web application 47 Fig. 4.7 Signalling protocol for offer/answer exchange User A sends creates an offer and sends a webrtc:offer message with the offer and the user B’s id. With that information, when the message reaches the server this one processes it and delivers to User B the content of the offer User A has sent him but with a new dynamic message type composed by UserAId:offer where UserAId is, as the name suggests the id of user A. This same process will be used for the answers and the iceCanditate exchanged (this is the IP and Port discovery process, so that both User A and User B can speak directly). Once all those messages have been exchanged, the videoconference can be started. After this chapter, on the conclusion the results will be shown and explained and afterwards compared with the initial goals to see if they have been achieved or not.
Annex 55 ANNEX A. FULL APPLICATION USE CASE SCENARIO This appendix will show some of the common use cases mentioned in the document. To do so, it will be described the whole process since the user registers in the application until the user starts a multi-videoconference. To begin with, the user types on the browser the URL of the domain that points to the server where the load balancer, and NGIX server, is hosted. Which leads him to the login screen. Fig. A.1 Login screen Once the user lands there, he realises he has to register himself on the application to be able to use it so he clicks on the register now link. Fig. A.2 Register form
Study, design and implementation of WebRTC for a real-time multimedia messaging application 56 Once the user successfully fills in the form and thus gets registered, is automatically redirected to the landing screen. Fig. A.3 Landing screen Now he proceeds searching for his friend on the search bar in order to send him a friendship request, so he types his name and clicks the search (+ sign) button. Fig. A.4 Search view showing users matching the criteria He finally finds his friend, Demo User 2, so he adds him to his roster contact. At this point, the request is on a pending state until Demo User 2 authorizes it himself. Fig. A.5 Real-time contact request notifications On the other end, Demo User 2 notices that some friend related change has happened just checking how, instantly, the contacts icon turns orange so he clicks on it to see the changes.
Annex 57 Fig. A.6 Available contact request resolutions At this point, Demo User 2 can accept or reject the request. If he’d chosen to reject it, Demo User 1 would never notice it because by design, and due to the database being document-based, each user has to have its own relationships with all his contacts so to him, it would appear like User 2 would have never updated the request. Luckily, Demo User 2 knows the user and he decides to accept him as a contact. Fig. A.7 Contact added to the roster Notice how, once the User 2 has accepted the request, it automatically changes to accepted and on top of that, the roster list gets updated with User 1 on it. From that point onwards, both of them can call each other. At this point, User 2 clicks User 1 on his roster and from there he’s shown all the information and options available to interact with. On the image below, can be seen the information provided: username, full name, online status and the actions that can be done: videoconference, voice call or arrange an appointment.
Study, design and implementation of WebRTC for a real-time multimedia messaging application 58 Fig. A.8 Contact details screen At that point, User 2 choses to start a video call with the user so clicks on the video camera button. On doing so, a confirmation popup appears. Fig. A.9 Call confirmation dialog After confirming the call, two different flows spawn at same time, depending on the user. On one side, User 1 will receive the call and a dialog will pop up so he can take action. On the other side, User 2, is shown a completely different popup waiting for the confirmation on the other end. Fig. A.10 dial-in state in both videoconference ends Finally, after User 1 accepts the call, both users are brought to the conference room where the videoconference will start when both parties will be ready once the signalling process has finished exchanging the information.
Annex 59 Fig. A.11 videoconference screen During the videoconference, they make use of the peer-to-peer chat capabilities so that they can securely share private messages. Fig. A.12 WebRTC DataChannel capabilities on chat messaging Finally after some time discussing, they agreed to talk with User 3, which might have the answer to some of the doubts that they have. Luckily, User 2 notices that the user is available on the phone, so he only needs to drag and drop the user contact to the videoconference and, again, the confirmation call dialog appears. Once the user confirms that he wants to add User 3 to the videoconference, this one goes through the same process described before until he joins the videoconference through his android phone.
Study, design and implementation of WebRTC for a real-time multimedia messaging application 60 Fig. A.13 Multi-conference between 3 users On the other hand, user 3, with the native android application sees the same content on the device but with a native interface, which dynamically resizes to show the content of all the users involved. Fig. A.14 Android native application interface