@wazo/sdk 0.39.0-beta.2 → 0.39.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/wazo-sdk.js +2 -2
- package/esm/domain/Phone/WebRTCPhone.js +8 -9
- package/esm/simple/room/Room.js +1 -1
- package/esm/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
- package/esm/types/web-rtc-client.d.ts +8 -0
- package/esm/types/web-rtc-client.d.ts.map +1 -1
- package/esm/web-rtc-client.js +75 -15
- package/lib/domain/Phone/WebRTCPhone.js +8 -9
- package/lib/simple/room/Room.js +1 -1
- package/lib/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
- package/lib/types/web-rtc-client.d.ts +8 -0
- package/lib/types/web-rtc-client.d.ts.map +1 -1
- package/lib/web-rtc-client.js +83 -15
- package/package.json +1 -1
- package/src/domain/Phone/WebRTCPhone.ts +7 -9
- package/src/simple/room/Room.ts +1 -1
- package/src/web-rtc-client.ts +86 -21
package/src/simple/room/Room.ts
CHANGED
|
@@ -219,7 +219,7 @@ class Room extends Emitter {
|
|
|
219
219
|
// Retrieve conference sources
|
|
220
220
|
const contacts = await getApiClient().dird.fetchConferenceContacts(sources.items[0]);
|
|
221
221
|
// Retrieve conference
|
|
222
|
-
const conference = contacts?.find(contact => contact.numbers?.find(number => number.number === extension));
|
|
222
|
+
const conference = contacts?.find(contact => contact.numbers?.find(number => String(number.number) === String(extension)));
|
|
223
223
|
logger.info('connected to room', {
|
|
224
224
|
sourceId: conference ? conference.sourceId : null,
|
|
225
225
|
name: conference ? conference.name : null,
|
package/src/web-rtc-client.ts
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
import 'webrtc-adapter';
|
|
5
5
|
import type { InviterInviteOptions } from 'sip.js/lib/api/inviter-invite-options';
|
|
6
6
|
import type { IncomingResponse } from 'sip.js/lib/core/messages/incoming-response';
|
|
7
|
+
import type { InvitationRejectOptions } from 'sip.js/lib/api/invitation-reject-options';
|
|
8
|
+
import type { InviterCancelOptions } from 'sip.js/lib/api/inviter-cancel-options';
|
|
9
|
+
import type { SessionByeOptions } from 'sip.js/lib/api/session-bye-options';
|
|
10
|
+
import type { InvitationAcceptOptions } from 'sip.js/lib/api/invitation-accept-options';
|
|
7
11
|
|
|
8
12
|
import type { SessionDialog } from 'sip.js/lib/core/dialogs/session-dialog';
|
|
9
13
|
import type { IncomingRequestMessage } from 'sip.js/lib/core/messages/incoming-request-message';
|
|
@@ -655,7 +659,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
655
659
|
const options = {
|
|
656
660
|
sessionDescriptionHandlerOptions: this.getMediaConfiguration(enableVideo || false),
|
|
657
661
|
};
|
|
658
|
-
return
|
|
662
|
+
return this._accept(session, options).then(() => {
|
|
659
663
|
// @ts-ignore
|
|
660
664
|
if (session.isCanceled) {
|
|
661
665
|
const message = 'accepted a canceled session (or was canceled during the accept phase).';
|
|
@@ -676,14 +680,8 @@ export default class WebRTCClient extends Emitter {
|
|
|
676
680
|
}
|
|
677
681
|
|
|
678
682
|
async hangup(session: Invitation | Inviter): Promise<OutgoingByeRequest | null> {
|
|
679
|
-
const {
|
|
680
|
-
|
|
681
|
-
id,
|
|
682
|
-
}: any = session;
|
|
683
|
-
logger.info('sdk webrtc hangup call', {
|
|
684
|
-
id,
|
|
685
|
-
state,
|
|
686
|
-
});
|
|
683
|
+
const { state, id }: any = session;
|
|
684
|
+
logger.info('sdk webrtc hangup call', { id, state });
|
|
687
685
|
|
|
688
686
|
try {
|
|
689
687
|
this._stopSendingStats(session);
|
|
@@ -694,17 +692,11 @@ export default class WebRTCClient extends Emitter {
|
|
|
694
692
|
// Check if Invitation or Inviter (Invitation = incoming call)
|
|
695
693
|
const isInviter = session instanceof Inviter;
|
|
696
694
|
|
|
697
|
-
const cancel = () => (<Inviter>session).cancel();
|
|
698
|
-
|
|
699
|
-
const reject = () => (<Invitation>session).reject();
|
|
700
|
-
|
|
701
|
-
const bye = () => session.bye && session.bye();
|
|
702
|
-
|
|
703
695
|
// @see github.com/onsip/SIP.js/blob/f11dfd584bc9788ccfc94e03034020672b738975/src/platform/web/simple-user/simple-user.ts#L1004
|
|
704
696
|
const actions: Record<string, any> = {
|
|
705
|
-
[SessionState.Initial]: isInviter ?
|
|
706
|
-
[SessionState.Establishing]: isInviter ?
|
|
707
|
-
[SessionState.Established]:
|
|
697
|
+
[SessionState.Initial]: isInviter ? this._cancel.bind(this, session) : this._reject.bind(this, session),
|
|
698
|
+
[SessionState.Establishing]: isInviter ? this._cancel.bind(this, session) : this._reject.bind(this, session),
|
|
699
|
+
[SessionState.Established]: this._bye.bind(this, session),
|
|
708
700
|
};
|
|
709
701
|
|
|
710
702
|
// Handle different session status
|
|
@@ -712,7 +704,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
712
704
|
return await actions[state]();
|
|
713
705
|
}
|
|
714
706
|
|
|
715
|
-
return await
|
|
707
|
+
return await this._bye(session);
|
|
716
708
|
} catch (error: any) {
|
|
717
709
|
logger.warn('sdk webrtc hangup, error', error);
|
|
718
710
|
}
|
|
@@ -763,11 +755,11 @@ export default class WebRTCClient extends Emitter {
|
|
|
763
755
|
|
|
764
756
|
try {
|
|
765
757
|
if (session instanceof Invitation) {
|
|
766
|
-
return
|
|
758
|
+
return this._reject(session);
|
|
767
759
|
}
|
|
768
760
|
|
|
769
761
|
if (session instanceof Inviter) {
|
|
770
|
-
return
|
|
762
|
+
return this._cancel(session);
|
|
771
763
|
}
|
|
772
764
|
} catch (e: any) {
|
|
773
765
|
logger.warn('Error when rejecting call', e.message, e.stack);
|
|
@@ -2598,4 +2590,77 @@ export default class WebRTCClient extends Emitter {
|
|
|
2598
2590
|
this.sessionNetworkStats[sessionId].push(networkStats);
|
|
2599
2591
|
}
|
|
2600
2592
|
|
|
2593
|
+
async _accept(session: Invitation, options: InvitationAcceptOptions = {}) {
|
|
2594
|
+
if (session.state === SessionState.Terminated || session.state === SessionState.Terminating) {
|
|
2595
|
+
const error = 'Trying to accept a terminated sipSession.';
|
|
2596
|
+
logger.warn(error, { state: session.state, sessionId: session.id });
|
|
2597
|
+
throw new Error(error);
|
|
2598
|
+
}
|
|
2599
|
+
|
|
2600
|
+
if (session.state !== SessionState.Initial) {
|
|
2601
|
+
const error = 'Trying to accept a non Initial sipSession.';
|
|
2602
|
+
logger.warn(error, { state: session.state, sessionId: session.id });
|
|
2603
|
+
throw new Error(error);
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
// @ts-ignore
|
|
2607
|
+
if (!session.incomingInviteRequest.acceptable) {
|
|
2608
|
+
const error = 'Trying to reject a non `acceptable` session';
|
|
2609
|
+
logger.warn(error, { state: session.state, sessionId: session.id });
|
|
2610
|
+
throw new Error(error);
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2613
|
+
try {
|
|
2614
|
+
return await session.accept(options);
|
|
2615
|
+
} catch (e) {
|
|
2616
|
+
logger.warn('Session accept, error', e);
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
|
|
2620
|
+
async _reject(session: Invitation, options: InvitationRejectOptions = {}) {
|
|
2621
|
+
if (session.state !== SessionState.Initial && session.state !== SessionState.Establishing) {
|
|
2622
|
+
logger.warn('Trying to reject a session in a wrong state', { state: session.state, sessionId: session.id });
|
|
2623
|
+
return;
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2626
|
+
// @ts-ignore
|
|
2627
|
+
if (!session.incomingInviteRequest.rejectable) {
|
|
2628
|
+
logger.warn('Trying to reject a non `rejectable` session', { state: session.state, sessionId: session.id });
|
|
2629
|
+
return;
|
|
2630
|
+
}
|
|
2631
|
+
|
|
2632
|
+
try {
|
|
2633
|
+
return await session.reject(options);
|
|
2634
|
+
} catch (e) {
|
|
2635
|
+
logger.warn('Session reject, error', e);
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2638
|
+
|
|
2639
|
+
async _cancel(session: Inviter, options: InviterCancelOptions = {}) {
|
|
2640
|
+
if (session.state !== SessionState.Initial && session.state !== SessionState.Establishing) {
|
|
2641
|
+
logger.warn('Trying to cancel a session in a wrong state', { state: session.state, sessionId: session.id });
|
|
2642
|
+
return;
|
|
2643
|
+
}
|
|
2644
|
+
|
|
2645
|
+
try {
|
|
2646
|
+
return await session.cancel(options);
|
|
2647
|
+
} catch (e) {
|
|
2648
|
+
logger.warn('Session cancel, error', e);
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
|
|
2652
|
+
async _bye(session: Invitation | Inviter, options: SessionByeOptions = {}) {
|
|
2653
|
+
if (session.state !== SessionState.Established) {
|
|
2654
|
+
logger.warn('Trying to end a session in a wrong state', { state: session.state, sessionId: session.id });
|
|
2655
|
+
return null;
|
|
2656
|
+
}
|
|
2657
|
+
|
|
2658
|
+
try {
|
|
2659
|
+
return await session.bye(options);
|
|
2660
|
+
} catch (e) {
|
|
2661
|
+
logger.warn('Session bye, error', e);
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
return null;
|
|
2665
|
+
}
|
|
2601
2666
|
}
|