Sipml5 webrtc for Ecmascript
Can be used in Angular and React
This is a Webrtc library for Ecmascript based on Sipml5. It's a bridge between Sipml5 and Ecmascript.
Installation
Install via npm
npm i ecmascript-webrtc-sipml
Usage
import SIPmlWebRTC into your component
;
Add the following tags into your html component (audio tags are used to play voice call or ringtone)
Then, you need to login or register with your information
implements OnInit sTransferNumber; oRingTone; oRingbackTone; oSipStack; oSipSessionRegister; oSipSessionCall; oSipSessionTransferCall; videoRemote; videoLocal; audioRemote; bFullScreen = false; oNotifICall; bDisableVideo = false; viewVideoLocal; viewVideoRemote; viewLocalScreencast; // <video> (webrtc) or <div> (webrtc4all) oConfigCall; oReadyStateTimer; ringtone;ringbacktone; { thisringtone = document; thisringbacktone = document; } { try // enable notifications if not already done // if (window.webkitNotifications && window.webkitNotifications.checkPermission() != 0) { // window.webkitNotifications.requestPermission(); // } Notification; // save credentials //saveCredentials(); // update debug level to be sure new values will be used if the user haven't updated the page SIPml; // create SIP stack thisoSipStack = realm: "xxx.xxx.xxx.xx" impi: "yyyy" impu: "sip:yyyy@xxx.xxx.xxx.xx" password: "yyyy" display_name: "yyyy" websocket_proxy_url: "wss://xxx.xxx.xxx.xx:8089/ws" outbound_proxy_url: ""//(window.localStorage ? window.localStorage.getItem('org.doubango.expert.sip_outboundproxy_url') : null), ice_servers: ""//(window.localStorage ? window.localStorage.getItem('org.doubango.expert.ice_servers') : null), enable_rtcweb_breaker: ""//(window.localStorage ? window.localStorage.getItem('org.doubango.expert.enable_rtcweb_breaker') == "true" : false), events_listener: events: '*' listener: thisonSipEventStack enable_early_ims: ""//(window.localStorage ? window.localStorage.getItem('org.doubango.expert.disable_early_ims') != "true" : true), // Must be true unless you're using a real IMS network enable_media_stream_cache: ""//(window.localStorage ? window.localStorage.getItem('org.doubango.expert.enable_media_caching') == "true" : false), //bandwidth: (window.localStorage ? tsk_string_to_object(window.localStorage.getItem('org.doubango.expert.bandwidth')) : null), // could be redefined a session-level //video_size: (window.localStorage ? tsk_string_to_object(window.localStorage.getItem('org.doubango.expert.video_size')) : null), // could be redefined a session-level sip_headers: name: 'User-Agent' value: 'IM-client/OMA1.0 sipML5-v1.2016.03.04' name: 'Organization' value: 'Doubango Telecom' ; if thisoSipStackstart != 0 console; else return; catch e console; //btnRegister.disabled = false; }
Call Control
Call Transfer
{ if thisoSipSessionCall var s_destination = ; //if (!tsk_string_is_null_or_empty(s_destination)) { //btnTransfer.disabled = true; if thisoSipSessionCall != 0 console; //btnTransfer.disabled = false; return; console; //} }
Start Audio call
this.oSipSessionCall.call("xxxx") start a audio call to xxxx number
{ let audioRemote = document; thisoConfigCall = audio_remote: audioRemote video_local: null video_remote: null screencast_window_id: 0x00000000 // entire desktop bandwidth: audio: undefined video: undefined video_size: minWidth: undefined minHeight: undefined maxWidth: undefined maxHeight: undefined events_listener: events: '*' listener: thisonSipEventSession sip_caps: name: '+g.oma.sip-im' name: 'language' value: '\"en,fr\"' ; if thisoSipStack && !thisoSipSessionCall if s_type == 'call-screenshare' if !SIPml ; return; if !locationprotocol if this; //window.location = 'https://ns313841.ovh.net/call.htm'; return; //btnCall.disabled = true; //btnHangUp.disabled = false; if windowlocalStorage //oConfigCall.bandwidth = tsk_string_to_object(window.localStorage.getItem('org.doubango.expert.bandwidth')); // already defined at stack-level but redifined to use latest values //oConfigCall.video_size = tsk_string_to_object(window.localStorage.getItem('org.doubango.expert.video_size')); // already defined at stack-level but redifined to use latest values debugger; // create call session thisoSipSessionCall = thisoSipStack; // make call if thisoSipSessionCall != 0 thisoSipSessionCall = null; console; //btnCall.disabled = false; //btnHangUp.disabled = true; return; //saveCallOptions(); else if thisoSipSessionCall console; thisoSipSessionCallacceptthisoConfigCall; }
Logout or signup
{ if thisoSipStack thisoSipStack; // shutdown all sessions }
HangUp
{ if thisoSipSessionCall console; thisoSipSessionCall; }
Mute / Unmute
{ if thisoSipSessionCall var i_ret; var bMute = !thisoSipSessionCallbMute; //txtCallStatus.innerHTML = bMute ? '<i>Mute the call...</i>' : '<i>Unmute the call...</i>'; i_ret = thisoSipSessionCall; if i_ret != 0 //txtCallStatus.innerHTML = '<i>Mute / Unmute failed</i>'; return; thisoSipSessionCallbMute = bMute; //btnMute.value = bMute ? "Unmute" : "Mute"; }
Other Important functions
{ try thisringtone; catch e } { try thisringtone; catch e } { try thisringbacktone; catch e } { try thisringbacktone; catch e } { console; }{ console; }{ } { // permission already asked when we registered //if (window.webkitNotifications && window.webkitNotifications.checkPermission() == 0) { if thisoNotifICall thisoNotifICall; //this.oNotifICall = Notification.createNotification('images/sipml-34x39.png', 'Incaming call', 'Incoming call from ' + s_number); thisoNotifICall { thisoNotifICall = null; }; thisoNotifICall; //}}