soft-phone
Version:
207 lines • 7.97 kB
JavaScript
import { Injectable } from '@angular/core';
import { User, CallState, Registration } from '../components/index';
var PhoneService = /** @class */ (function () {
function PhoneService() {
this.displayText = "";
this.status = CallState.DialPadOutbound;
this.reg = new Registration();
this.txtRegStatus = "Disconnected";
this.btnMutevalue = "Mute";
this.btnHoldResumedvalue = "Hold";
this.call_type = 'call-audio';
}
PhoneService.prototype.onSipEventSession = function (e) {
switch (e.type) {
case 'connecting':
case 'connected':
var bConnected = (e.type == 'connected');
if (e.session == this.registerSession) {
this.txtRegStatus = e.description;
}
else if (e.session == this.callSession) {
if (bConnected) {
this.stopRingbackTone();
this.stopRingTone();
this.status = CallState.InCall;
if (this.reg.auto_recording) {
//start recording
this.recordCall("0");
}
}
this.callStat = e.description;
}
break;
case 'terminating':
case 'terminated':
if (e.session == this.registerSession) {
this.callSession = null;
this.registerSession = null;
this.callStat = e.description;
}
else if (e.session == this.callSession) {
this.callTerminated(e.description);
}
break;
case 'i_ao_request':
{
if (e.session == this.callSession) {
var iSipResponseCode = e.getSipResponseCode();
if (iSipResponseCode == 180 || iSipResponseCode == 183) {
this.startRingbackTone();
this.callStat = 'Remote ringing...';
}
}
break;
}
case 'm_early_media':
{
if (e.session == this.callSession) {
this.stopRingbackTone();
this.stopRingTone();
this.callStat = 'Early media started';
}
break;
}
case 'm_local_hold_ok':
{
if (e.session == this.callSession) {
if (this.callSession.bTransfering) {
this.callSession.bTransfering = false;
// this.AVSession.TransferCall(this.transferUri);
}
this.btnHoldResumedvalue = 'Resume';
this.btnHoldResumedisabled = false;
this.callStat = 'Call placed on hold';
this.callSession.bHeld = true;
}
break;
}
case 'm_local_hold_nok':
{
if (e.session == this.callSession) {
this.callSession.bTransfering = false;
this.btnHoldResumedvalue = 'Hold';
this.btnHoldResumedisabled = false;
this.callStat = 'Failed to place remote party on hold';
}
break;
}
case 'm_local_resume_ok':
{
if (e.session == this.callSession) {
this.callSession.bTransfering = false;
this.btnHoldResumedvalue = 'Hold';
this.btnHoldResumedisabled = false;
this.callStat = 'Call taken off hold';
this.callSession.bHeld = false;
}
break;
}
case 'm_local_resume_nok':
{
if (e.session == this.callSession) {
this.callSession.bTransfering = false;
this.btnHoldResumedisabled = false;
this.callStat = 'Failed to unhold call';
}
break;
}
case 'm_remote_hold':
{
if (e.session == this.callSession) {
this.callStat = 'Placed on hold by remote party';
}
break;
}
case 'm_remote_resume':
{
if (e.session == this.callSession) {
this.callStat = 'Taken off hold by remote party';
}
break;
}
default:
this.callStat = e.type;
break;
}
console.info('call session event = ' + e.type);
};
PhoneService.prototype.callTerminated = function (description) {
this.callSession = null;
this.selectedUser = null;
this.selectedAgent = null;
this.displayText = null;
this.stopRingbackTone();
this.stopRingTone();
this.status = CallState.DialPadOutbound;
this.callStat = description;
};
PhoneService.prototype.makeCall = function () {
if (this.sipStack) {
// create call session
this.callSession = this.sipStack.newSession(this.call_type, this.configCall);
// make call
if (this.selectedUser) {
this.status = CallState.ActiveCallOutbound;
this.dial(this.selectedUser.phoneNumber);
}
else {
if (this.displayText) {
this.selectedUser = new User();
this.selectedUser.fullname = this.displayText;
this.selectedUser.phoneNumber = this.displayText;
this.status = CallState.ActiveCallOutbound;
this.dial(this.displayText);
}
}
}
};
PhoneService.prototype.dial = function (phoneNumber) {
if (this.callSession.call(phoneNumber) != 0) {
this.callSession = null;
this.callStat = 'Failed to make call';
return;
}
};
PhoneService.prototype.startRingTone = function () {
try {
(document.getElementById('ringtone')).play();
}
catch (e) { }
};
PhoneService.prototype.startRingbackTone = function () {
try {
(document.getElementById('ringbacktone')).play();
}
catch (e) { }
};
PhoneService.prototype.stopRingbackTone = function () {
try {
(document.getElementById('ringbacktone')).pause();
}
catch (e) { }
};
PhoneService.prototype.stopRingTone = function () {
try {
(document.getElementById('ringtone')).pause();
}
catch (e) { }
};
PhoneService.prototype.recordCall = function (x) {
try {
//start recording
if (x === "1") {
this.recordCallvalue = true;
}
}
catch (e) { }
};
PhoneService.decorators = [
{ type: Injectable },
];
/** @nocollapse */
PhoneService.ctorParameters = function () { return []; };
return PhoneService;
}());
export { PhoneService };
//# sourceMappingURL=phone-service.js.map