Preliminary sip.js

Foreword

We have a project manual outbound demand through a browser, here involving some voip related technology stack. As used freeswitch softswitch platform, SIP (Session Initiation Protocol) signaling, as a carrier, binding and other related technologies webrtc browser calls demand. sip.js it is to use javascript to sip protocol is encapsulated, it is precisely the combination of webrtc to help us quickly build real-time transmission of audio and video browser.

About sip agreement

As familiar sip http protocol, it is a text-based application-layer control signaling protocol, which also uses a mode request / response communication. Common request message includes:

  • INVITE: is the calling user initiates a session request
  • ACK: The client confirms to the server that it has received a final response to an INVITE request
  • BYE: it means the end of an already established call (call end)
  • CANCEL: cancel the request expressed before receiving a final response to the request, there was no effect on the request has been completed.

In addition, there are other types of requests, but it is not common, common basically these four. Upon receiving the request, the server needs to respond to, for example, the client initiates the INVITE request, the server begins a session, this time in turn sends the following response message, indicating that the current session state:

  • 100 test calls (the Trying)
  • 180/183 represents is outbound, then media can be early or ringing. The difference between 180 and 183, may refer to this article
  • 200 successful response

This time the client needs to return an ACK indicates a successful session is established. Three kinds of response message here represent only a case through the establishment of normal telephone, and some identify the error message, for example, 401 Unauthorized, 486 and so the line is busy, you can see it, and very much like http, there is an identification code and description information. Note, however, SIP is only used to create, modify, and release one or more participants of the session, what session type specific selection, the speech codec information, load information needs to be controlled by the SDP (Session Description Protocol). The above-mentioned 183 or 200 response status, will carry sdp information for establishing a media channel, on sdp message format, you can refer to this article .

Depth sip.js

sip.js sip protocol using javascript of the package, the above mentioned sip we only used to control the session establishment and modification, it does not provide session description, conference control functions, which are to be described by sdp. And it also does not provide established media channels, establish a media channel in the browser, we are most likely to think that webrtc, sip it is to establish a media channel through webrtc. Related learn about webrtc, we can refer to this . After learning through webrtc we know, it is to realize the transmission of audio and video data streams through the establishment of RTCPeerConnection (abbreviated pc) between the client webrtc. Prior to the establishment pc, some media also need to exchange information, which we call signaling process. three types of information used to exchange signaling:

  • Connection control information: initialize or close the connection reports an error.
  • Network configuration: For the external network, our computer's IP address and port.
  • Multimedia data: what codec, what information the browser can handle.

The webrtc has provided api Let's quickly generate these data media, namely the pc createOffer methods and createAnswer methods, and their data generated precisely sdp text format mentioned above. Therefore, we can conclude that, webrtc also to exchange media data by sdp, so as to establish a media channel. As to why points createOffer method and createAnswer method, because the signaling is taking a offer / answer a manner similar requests / questions and answers, will be completed after the sender sends signaling offer, the responder sends answer, the two sides exchanged media information, thus establishment pc. Exchange of media can take a variety of data transmission, sip.js websocket default is used for transmission. As an example so that we can get to understand more clearly the process of establishing the use of a pass after sip.js session:

  1. The client initiates a request invite, invite the client carries the media data encapsulated into packets createoffer sdp method, together to the service side
  2. The server receives the request (we use freeswitch), analytical sdp, call, call state while sending the response to the client, such as 100,183,200, 183 and 200 when the server will carry sdp, difference is that 200 is really set up the call, the 183 could carry early media and other information.
  3. By default, the client will resolve sdp information carried by 200 states, thus completing the process of signaling, media channel is established, start a conversation.

to sum up

Through the above description, we can see the relationship sip and webrtc, which in fact responsible for different functions, but can be very good together to build a more powerful application. Creating and managing sip primarily responsible for the session, and the session webrtc application for establishing a media channel, enabling transmission of browser-side audio and video streams, but it is the combination of the two sip.js to help you quickly develop a large-scale web-side . This article only on the principle of sip.js partial interpretation, and does not describe how to use these technologies, but also need to refer to specific documents or you can read the source code for more information.

Guess you like

Origin www.cnblogs.com/danceonbeat/p/12167666.html