Skip to content

Commit

Permalink
feat(calling): move apis, listeners from calling client to line
Browse files Browse the repository at this point in the history
  • Loading branch information
ShreyasSharma28 committed Sep 27, 2023
1 parent fda9674 commit 701551b
Show file tree
Hide file tree
Showing 16 changed files with 561 additions and 309 deletions.
41 changes: 21 additions & 20 deletions docs/samples/calling/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,13 @@ function toggleDisplay(elementId, status) {
}
}

const callNotifyEvent = new CustomEvent('callingClient:incoming_call', {
const callNotifyEvent = new CustomEvent('line:incoming_call', {
detail: {
callObject: call,
},
});

callListener.addEventListener('callingClient:incoming_call', (myEvent) => {
callListener.addEventListener('line:incoming_call', (myEvent) => {
console.log('Received incoming call');
answerElm.disabled = false;
const callerDisplay = myEvent.detail.callObject.getCallerInfo();
Expand Down Expand Up @@ -345,9 +345,9 @@ function createDevice() {
});

// Start listening for incoming calls
callingClient.on('callingClient:incoming_call', (callObj) => {
line.on('line:incoming_call', (callObj) => {
call = callObj;
call.on('call:caller_id', (CallerIdEmitter) => {
call.on('caller_id', (CallerIdEmitter) => {
callDetailsElm.innerText = `Name: ${CallerIdEmitter.callerId.name}, Number: ${CallerIdEmitter.callerId.num}, Avatar: ${CallerIdEmitter.callerId.avatarSrc}, UserId: ${CallerIdEmitter.callerId.id}`;
console.log(
`callerId : Name: ${CallerIdEmitter.callerId.name}, Number: ${CallerIdEmitter.callerId.name}, Avatar: ${CallerIdEmitter.callerId.avatarSrc}, UserId: ${CallerIdEmitter.callerId.id}`
Expand Down Expand Up @@ -407,14 +407,14 @@ function muteUnmute() {
function holdResume() {
const elem = document.getElementById('hold_button');

call.on('call:held', (correlationId) => {
call.on('held', (correlationId) => {
if (elem.value === 'Hold') {
callDetailsElm.innerText = 'Call is held';
elem.value = 'Resume';
}
});

call.on('call:resumed', (correlationId) => {
call.on('resumed', (correlationId) => {
if (elem.value === 'Resume') {
callDetailsElm.innerText = 'Call is Resumed';
elem.value = 'Hold';
Expand Down Expand Up @@ -477,12 +477,13 @@ function createCall(e) {

console.log(destination.value);

call = callingClient.makeCall({

call = line.makeCall({
type: 'uri',
address: destination.value,
});

call.on('call:caller_id', (CallerIdEmitter) => {
call.on('caller_id', (CallerIdEmitter) => {
callDetailsElm.innerText = `Name: ${CallerIdEmitter.callerId.name}, Number: ${CallerIdEmitter.callerId.num}, Avatar: ${CallerIdEmitter.callerId.avatarSrc} , UserId: ${CallerIdEmitter.callerId.id}`;
console.log(
`callerId : Name: ${CallerIdEmitter.callerId.name}, Number: ${CallerIdEmitter.callerId.num}, Avatar: ${CallerIdEmitter.callerId.avatarSrc}, UserId: ${CallerIdEmitter.callerId.id}`
Expand All @@ -493,19 +494,19 @@ function createCall(e) {
}
});

call.on('call:progress', (correlationId) => {
call.on('progress', (correlationId) => {
callDetailsElm.innerText = `${correlationId}: Call Progress`;
});
call.on('call:connect', (correlationId) => {
call.on('connect', (correlationId) => {
callDetailsElm.innerText = `${correlationId}: Call Connect`;
});
call.on('call:established', (correlationId) => {
call.on('established', (correlationId) => {
callDetailsElm.innerText = `${correlationId}: Call Established`;
transferElm.disabled = false;
outboundEndElm.disabled = false;
makeCallBtn.disabled = true;
});
call.on('call:disconnect', (correlationId) => {
call.on('disconnect', (correlationId) => {
callDetailsElm.innerText = `${correlationId}: Call Disconnected`;
makeCallBtn.disabled = false;
endElm.disabled = true;
Expand All @@ -519,7 +520,7 @@ function createCall(e) {
}
});

call.on('call:remote_media', (track) => {
call.on('remote_media', (track) => {
document.getElementById('remote-audio').srcObject = new MediaStream([track]);
});

Expand Down Expand Up @@ -561,20 +562,20 @@ function commitTransfer() {
address: digit,
});

callTranferObj.on('call:remote_media', (track) => {
callTranferObj.on('remote_media', (track) => {
document.getElementById('remote-audio').srcObject = new MediaStream([track]);

transferDetailsElm.innerText = `Got remote audio`;
});

callTranferObj.on('call:established', (correlationId) => {
callTranferObj.on('established', (correlationId) => {
transferDetailsElm.innerText = `${correlationId}: Transfer target connected`;
endSecondElm.disabled = false;
transferElm.innerHTML = 'Commit';
transferElm.disabled = false;
});

callTranferObj.on('call:disconnect', (correlationId) => {
callTranferObj.on('disconnect', (correlationId) => {
endSecondElm.disabled = true;
callTranferObj = null;
});
Expand All @@ -595,7 +596,7 @@ function initiateTransfer() {
if (!call.isHeld()) {
call.doHoldResume();

call.on('call:held', (correlationId) => {
call.on('held', (correlationId) => {
transferDetailsElm.innerText = `Placed call: ${call.getCorrelationId()} on hold`;
commitTransfer();
});
Expand Down Expand Up @@ -677,16 +678,16 @@ function answer() {
answerElm.disabled = true;

if (call) {
call.on('call:established', (correlationId) => {
call.on('established', (correlationId) => {
callDetailsElm.innerText = `${correlationId}: Call Established`;
console.log(` Call is Established: ${correlationId}`);
endElm.disabled = false;
});
call.on('call:disconnect', () => {
call.on('disconnect', () => {
console.log(` Call is Disconnected: ${correlationId}`);
});

call.on('call:remote_media', (track) => {
call.on('remote_media', (track) => {
document.getElementById('remote-audio').srcObject = new MediaStream([track]);
});

Expand Down
13 changes: 8 additions & 5 deletions packages/calling/src/CallHistory/CallHistory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {SORT, SORT_BY, WebexRequestPayload} from '../common/types';
import {CallHistory, createCallHistoryClient} from './CallHistory';
import {ICallHistory} from './types';
import {sortedCallHistory, mockCallHistoryBody, MOCK_SESSION_EVENT} from './callHistoryFixtures';
import {CallSessionEvent, EVENT_KEYS, MOBIUS_EVENT_KEYS} from '../Events/types';
import {COMMON_EVENT_KEYS, CallSessionEvent, MOBIUS_EVENT_KEYS} from '../Events/types';

const webex = getTestUtilsWebex();

Expand Down Expand Up @@ -82,10 +82,13 @@ describe('Call history tests', () => {
});

it('verify the recent user session event ', (done) => {
callHistory.on(EVENT_KEYS.CALL_HISTORY_USER_SESSION_INFO, (event: CallSessionEvent) => {
expect(event.data).toEqual(MOCK_SESSION_EVENT.data);
done();
});
callHistory.on(
COMMON_EVENT_KEYS.CALL_HISTORY_USER_SESSION_INFO,
(event: CallSessionEvent) => {
expect(event.data).toEqual(MOCK_SESSION_EVENT.data);
done();
}
);

expect(mockOn.mock.calls[0][0]).toEqual(MOBIUS_EVENT_KEYS.CALL_SESSION_EVENT_INCLUSIVE);
const callSessionCallback = mockOn.mock.calls[0][1];
Expand Down
4 changes: 2 additions & 2 deletions packages/calling/src/CallHistory/CallHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {serviceErrorCodeHandler} from '../common/Utils';
import {CALL_HISTORY_FILE, FROM_DATE, HISTORY, LIMIT, NUMBER_OF_DAYS} from './constants';
import {STATUS_CODE, SUCCESS_MESSAGE, USER_SESSIONS} from '../common/constants';
import {
COMMON_EVENT_KEYS,
CallHistoryEventTypes,
CallSessionEvent,
EVENT_KEYS,
MOBIUS_EVENT_KEYS,
UserSession,
} from '../Events/types';
Expand Down Expand Up @@ -143,7 +143,7 @@ export class CallHistory extends Eventing<CallHistoryEventTypes> implements ICal
MOBIUS_EVENT_KEYS.CALL_SESSION_EVENT_INCLUSIVE,
async (event?: CallSessionEvent) => {
if (event && event.data.userSessions.userSessions) {
this.emit(EVENT_KEYS.CALL_HISTORY_USER_SESSION_INFO, event as CallSessionEvent);
this.emit(COMMON_EVENT_KEYS.CALL_HISTORY_USER_SESSION_INFO, event as CallSessionEvent);
}
}
);
Expand Down
Loading

0 comments on commit 701551b

Please sign in to comment.