Skip to content

Commit

Permalink
Merge pull request #225 from ably-labs/remove-presence-absent
Browse files Browse the repository at this point in the history
presence: remove absent event from public enums
  • Loading branch information
AndyTWF authored Jun 25, 2024
2 parents 246fbd6 + 9e2659b commit 01b1102
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
21 changes: 12 additions & 9 deletions src/Presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ interface PresenceEventsMap {
[PresenceEvents.leave]: PresenceEvent;
[PresenceEvents.update]: PresenceEvent;
[PresenceEvents.present]: PresenceEvent;
[PresenceEvents.absent]: PresenceEvent;
}

/**
Expand Down Expand Up @@ -74,7 +73,7 @@ export interface PresenceMember {
/**
* The current state of the presence member.
*/
action: 'absent' | 'present' | 'enter' | 'leave' | 'update';
action: 'present' | 'enter' | 'leave' | 'update';

/**
* The extras associated with the presence member.
Expand Down Expand Up @@ -143,7 +142,7 @@ export interface Presence {

/**
* Subscribe the given listener from the given list of events.
* @param eventOrEvents {'enter' | 'leave' | 'update' | 'absent' | 'present'} single event name or array of events to subscribe to
* @param eventOrEvents {'enter' | 'leave' | 'update' | 'present'} single event name or array of events to subscribe to
* @param listener listener to subscribe
*/
subscribe(eventOrEvents: PresenceEvents | PresenceEvents[], listener?: PresenceListener): Promise<void>;
Expand All @@ -156,7 +155,7 @@ export interface Presence {

/**
* Unsubscribe the given listener from the given list of events.
* @param eventOrEvents {'enter' | 'leave' | 'update' | 'present' | 'absent'} single event name or array of events to unsubscribe from
* @param eventOrEvents {'enter' | 'leave' | 'update' | 'present'} single event name or array of events to unsubscribe from
* @param listener listener to unsubscribe
*/
unsubscribe(eventOrEvents: PresenceEvents | PresenceEvents[], listener?: PresenceListener): Promise<void>;
Expand Down Expand Up @@ -210,9 +209,11 @@ export class DefaultPresence extends EventEmitter<PresenceEventsMap> implements
async get(params?: Ably.RealtimePresenceParams): Promise<PresenceMember[]> {
this._logger.trace('Presence.get()', { params });
const userOnPresence = await this.subscriptionManager.channel.presence.get(params);

// ably-js never emits the 'absent' event, so we can safely ignore it here.
return userOnPresence.map((user) => ({
clientId: user.clientId,
action: user.action,
action: user.action as PresenceEvents,
data: user.data ? (JSON.parse(user.data).userCustomData as PresenceData) : undefined,
timestamp: user.timestamp,
extras: user.extras,
Expand Down Expand Up @@ -269,7 +270,7 @@ export class DefaultPresence extends EventEmitter<PresenceEventsMap> implements

/**
* Subscribe the given listener from the given list of events.
* @param eventOrEvents {'enter' | 'leave' | 'update' | 'absent' | 'present'} single event name or array of events to subscribe to
* @param eventOrEvents {'enter' | 'leave' | 'update' | 'present'} single event name or array of events to subscribe to
* @param listener listener to subscribe
*/
subscribe(eventOrEvents: PresenceEvents | PresenceEvents[], listener?: PresenceListener): Promise<void>;
Expand Down Expand Up @@ -302,7 +303,7 @@ export class DefaultPresence extends EventEmitter<PresenceEventsMap> implements

/**
* Unsubscribe the given listener from the given list of events.
* @param eventOrEvents {'enter' | 'leave' | 'update' | 'present' | 'absent'} single event name or array of events to unsubscribe from
* @param eventOrEvents {'enter' | 'leave' | 'update' | 'present'} single event name or array of events to unsubscribe from
* @param listener listener to unsubscribe
*/
unsubscribe(eventOrEvents: PresenceEvents | PresenceEvents[], listener?: PresenceListener): Promise<void>;
Expand Down Expand Up @@ -342,8 +343,10 @@ export class DefaultPresence extends EventEmitter<PresenceEventsMap> implements
subscribeToEvents = (member: Ably.PresenceMessage) => {
try {
const parsedData = JSON.parse(member.data);
this.emit(PresenceEvents[member.action], {
action: PresenceEvents[member.action],

// ably-js never emits the 'absent' event, so we can safely ignore it here.
this.emit(PresenceEvents[member.action as PresenceEvents], {
action: PresenceEvents[member.action as PresenceEvents],
clientId: member.clientId,
timestamp: member.timestamp,
data: parsedData.userCustomData,
Expand Down
5 changes: 0 additions & 5 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ export enum PresenceEvents {
* Event triggered when a user initially subscribes to presence.
*/
present = 'present',

/**
* Event triggered while syncing if leave event received before end of sync.
*/
absent = 'absent',
}

export enum TypingEvents {
Expand Down

0 comments on commit 01b1102

Please sign in to comment.