Skip to content

Commit

Permalink
fix: fixes to widget call [WTEL-4003]
Browse files Browse the repository at this point in the history
  • Loading branch information
dlohvinov committed Nov 3, 2023
1 parent 29f4afb commit 1ef0b83
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions src/modules/call/store/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const actions = {

const configuration = {
sockets: [socket],
// uri: 'sip:[email protected]',
uri: `sip:${context.rootState.config.call.id}@${hostname}`,
register: false,
};
Expand All @@ -58,39 +57,50 @@ const actions = {
MAKE_CALL: async (context, { initWithMuted }) => {
await context.dispatch('now/SET_NOW_WATCHER');

const initAudio = () => {
const audio = new Audio();
audio.autoplay = true;
// eslint-disable-next-line prefer-destructuring
audio.srcObject = context.state.session.connection.getRemoteStreams()[0];
context.commit('SET_SESSION_AUDIO', audio);
if (initWithMuted) context.dispatch('TOGGLE_MUTE', true);
};

const closeSession = () => {
// https://stackoverflow.com/questions/8864617/how-do-i-remove-properly-html5-audio-without-appending-to-dom
// eslint-disable-next-line no-param-reassign
if (context.state.sessionAudio) context.state.sessionAudio.srcObject = null;
context.commit('SET_SESSION_STATE', SessionState.IDLE);
context.commit('SET_SESSION_AUDIO', null);
context.commit('SET_SESSION_MUTE', false);
context.commit('SET_SESSION_DTMF', '');
context.commit('SET_SESSION', null);
context.dispatch('CLOSE_USER_AGENT');
context.dispatch('now/SET_NOW_WATCHER');
};

const eventHandlers = {
progress(event) { // ringing
progress() { // ringing
context.commit('SET_SESSION_STATE', SessionState.RINGING);
console.warn(event, 'event');

const audio = new Audio();
audio.autoplay = true;
// eslint-disable-next-line prefer-destructuring
audio.srcObject = this.connection.getRemoteStreams()[0];
context.commit('SET_SESSION_AUDIO', audio);
initAudio();
},
// 200 OK
confirmed: () => context.commit('SET_SESSION_STATE', SessionState.ACTIVE),
confirmed: () => {
context.commit('SET_SESSION_STATE', SessionState.ACTIVE);
if (!context.state.sessionAudio) initAudio();
},
hold: () => context.commit('SET_SESSION_STATE', SessionState.HOLD),
unhold: () => context.commit('SET_SESSION_STATE', SessionState.ACTIVE),
muted: () => context.commit('SET_SESSION_MUTE', true),
unmuted: () => context.commit('SET_SESSION_MUTE', false),
newDTMF: ({ originator, dtmf }) => originator === 'local' && context.commit('NEW_SESSION_DTMF', dtmf.tone),
// bug
failed: (event) => console.error('call failed with cause', event),
// bye
ended: () => {
// https://stackoverflow.com/questions/8864617/how-do-i-remove-properly-html5-audio-without-appending-to-dom
// eslint-disable-next-line no-param-reassign
context.state.sessionAudio.srcObject = null;
context.commit('SET_SESSION_STATE', SessionState.IDLE);
context.commit('SET_SESSION_AUDIO', null);
context.commit('SET_SESSION_MUTE', false);
context.commit('SET_SESSION_DTMF', '');
context.commit('SET_SESSION', null);
context.dispatch('CLOSE_USER_AGENT');
context.dispatch('now/SET_NOW_WATCHER');
failed: (event) => {
console.error('call failed with cause', event);
closeSession();
},
// bye
ended: () => closeSession(),
};

await context.dispatch('START_USER_AGENT');
Expand All @@ -103,7 +113,6 @@ const actions = {
const session = context.state.userAgent.call('sip:[email protected]', options);
window.session = session;
context.commit('SET_SESSION', session);
if (initWithMuted) await context.dispatch('TOGGLE_MUTE', true);
},
HANGUP: (context) => {
context.state.session.terminate();
Expand All @@ -120,13 +129,13 @@ const actions = {
const { session } = context.state;
// checking typeof because toggle button can send event
if (value !== undefined && typeof value === 'boolean') {
if (value) session.mute();
else session.unmute();
if (value) return session.mute();
else return session.unmute();
}
if (session.isMuted().audio) {
session.unmute();
return session.unmute();
} else {
session.mute();
return session.mute();
}
},
SEND_DTMF: (context, digit) => {
Expand Down

0 comments on commit 1ef0b83

Please sign in to comment.