Skip to content

Commit

Permalink
Merge pull request #107 from open-voip-alliance/log-for-invalid-dialo…
Browse files Browse the repository at this point in the history
…g-node

Added logging when a subscription dialog is invalid
  • Loading branch information
patrickswijgman authored Mar 7, 2022
2 parents 3973910 + 7f68dec commit 3ec5e4e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webphone-lib",
"version": "0.2.19",
"version": "0.2.19-beta.1",
"description": "Webphone Lib",
"author": "Open VoIP Alliance",
"license": "MIT",
Expand Down
14 changes: 11 additions & 3 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ export class ClientImpl extends EventEmitter implements IClient {

return new Promise<void>((resolve, reject) => {
if (this.subscriptions[uri]) {
log.info('Already subscribed', this.constructor.name);

log.debug(`[blf] Already subscribed to ${uri}`, this.constructor.name);
resolve();
return;
}
Expand All @@ -251,24 +250,32 @@ export class ClientImpl extends EventEmitter implements IClient {
this.subscriptions[uri].delegate = {
onNotify: (notification: Notification) => {
notification.accept();
this.emit('subscriptionNotify', uri, statusFromDialog(notification));
const status = statusFromDialog(notification);
log.debug(
`[blf] ${notification} \n accepted, emitting notify event with status ${status}`,
'client.subscriptions.delegate.onNotify'
);
this.emit('subscriptionNotify', uri, status);
}
};

this.subscriptions[uri].stateChange.on((newState: SubscriptionState) => {
switch (newState) {
case SubscriptionState.Subscribed:
log.debug(`[blf] Already subscribed to ${uri}`, this.constructor.name);
resolve();
break;
case SubscriptionState.Terminated:
delete this.subscriptions[uri];
log.debug(`[blf] subscription terminated for ${uri}`, this.constructor.name);
this.emit('subscriptionTerminated', uri);
break;
}
});

this.subscriptions[uri].on('failed', (response: Core.IncomingResponseMessage) => {
if (!response) {
log.error(`[blf] subscription failed for ${uri}`, this.constructor.name);
this.removeSubscription({ uri });
reject();
return;
Expand Down Expand Up @@ -296,6 +303,7 @@ export class ClientImpl extends EventEmitter implements IClient {
this.subscriptions[uri].subscribe();
});
}

public async resubscribe(uri: string): Promise<void> {
if (!this.subscriptions[uri]) {
throw new Error('Cannot resubscribe to nonexistent subscription.');
Expand Down
6 changes: 6 additions & 0 deletions src/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { SubscriptionStatus } from './enums';

export { Subscription } from 'sip.js';

import { log } from './logger';

/**
* Parse an incoming dialog XML request body and return
* the account state from it.
Expand All @@ -14,6 +16,10 @@ export function statusFromDialog(notification: any): SubscriptionStatus | string
const dialogNode = xmlDoc ? xmlDoc.getElementsByTagName('dialog-info')[0] : null;
// Skip; an invalid dialog.
if (!dialogNode) {
log.error(
`[blf] ${notification} \n did not result in a valid dialogNode`,
'subscription.statusFromDialog'
);
return null;
}

Expand Down

0 comments on commit 3ec5e4e

Please sign in to comment.