Skip to content

Commit

Permalink
verify existence of granted argument on subscribe callback
Browse files Browse the repository at this point in the history
  • Loading branch information
SlevinBE authored and sclausen committed May 8, 2018
1 parent 5bd3199 commit 83b59ed
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/mqtt.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,16 @@ export class MqttService {
() => {
const subscription: Subscription = new Subscription();
this.client.subscribe(filterString, (err, granted: ISubscriptionGrant[]) => {
granted.forEach((granted_: ISubscriptionGrant) => {
if (granted_.qos === 128) {
delete this.observables[granted_.topic];
this.client.unsubscribe(granted_.topic);
rejected.error(`subscription for '${granted_.topic}' rejected!`);
}
this._onSuback.emit({ filter: filterString, granted: granted_.qos !== 128 });
});
if(granted) { // granted can be undefined when an error occurs when the client is disconnecting
granted.forEach((granted_: ISubscriptionGrant) => {
if (granted_.qos === 128) {
delete this.observables[granted_.topic];
this.client.unsubscribe(granted_.topic);
rejected.error(`subscription for '${granted_.topic}' rejected!`);
}
this._onSuback.emit({filter: filterString, granted: granted_.qos !== 128});
});
}
});
subscription.add(() => {
delete this.observables[filterString];
Expand Down

0 comments on commit 83b59ed

Please sign in to comment.