Skip to content

Commit

Permalink
Merge pull request #754 from wazo-platform/on_progress_180
Browse files Browse the repository at this point in the history
Trigger onProgress event only when receiving a 180 message
  • Loading branch information
manuquentin authored Mar 1, 2024
2 parents 079bbfe + d821745 commit 5c4117d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
20 changes: 8 additions & 12 deletions src/domain/Phone/WebRTCPhone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,18 +387,6 @@ export default class WebRTCPhone extends Emitter implements Phone {

sipSession.stateChange.addListener((newState: SessionState) => {
switch (newState) {
case SessionState.Establishing:
if (sipSession instanceof Invitation) {
// No need to trigger progress for an invitation (eg: when we answer the call).
return;
}

// When receiving a progress event, we know we are the caller so we have to force incoming to false
return this.eventEmitter.emit(ON_PROGRESS, this._createCallSession(sipSession, null, {
incoming: false,
ringing: true,
}), this.audioOutputDeviceId, this.audioOutputVolume);

case SessionState.Terminating:
logger.info('WebRTC phone - call terminating', {
sipId: sipSession.id,
Expand Down Expand Up @@ -1586,6 +1574,14 @@ export default class WebRTCPhone extends Emitter implements Phone {
logger.info('WebRTC disconnected');
this.eventEmitter.emit(ON_DISCONNECTED);
});
this.client.on(this.client.ON_PROGRESS, session => {
logger.info('WebRTC progess (180)');

this.eventEmitter.emit(ON_PROGRESS, this._createCallSession(session, null, {
incoming: false,
ringing: true,
}), this.audioOutputDeviceId, this.audioOutputVolume);
});
this.client.on(this.client.ON_EARLY_MEDIA, session => {
logger.info('WebRTC early media');

Expand Down
15 changes: 9 additions & 6 deletions src/web-rtc-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const MESSAGE = 'message';
const ACCEPTED = 'accepted';
const REJECTED = 'rejected';
const ON_TRACK = 'onTrack';
const ON_PROGRESS = 'onProgress';
const ON_EARLY_MEDIA = 'onEarlyMedia';
const ON_REINVITE = 'reinvite';
const ON_ERROR = 'onError';
Expand Down Expand Up @@ -160,6 +161,8 @@ export default class WebRTCClient extends Emitter {

ON_EARLY_MEDIA: string;

ON_PROGRESS: string;

ON_DISCONNECTED: string;

static isAPrivateIp(ip: string): boolean {
Expand Down Expand Up @@ -236,6 +239,7 @@ export default class WebRTCClient extends Emitter {
this.ON_NETWORK_STATS = ON_NETWORK_STATS;
this.ON_DISCONNECTED = ON_DISCONNECTED;
this.ON_EARLY_MEDIA = ON_EARLY_MEDIA;
this.ON_PROGRESS = ON_PROGRESS;
}

configureMedia(media: MediaConfig) {
Expand Down Expand Up @@ -594,9 +598,7 @@ export default class WebRTCClient extends Emitter {
this._onAccepted(session as WazoSession, response.session, true);
},
onProgress: (payload: IncomingResponse) => {
if (payload.message.statusCode === 183) {
this._onEarlyProgress(payload.session);
}
this._onProgress(payload.session, payload.message.statusCode === 183);
},
onReject: (response: IncomingResponse) => {
logger.info('on call rejected', {
Expand Down Expand Up @@ -2167,15 +2169,16 @@ export default class WebRTCClient extends Emitter {
};
}

_onEarlyProgress(session: WazoSession): void {
_onProgress(session: WazoSession, early = false): void {
this._setupMedias(session);

const sessionId = this.getSipSessionId(session).substr(0, 20);
this.updateRemoteStream(sessionId);
logger.info('Early media progress progress received', {
logger.info('progress received', {
sessionId,
early,
});
this.eventEmitter.emit(ON_EARLY_MEDIA, session);
this.eventEmitter.emit(early ? ON_EARLY_MEDIA : ON_PROGRESS, session);
}

_onAccepted(session: WazoSession, sessionDialog?: SessionDialog, withEvent = true, initAllTracks = true): void {
Expand Down

0 comments on commit 5c4117d

Please sign in to comment.