Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added logging when a subscription dialog is invalid #107

Merged
merged 4 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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