Skip to content
Open
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 lib/core/endpoints/presence/get_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GetPresenceStateRequest extends request_1.AbstractRequest {
}
get path() {
const { keySet: { subscribeKey }, uuid, channels, } = this.parameters;
return `/v2/presence/sub-key/${subscribeKey}/channel/${(0, utils_1.encodeNames)(channels !== null && channels !== void 0 ? channels : [], ',')}/uuid/${uuid}`;
return `/v2/presence/sub-key/${subscribeKey}/channel/${(0, utils_1.encodeNames)(channels !== null && channels !== void 0 ? channels : [], ',')}/uuid/${(0, utils_1.encodeString)(uuid)}`;
}
get queryParameters() {
const { channelGroups } = this.parameters;
Expand Down
2 changes: 1 addition & 1 deletion lib/core/endpoints/presence/heartbeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class HeartbeatRequest extends request_1.AbstractRequest {
const query = { heartbeat: `${heartbeat}` };
if (channelGroups && channelGroups.length !== 0)
query['channel-group'] = channelGroups.join(',');
if (state)
if (state !== undefined)
query.state = JSON.stringify(state);
return query;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/core/endpoints/presence/set_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SetPresenceStateRequest extends request_1.AbstractRequest {
const { keySet: { subscribeKey }, state, channels = [], channelGroups = [], } = this.parameters;
if (!subscribeKey)
return 'Missing Subscribe Key';
if (!state)
if (state === undefined)
return 'Missing State';
if ((channels === null || channels === void 0 ? void 0 : channels.length) === 0 && (channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.length) === 0)
return 'Please provide a list of channels and/or channel-groups';
Expand Down
2 changes: 1 addition & 1 deletion lib/core/endpoints/presence/where_now.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class WhereNowRequest extends request_1.AbstractRequest {
const serviceResponse = this.deserializeResponse(response);
if (!serviceResponse.payload)
return { channels: [] };
return { channels: serviceResponse.payload.channels };
return { channels: serviceResponse.payload.channels || [] };
});
}
get path() {
Expand Down
12 changes: 10 additions & 2 deletions src/core/endpoints/presence/get_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AbstractRequest } from '../../components/request';
import RequestOperation from '../../constants/operations';
import { KeySet, Payload, Query } from '../../types/api';
import * as Presence from '../../types/api/presence';
import { encodeNames } from '../../utils';
import { encodeNames, encodeString } from '../../utils';

// --------------------------------------------------------
// ------------------------ Types -------------------------
Expand All @@ -20,6 +20,11 @@ import { encodeNames } from '../../utils';
* Request configuration parameters.
*/
type RequestParameters = Presence.GetPresenceStateParameters & {
/**
* The subscriber uuid to get the current state.
*/
uuid: string;

/**
* PubNub REST API access key set.
*/
Expand Down Expand Up @@ -103,7 +108,10 @@ export class GetPresenceStateRequest extends AbstractRequest<Presence.GetPresenc
channels,
} = this.parameters;

return `/v2/presence/sub-key/${subscribeKey}/channel/${encodeNames(channels ?? [], ',')}/uuid/${uuid}`;
return `/v2/presence/sub-key/${subscribeKey}/channel/${encodeNames(
channels ?? [],
',',
)}/uuid/${encodeString(uuid)}`;
}

protected get queryParameters(): Query {
Expand Down
2 changes: 1 addition & 1 deletion src/core/endpoints/presence/heartbeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class HeartbeatRequest extends AbstractRequest<Presence.PresenceHeartbeat
const query: Record<string, string> = { heartbeat: `${heartbeat}` };

if (channelGroups && channelGroups.length !== 0) query['channel-group'] = channelGroups.join(',');
if (state) query.state = JSON.stringify(state);
if (state !== undefined) query.state = JSON.stringify(state);

return query;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/endpoints/presence/set_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class SetPresenceStateRequest extends AbstractRequest<Presence.SetPresenc
} = this.parameters;

if (!subscribeKey) return 'Missing Subscribe Key';
if (!state) return 'Missing State';
if (state === undefined) return 'Missing State';
if (channels?.length === 0 && channelGroups?.length === 0)
return 'Please provide a list of channels and/or channel-groups';
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/endpoints/presence/where_now.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class WhereNowRequest extends AbstractRequest<Presence.WhereNowResponse,

if (!serviceResponse.payload) return { channels: [] };

return { channels: serviceResponse.payload.channels };
return { channels: serviceResponse.payload.channels || [] };
}

protected get path(): string {
Expand Down
2 changes: 1 addition & 1 deletion src/core/pubnub-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2542,7 +2542,7 @@ export class PubNubCore<

const request = new GetPresenceStateRequest({
...parameters,
uuid: parameters.uuid ?? this._configuration.userId,
uuid: parameters.uuid ?? this._configuration.userId!,
keySet: this._configuration.keySet,
});
const logResponse = (response: Presence.GetPresenceStateResponse | null) => {
Expand Down
Loading