Skip to content

Commit

Permalink
fix: firefox call twice fix [WTEL-4036]
Browse files Browse the repository at this point in the history
  • Loading branch information
dlohvinov committed Nov 20, 2023
1 parent 05ec73c commit 54daa73
Showing 1 changed file with 38 additions and 28 deletions.
66 changes: 38 additions & 28 deletions src/modules/call/store/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ReactiveNowStoreModule
import SessionState from '../enums/SessionState.enum';

const state = {
// incapsulated
// encapsulated
userAgent: null,
session: null,
sessionAudio: null,
Expand All @@ -28,26 +28,36 @@ const getters = {

const actions = {
START_USER_AGENT: (context) => {
const socket = new JsSIP.WebSocketInterface(context.rootState.config.call.url);
JsSIP.debug.enable('JsSIP:*');

const { hostname } = new URL(context.rootState.config.call.url);

const configuration = {
sockets: [socket],
uri: `sip:${context.rootState.config.call.id}@${hostname}`,
register: false,
};
const userAgent = new JsSIP.UA(configuration);

userAgent.start();

context.commit('SET_USER_AGENT', userAgent);

window.addEventListener('beforeunload', async (event) => {
await context.dispatch('CLOSE_USER_AGENT');
// eslint-disable-next-line no-param-reassign
delete event.returnValue; // page will always reload
return new Promise((resolve, reject) => {
try {
const socket = new JsSIP.WebSocketInterface(context.rootState.config.call.url);
// JsSIP.debug.enable('JsSIP:*');

const { hostname } = new URL(context.rootState.config.call.url);

const configuration = {
sockets: [socket],
uri: `sip:${context.rootState.config.call.id}@${hostname}`,
register: false,
};
const userAgent = new JsSIP.UA(configuration);

userAgent.start();

context.commit('SET_USER_AGENT', userAgent);

window.addEventListener('beforeunload', async (event) => {
await context.dispatch('CLOSE_USER_AGENT');
// eslint-disable-next-line no-param-reassign
delete event.returnValue; // page will always reload
});

userAgent.on('connected', () => {
resolve();
});
} catch (err) {
reject(err);
}
});
},
CLOSE_USER_AGENT: (context) => {
Expand Down Expand Up @@ -95,7 +105,10 @@ const actions = {
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' &&
newDTMF: ({
originator,
dtmf,
}) => originator === 'local' &&
context.commit('NEW_SESSION_DTMF', dtmf.tone),
// bug
failed: (event) => {
Expand All @@ -113,12 +126,9 @@ const actions = {
mediaConstraints: { audio: true },
sessionTimersExpires: 300,
};
// setTimeout(() => {

const session = context.state.userAgent.call('sip:[email protected]', options);
window.session = session;
context.commit('SET_SESSION', session);
// }, 500);
const session = context.state.userAgent.call('sip:[email protected]', options);
window.session = session;
context.commit('SET_SESSION', session);
},
HANGUP: (context) => {
context.state.session.terminate();
Expand Down

0 comments on commit 54daa73

Please sign in to comment.