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

Initial implementation of AssetSubscriber class #1

Merged
merged 11 commits into from
Dec 11, 2020
Prev Previous commit
Next Next commit
stop requiring clientId in ablyOptions
  • Loading branch information
owenpearson committed Dec 4, 2020
commit e10185eb35b630cbc21d31ca65415a442960a42c
11 changes: 2 additions & 9 deletions src/lib/AssetConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ enum ClientTypes {
class AssetConnection {
logger: Logger;
ably: AblyTypes.RealtimePromise;
clientId: string;
channel: AblyTypes.RealtimeChannelPromise;
trackingId: string;
onRawLocationUpdate?: LocationListener;
Expand All @@ -36,12 +35,6 @@ class AssetConnection {
this.onEnhancedLocationUpdate = onEnhancedLocationUpdate;
this.onStatusUpdate = onStatusUpdate;

if (!ablyOptions.clientId) {
logger.logError('ablyOptions.clientId must be provided');
throw new Error('ablyOptions.clientId must be provided');
}

this.clientId = ablyOptions.clientId;
this.ably = new Ably.Realtime.Promise(ablyOptions);
this.channel = this.ably.channels.get(trackingId, {
params: { rewind: '1' },
Expand Down Expand Up @@ -78,7 +71,7 @@ class AssetConnection {

private async joinChannelPresence() {
this.channel.presence.subscribe(this.onPresenceMessage);
this.channel.presence.enterClient(this.clientId, ClientTypes.subscriber).catch((reason) => {
this.channel.presence.enterClient(this.ably.auth.clientId, ClientTypes.subscriber).catch((reason) => {
this.logger.logError(`Error entering channel presence: ${reason}`);
throw new Error(reason);
});
Expand All @@ -87,7 +80,7 @@ class AssetConnection {
private leaveChannelPresence() {
this.channel.presence.unsubscribe();
this.notifyAssetIsOffline();
this.channel.presence.leaveClient(this.clientId, ClientTypes.subscriber).catch((reason) => {
this.channel.presence.leaveClient(this.ably.auth.clientId, ClientTypes.subscriber).catch((reason) => {
this.logger.logError(`Error leaving channel presence: ${reason}`);
throw new Error(reason);
});
Expand Down