153 lines
2.5 KiB
JavaScript
153 lines
2.5 KiB
JavaScript
let Softphone = {
|
|
|
|
/**
|
|
* Check if has a call session
|
|
*/
|
|
isOnCall: function() {
|
|
if (ua.sessionInstance)
|
|
return true;
|
|
|
|
return false;
|
|
},
|
|
|
|
/**
|
|
* Make a new call
|
|
*/
|
|
call: function(number) {
|
|
if (this.isOnCall())
|
|
return;
|
|
|
|
ua.sessionInstance = ua.call(`sip:${number}@${uriHost}`, options);
|
|
},
|
|
|
|
/**
|
|
* Hang up current call
|
|
*/
|
|
hangup: function() {
|
|
if (!this.isOnCall())
|
|
return;
|
|
|
|
ua.sessionInstance.terminate();
|
|
},
|
|
|
|
/**
|
|
* Answer incoming call
|
|
*/
|
|
answer: function() {
|
|
if (!this.isOnCall())
|
|
return;
|
|
|
|
ua.sessionInstance.answer(options);
|
|
},
|
|
|
|
/**
|
|
* Mute current call
|
|
*/
|
|
mute: function() {
|
|
if (!this.isOnCall())
|
|
return
|
|
|
|
ua.sessionInstance.mute();
|
|
},
|
|
|
|
/**
|
|
* Unmute current call
|
|
*/
|
|
unmute: function() {
|
|
if (!this.isOnCall())
|
|
return
|
|
|
|
ua.sessionInstance.unmute();
|
|
},
|
|
|
|
/**
|
|
* Get if current call is muted
|
|
*/
|
|
isMuted: function() {
|
|
if (!this.isOnCall())
|
|
return
|
|
|
|
return ua.sessionInstance.isMuted();
|
|
},
|
|
|
|
/**
|
|
* Hold current call
|
|
*/
|
|
hold: function() {
|
|
if (!this.isOnCall())
|
|
return
|
|
|
|
ua.sessionInstance.hold();
|
|
},
|
|
|
|
/**
|
|
* Unhold current call
|
|
*/
|
|
unhold: function() {
|
|
if (!ua.sessionInstance)
|
|
return
|
|
|
|
ua.sessionInstance.unhold();
|
|
},
|
|
|
|
/**
|
|
* Get if current call is on hold
|
|
*/
|
|
isOnHold: function() {
|
|
if (!this.isOnCall())
|
|
return
|
|
|
|
return ua.sessionInstance.isOnHold().local;
|
|
},
|
|
|
|
/**
|
|
* Transfer current call
|
|
*/
|
|
transfer: function(number) {
|
|
if (!this.isOnCall())
|
|
return
|
|
|
|
ua.sessionInstance.refer(`sip:${number}@${uriHost}`);
|
|
},
|
|
|
|
/**
|
|
* Get volume
|
|
*/
|
|
getVolume: function() {
|
|
return options.volume;
|
|
},
|
|
|
|
isMicEnabled: function() {
|
|
if (options.microphone)
|
|
return true;
|
|
},
|
|
|
|
getStatus: function() {
|
|
|
|
},
|
|
|
|
setStatus: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* Returns a number from incoming calls
|
|
*/
|
|
getRemoteIdentity: function() {
|
|
if (!this.isOnCall())
|
|
return;
|
|
|
|
return ua.sessionInstance._remote_identity._uri._user;
|
|
},
|
|
|
|
/**
|
|
* Returns call direction
|
|
*/
|
|
getDirection: function() {
|
|
if (!this.isOnCall())
|
|
return;
|
|
|
|
return ua.sessionInstance.direction;
|
|
}
|
|
}
|