Socket
Socket
Sign inDemoInstall

pubnub

Package Overview
Dependencies
Maintainers
5
Versions
224
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pubnub - npm Package Compare versions

Comparing version 4.23.0 to 4.24.0

karma/coverage/PhantomJS 2.1.1 (Mac OS X 0.0.0)/base.css

14

CHANGELOG.md

@@ -0,1 +1,13 @@

## [v4.24.0](https://github.com/pubnub/javascript/tree/v4.24.0)
May-09-2019
[Full Changelog](https://github.com/pubnub/javascript/compare/v4.23.0...v4.24.0)
- ⭐ Disables the presence heartbeat by default when a subscribe is called. Presence heartbeat can still be enabled explicitly.
## [v4.23.0](https://github.com/pubnub/javascript/tree/v4.23.0)

@@ -9,3 +21,3 @@ March-14-2019

- ⭐ `timetoken` is deprecated in message-counts API. Use `channelTimetokens` instead, pass one value in `channelTimetokens` to achieve the same results
- ⭐ The `timetoken` parameter is deprecated in the `message-counts` function. Use `channelTimetokens` instead, pass one value in `channelTimetokens` to achieve the same results

@@ -12,0 +24,0 @@

2

dist/titanium/stats.json

@@ -1,1 +0,1 @@

{"errors":[],"warnings":[],"version":"1.15.0","hash":"c97e53a44c54581767af","publicPath":"","assetsByChunkName":{"main":"pubnub.js"},"assets":[{"name":"pubnub.js","size":159785,"chunks":[0],"chunkNames":["main"],"emitted":true},{"name":"stats.json","size":0,"chunks":[],"chunkNames":[]}],"chunks":[{"id":0,"rendered":true,"initial":true,"entry":true,"extraAsync":false,"size":152106,"names":["main"],"files":["pubnub.js"],"hash":"dfbe3f74c84d0ca10359","parents":[],"modules":[],"filteredModules":44,"origins":[{"moduleId":0,"module":"/Users/madison/Documents/repos/javascript/node_modules/babel-loader/lib/index.js!/Users/madison/Documents/repos/javascript/src/titanium/index.js","moduleIdentifier":"/Users/madison/Documents/repos/javascript/node_modules/babel-loader/lib/index.js!/Users/madison/Documents/repos/javascript/src/titanium/index.js","moduleName":"./src/titanium/index.js","loc":"","name":"main","reasons":[]}]}],"modules":[],"filteredModules":44,"children":[]}
{"errors":[],"warnings":[],"version":"1.15.0","hash":"e6602ccb26c9dc642e89","publicPath":"","assetsByChunkName":{"main":"pubnub.js"},"assets":[{"name":"pubnub.js","size":159949,"chunks":[0],"chunkNames":["main"],"emitted":true},{"name":"stats.json","size":0,"chunks":[],"chunkNames":[]}],"chunks":[{"id":0,"rendered":true,"initial":true,"entry":true,"extraAsync":false,"size":152251,"names":["main"],"files":["pubnub.js"],"hash":"7fd000bd8339ba255eb1","parents":[],"modules":[],"filteredModules":44,"origins":[{"moduleId":0,"module":"/Users/david.lin/code/sdk/javascript/node_modules/babel-loader/lib/index.js!/Users/david.lin/code/sdk/javascript/src/titanium/index.js","moduleIdentifier":"/Users/david.lin/code/sdk/javascript/node_modules/babel-loader/lib/index.js!/Users/david.lin/code/sdk/javascript/src/titanium/index.js","moduleName":"./src/titanium/index.js","loc":"","name":"main","reasons":[]}]}],"modules":[],"filteredModules":44,"children":[]}

@@ -1,1 +0,1 @@

{"errors":[],"warnings":[],"version":"1.15.0","hash":"a5f33996074866c3f512","publicPath":"","assetsByChunkName":{"main":"pubnub.js"},"assets":[{"name":"pubnub.js","size":206697,"chunks":[0],"chunkNames":["main"],"emitted":true},{"name":"stats.json","size":0,"chunks":[],"chunkNames":[]}],"chunks":[{"id":0,"rendered":true,"initial":true,"entry":true,"extraAsync":false,"size":196873,"names":["main"],"files":["pubnub.js"],"hash":"906f018f7c7f42f99c5c","parents":[],"modules":[],"filteredModules":50,"origins":[{"moduleId":0,"module":"/Users/madison/Documents/repos/javascript/node_modules/babel-loader/lib/index.js!/Users/madison/Documents/repos/javascript/src/web/index.js","moduleIdentifier":"/Users/madison/Documents/repos/javascript/node_modules/babel-loader/lib/index.js!/Users/madison/Documents/repos/javascript/src/web/index.js","moduleName":"./src/web/index.js","loc":"","name":"main","reasons":[]}]}],"modules":[],"filteredModules":50,"children":[]}
{"errors":[],"warnings":[],"version":"1.15.0","hash":"2fdfceaa6ad684e89467","publicPath":"","assetsByChunkName":{"main":"pubnub.js"},"assets":[{"name":"pubnub.js","size":206944,"chunks":[0],"chunkNames":["main"],"emitted":true},{"name":"stats.json","size":0,"chunks":[],"chunkNames":[]}],"chunks":[{"id":0,"rendered":true,"initial":true,"entry":true,"extraAsync":false,"size":197099,"names":["main"],"files":["pubnub.js"],"hash":"a823bfddef27fc5377aa","parents":[],"modules":[],"filteredModules":50,"origins":[{"moduleId":0,"module":"/Users/david.lin/code/sdk/javascript/node_modules/babel-loader/lib/index.js!/Users/david.lin/code/sdk/javascript/src/web/index.js","moduleIdentifier":"/Users/david.lin/code/sdk/javascript/node_modules/babel-loader/lib/index.js!/Users/david.lin/code/sdk/javascript/src/web/index.js","moduleName":"./src/web/index.js","loc":"","name":"main","reasons":[]}]}],"modules":[],"filteredModules":50,"children":[]}

@@ -92,3 +92,4 @@ 'use strict';

value: function setAuthKey(val) {
this.authKey = val;return this;
this.authKey = val;
return this;
}

@@ -98,3 +99,4 @@ }, {

value: function setCipherKey(val) {
this.cipherKey = val;return this;
this.cipherKey = val;
return this;
}

@@ -121,3 +123,4 @@ }, {

value: function setFilterExpression(val) {
this.filterExpression = val;return this;
this.filterExpression = val;
return this;
}

@@ -149,3 +152,4 @@ }, {

value: function setHeartbeatInterval(val) {
this._heartbeatInterval = val;return this;
this._heartbeatInterval = val;
return this;
}

@@ -160,3 +164,4 @@ }, {

value: function setSubscribeTimeout(val) {
this._subscribeRequestTimeout = val;return this;
this._subscribeRequestTimeout = val;
return this;
}

@@ -171,3 +176,4 @@ }, {

value: function setTransactionTimeout(val) {
this._transactionalRequestTimeout = val;return this;
this._transactionalRequestTimeout = val;
return this;
}

@@ -182,3 +188,4 @@ }, {

value: function setSendBeaconConfig(val) {
this._useSendBeacon = val;return this;
this._useSendBeacon = val;
return this;
}

@@ -188,3 +195,3 @@ }, {

value: function getVersion() {
return '4.23.0';
return '4.24.0';
}

@@ -191,0 +198,0 @@ }, {

@@ -107,3 +107,5 @@ 'use strict';

channelGroups.forEach(function (channelGroup) {
if (channelGroup in _this._channelGroups) _this._channelGroups[channelGroup].state = state;
if (channelGroup in _this._channelGroups) {
_this._channelGroups[channelGroup].state = state;
}
});

@@ -168,7 +170,9 @@

_args$withHeartbeats = args.withHeartbeats,
withHeartbeats = _args$withHeartbeats === undefined ? true : _args$withHeartbeats;
withHeartbeats = _args$withHeartbeats === undefined ? false : _args$withHeartbeats;
if (!this._config.subscribeKey || this._config.subscribeKey === '') {
if (console && console.log) console.log('subscribe key missing; aborting subscribe');
if (console && console.log) {
console.log('subscribe key missing; aborting subscribe');
}
return;

@@ -277,3 +281,6 @@ }

value: function unsubscribeAll(isOffline) {
this.adaptUnsubscribeChange({ channels: this.getSubscribedChannels(), channelGroups: this.getSubscribedChannelGroups() }, isOffline);
this.adaptUnsubscribeChange({
channels: this.getSubscribedChannels(),
channelGroups: this.getSubscribedChannelGroups()
}, isOffline);
}

@@ -350,3 +357,5 @@ }, {

var channelState = _this5._channels[channel].state;
if (Object.keys(channelState).length) presenceState[channel] = channelState;
if (Object.keys(channelState).length) {
presenceState[channel] = channelState;
}
});

@@ -356,3 +365,5 @@

var channelGroupState = _this5._channelGroups[channelGroup].state;
if (Object.keys(channelGroupState).length) presenceState[channelGroup] = channelGroupState;
if (Object.keys(channelGroupState).length) {
presenceState[channelGroup] = channelGroupState;
}
});

@@ -380,3 +391,4 @@

channelGroups: heartbeatChannelGroups,
state: presenceState }, onHeartbeat.bind(this));
state: presenceState
}, onHeartbeat.bind(this));
}

@@ -394,10 +406,10 @@ }, {

Object.keys(this._presenceChannels).forEach(function (channel) {
return channels.push(channel + '-pnpres');
channels.push(channel + '-pnpres');
});
Object.keys(this._channelGroups).forEach(function (channelGroup) {
return channelGroups.push(channelGroup);
channelGroups.push(channelGroup);
});
Object.keys(this._presenceChannelGroups).forEach(function (channelGroup) {
return channelGroups.push(channelGroup + '-pnpres');
channelGroups.push(channelGroup + '-pnpres');
});

@@ -404,0 +416,0 @@

{
"name": "pubnub",
"version": "4.23.0",
"version": "4.24.0",
"author": "PubNub <support@pubnub.com>",

@@ -5,0 +5,0 @@ "description": "Publish & Subscribe Real-time Messaging with PubNub",

@@ -25,3 +25,3 @@ # PubNub JavaScript SDK (V4)

* https://cdn.pubnub.com/sdk/javascript/pubnub.4.23.0.min.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.23.0.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.24.0.min.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.24.0.js

@@ -5,11 +5,15 @@ /* @flow */

import uuidGenerator from './uuid';
import { InternalSetupStruct, DatabaseInterface, KeepAliveStruct, ProxyStruct } from '../flow_interfaces';
import {
InternalSetupStruct,
DatabaseInterface,
KeepAliveStruct,
ProxyStruct,
} from '../flow_interfaces';
type ConfigConstructArgs = {
setup: InternalSetupStruct,
db: DatabaseInterface
}
db: DatabaseInterface,
};
export default class {
_db: DatabaseInterface;

@@ -119,16 +123,17 @@

/*
support for client deduping
*/
dedupeOnSubscribe: boolean
maximumCacheSize: number
dedupeOnSubscribe: boolean;
maximumCacheSize: number;
/*
support customp encryption and decryption functions.
*/
customEncrypt: Function // function to support custome encryption of messages
customDecrypt: Function // function used to decrypt old version messages
customEncrypt: Function; // function to support custome encryption of messages
constructor({ setup, db } : ConfigConstructArgs) {
customDecrypt: Function; // function used to decrypt old version messages
constructor({ setup, db }: ConfigConstructArgs) {
this._db = db;

@@ -171,3 +176,4 @@

this.announceFailedHeartbeats = setup.announceFailedHeartbeats || true;
this.announceSuccessfulHeartbeats = setup.announceSuccessfulHeartbeats || false;
this.announceSuccessfulHeartbeats =
setup.announceSuccessfulHeartbeats || false;

@@ -196,6 +202,20 @@ this.useInstanceId = setup.useInstanceId || false;

// exposed setters
getAuthKey(): string { return this.authKey; }
setAuthKey(val: string): this { this.authKey = val; return this; }
setCipherKey(val: string): this { this.cipherKey = val; return this; }
getUUID(): string { return this.UUID; }
getAuthKey(): string {
return this.authKey;
}
setAuthKey(val: string): this {
this.authKey = val;
return this;
}
setCipherKey(val: string): this {
this.cipherKey = val;
return this;
}
getUUID(): string {
return this.UUID;
}
setUUID(val: string): this {

@@ -207,9 +227,18 @@ if (this._db && this._db.set) this._db.set(`${this.subscribeKey}uuid`, val);

getFilterExpression(): string { return this.filterExpression; }
setFilterExpression(val: string): this { this.filterExpression = val; return this; }
getFilterExpression(): string {
return this.filterExpression;
}
getPresenceTimeout(): number { return this._presenceTimeout; }
setFilterExpression(val: string): this {
this.filterExpression = val;
return this;
}
getPresenceTimeout(): number {
return this._presenceTimeout;
}
setPresenceTimeout(val: number): this {
this._presenceTimeout = val;
this.setHeartbeatInterval((this._presenceTimeout / 2) - 1);
this.setHeartbeatInterval(this._presenceTimeout / 2 - 1);
return this;

@@ -222,17 +251,41 @@ }

getHeartbeatInterval(): number { return this._heartbeatInterval; }
setHeartbeatInterval(val: number): this { this._heartbeatInterval = val; return this; }
getHeartbeatInterval(): number {
return this._heartbeatInterval;
}
setHeartbeatInterval(val: number): this {
this._heartbeatInterval = val;
return this;
}
// deprecated setters.
getSubscribeTimeout(): number { return this._subscribeRequestTimeout; }
setSubscribeTimeout(val: number): this { this._subscribeRequestTimeout = val; return this; }
getSubscribeTimeout(): number {
return this._subscribeRequestTimeout;
}
getTransactionTimeout(): number { return this._transactionalRequestTimeout; }
setTransactionTimeout(val: number): this { this._transactionalRequestTimeout = val; return this; }
setSubscribeTimeout(val: number): this {
this._subscribeRequestTimeout = val;
return this;
}
isSendBeaconEnabled(): boolean { return this._useSendBeacon; }
setSendBeaconConfig(val: boolean): this { this._useSendBeacon = val; return this; }
getTransactionTimeout(): number {
return this._transactionalRequestTimeout;
}
setTransactionTimeout(val: number): this {
this._transactionalRequestTimeout = val;
return this;
}
isSendBeaconEnabled(): boolean {
return this._useSendBeacon;
}
setSendBeaconConfig(val: boolean): this {
this._useSendBeacon = val;
return this;
}
getVersion(): string {
return '4.23.0';
return '4.24.0';
}

@@ -239,0 +292,0 @@

@@ -8,3 +8,8 @@ /* @flow */

import utils from '../utils';
import { MessageAnnouncement, SubscribeEnvelope, StatusAnnouncement, PresenceAnnouncement } from '../flow_interfaces';
import {
MessageAnnouncement,
SubscribeEnvelope,
StatusAnnouncement,
PresenceAnnouncement,
} from '../flow_interfaces';
import categoryConstants from '../constants/categories';

@@ -17,4 +22,4 @@

timetoken: ?number,
withHeartbeats: ?boolean
}
withHeartbeats: ?boolean,
};

@@ -24,9 +29,9 @@ type PresenceArgs = {

channelGroups: Array<string>,
connected: boolean
}
connected: boolean,
};
type UnsubscribeArgs = {
channels: Array<string>,
channelGroups: Array<string>
}
channelGroups: Array<string>,
};

@@ -36,18 +41,17 @@ type StateArgs = {

channelGroups: Array<string>,
state: Object
}
state: Object,
};
type SubscriptionManagerConsturct = {
leaveEndpoint: Function,
subscribeEndpoint: Function,
timeEndpoint: Function,
heartbeatEndpoint: Function,
setStateEndpoint: Function,
config: Config,
crypto: Crypto,
listenerManager: ListenerManager
}
type SubscriptionManagerConstruct = {
leaveEndpoint: Function,
subscribeEndpoint: Function,
timeEndpoint: Function,
heartbeatEndpoint: Function,
setStateEndpoint: Function,
config: Config,
crypto: Crypto,
listenerManager: ListenerManager,
};
export default class {
_crypto: Crypto;

@@ -93,3 +97,12 @@ _config: Config;

constructor({ subscribeEndpoint, leaveEndpoint, heartbeatEndpoint, setStateEndpoint, timeEndpoint, config, crypto, listenerManager }: SubscriptionManagerConsturct) {
constructor({
subscribeEndpoint,
leaveEndpoint,
heartbeatEndpoint,
setStateEndpoint,
timeEndpoint,
config,
crypto,
listenerManager,
}: SubscriptionManagerConstruct) {
this._listenerManager = listenerManager;

@@ -132,8 +145,10 @@ this._config = config;

channels.forEach((channel) => {
channels.forEach(channel => {
if (channel in this._channels) this._channels[channel].state = state;
});
channelGroups.forEach((channelGroup) => {
if (channelGroup in this._channelGroups) this._channelGroups[channelGroup].state = state;
channelGroups.forEach(channelGroup => {
if (channelGroup in this._channelGroups) {
this._channelGroups[channelGroup].state = state;
}
});

@@ -156,3 +171,3 @@

} else {
channels.forEach((channel) => {
channels.forEach(channel => {
if (channel in this._heartbeatChannels) {

@@ -163,3 +178,3 @@ delete this._heartbeatChannels[channel];

channelGroups.forEach((channelGroup) => {
channelGroups.forEach(channelGroup => {
if (channelGroup in this._heartbeatChannelGroups) {

@@ -171,3 +186,3 @@ delete this._heartbeatChannelGroups[channelGroup];

if (this._config.suppressLeaveEvents === false) {
this._leaveEndpoint({ channels, channelGroups }, (status) => {
this._leaveEndpoint({ channels, channelGroups }, status => {
this._listenerManager.announceStatus(status);

@@ -182,6 +197,15 @@ });

adaptSubscribeChange(args: SubscribeArgs) {
const { timetoken, channels = [], channelGroups = [], withPresence = false, withHeartbeats = true } = args;
const {
timetoken,
channels = [],
channelGroups = [],
withPresence = false,
withHeartbeats = false,
} = args;
if (!this._config.subscribeKey || this._config.subscribeKey === '') {
if (console && console.log) console.log('subscribe key missing; aborting subscribe') //eslint-disable-line
// eslint-disable-next-line
if (console && console.log) {
console.log('subscribe key missing; aborting subscribe'); //eslint-disable-line
}
return;

@@ -230,3 +254,3 @@ }

channels.forEach((channel) => {
channels.forEach(channel => {
if (channel in this._channels) {

@@ -246,3 +270,3 @@ delete this._channels[channel];

channelGroups.forEach((channelGroup) => {
channelGroups.forEach(channelGroup => {
if (channelGroup in this._channelGroups) {

@@ -268,16 +292,21 @@ delete this._channelGroups[channelGroup];

if (this._config.suppressLeaveEvents === false && !isOffline) {
this._leaveEndpoint({ channels: actualChannels, channelGroups: actualChannelGroups }, (status) => {
status.affectedChannels = actualChannels;
status.affectedChannelGroups = actualChannelGroups;
status.currentTimetoken = this._currentTimetoken;
status.lastTimetoken = this._lastTimetoken;
this._listenerManager.announceStatus(status);
});
this._leaveEndpoint(
{ channels: actualChannels, channelGroups: actualChannelGroups },
status => {
status.affectedChannels = actualChannels;
status.affectedChannelGroups = actualChannelGroups;
status.currentTimetoken = this._currentTimetoken;
status.lastTimetoken = this._lastTimetoken;
this._listenerManager.announceStatus(status);
}
);
}
// if we have nothing to subscribe to, reset the timetoken.
if (Object.keys(this._channels).length === 0 &&
if (
Object.keys(this._channels).length === 0 &&
Object.keys(this._presenceChannels).length === 0 &&
Object.keys(this._channelGroups).length === 0 &&
Object.keys(this._presenceChannelGroups).length === 0) {
Object.keys(this._presenceChannelGroups).length === 0
) {
this._lastTimetoken = 0;

@@ -294,3 +323,9 @@ this._currentTimetoken = 0;

unsubscribeAll(isOffline: boolean) {
this.adaptUnsubscribeChange({ channels: this.getSubscribedChannels(), channelGroups: this.getSubscribedChannelGroups() }, isOffline);
this.adaptUnsubscribeChange(
{
channels: this.getSubscribedChannels(),
channelGroups: this.getSubscribedChannelGroups(),
},
isOffline
);
}

@@ -334,3 +369,6 @@

this._performHeartbeatLoop();
this._heartbeatTimer = setInterval(this._performHeartbeatLoop.bind(this), this._config.getHeartbeatInterval() * 1000);
this._heartbeatTimer = setInterval(
this._performHeartbeatLoop.bind(this),
this._config.getHeartbeatInterval() * 1000
);
}

@@ -356,10 +394,14 @@

this.getSubscribedChannels().forEach((channel) => {
this.getSubscribedChannels().forEach(channel => {
let channelState = this._channels[channel].state;
if (Object.keys(channelState).length) presenceState[channel] = channelState;
if (Object.keys(channelState).length) {
presenceState[channel] = channelState;
}
});
this.getSubscribedChannelGroups().forEach((channelGroup) => {
this.getSubscribedChannelGroups().forEach(channelGroup => {
let channelGroupState = this._channelGroups[channelGroup].state;
if (Object.keys(channelGroupState).length) presenceState[channelGroup] = channelGroupState;
if (Object.keys(channelGroupState).length) {
presenceState[channelGroup] = channelGroupState;
}
});

@@ -384,6 +426,10 @@

this._heartbeatEndpoint({
channels: heartbeatChannels,
channelGroups: heartbeatChannelGroups,
state: presenceState }, onHeartbeat.bind(this));
this._heartbeatEndpoint(
{
channels: heartbeatChannels,
channelGroups: heartbeatChannelGroups,
state: presenceState,
},
onHeartbeat.bind(this)
);
}

@@ -397,6 +443,12 @@

Object.keys(this._channels).forEach(channel => channels.push(channel));
Object.keys(this._presenceChannels).forEach(channel => channels.push(`${channel}-pnpres`));
Object.keys(this._presenceChannels).forEach(channel => {
channels.push(`${channel}-pnpres`);
});
Object.keys(this._channelGroups).forEach(channelGroup => channelGroups.push(channelGroup));
Object.keys(this._presenceChannelGroups).forEach(channelGroup => channelGroups.push(`${channelGroup}-pnpres`));
Object.keys(this._channelGroups).forEach(channelGroup => {
channelGroups.push(channelGroup);
});
Object.keys(this._presenceChannelGroups).forEach(channelGroup => {
channelGroups.push(`${channelGroup}-pnpres`);
});

@@ -412,9 +464,15 @@ if (channels.length === 0 && channelGroups.length === 0) {

filterExpression: this._config.filterExpression,
region: this._region
region: this._region,
};
this._subscribeCall = this._subscribeEndpoint(subscribeArgs, this._processSubscribeResponse.bind(this));
this._subscribeCall = this._subscribeEndpoint(
subscribeArgs,
this._processSubscribeResponse.bind(this)
);
}
_processSubscribeResponse(status: StatusAnnouncement, payload: SubscribeEnvelope) {
_processSubscribeResponse(
status: StatusAnnouncement,
payload: SubscribeEnvelope
) {
if (status.error) {

@@ -424,7 +482,13 @@ // if we timeout from server, restart the loop.

this._startSubscribeLoop();
} else if (status.category === categoryConstants.PNNetworkIssuesCategory) {
} else if (
status.category === categoryConstants.PNNetworkIssuesCategory
) {
// we lost internet connection, alert the reconnection manager and terminate all loops
this.disconnect();
if (status.error && this._config.autoNetworkDetection && this._isOnline) {
if (
status.error &&
this._config.autoNetworkDetection &&
this._isOnline
) {
this._isOnline = false;

@@ -445,3 +509,3 @@ this._listenerManager.announceNetworkDown();

lastTimetoken: this._lastTimetoken,
currentTimetoken: this._currentTimetoken
currentTimetoken: this._currentTimetoken,
};

@@ -491,5 +555,9 @@ this._listenerManager.announceStatus(reconnectedAnnounce);

if (requestMessageCountThreshold && messages.length >= requestMessageCountThreshold) {
if (
requestMessageCountThreshold &&
messages.length >= requestMessageCountThreshold
) {
let countAnnouncement: StatusAnnouncement = {};
countAnnouncement.category = categoryConstants.PNRequestMessageCountExceededCategory;
countAnnouncement.category =
categoryConstants.PNRequestMessageCountExceededCategory;
countAnnouncement.operation = status.operation;

@@ -499,3 +567,3 @@ this._listenerManager.announceStatus(countAnnouncement);

messages.forEach((message) => {
messages.forEach(message => {
let channel = message.channel;

@@ -523,12 +591,19 @@ let subscriptionMatch = message.subscriptionMatch;

// deprecated -->
announce.actualChannel = (subscriptionMatch != null) ? channel : null;
announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel;
announce.actualChannel = subscriptionMatch != null ? channel : null;
announce.subscribedChannel =
subscriptionMatch != null ? subscriptionMatch : channel;
// <-- deprecated
if (channel) {
announce.channel = channel.substring(0, channel.lastIndexOf('-pnpres'));
announce.channel = channel.substring(
0,
channel.lastIndexOf('-pnpres')
);
}
if (subscriptionMatch) {
announce.subscription = subscriptionMatch.substring(0, subscriptionMatch.lastIndexOf('-pnpres'));
announce.subscription = subscriptionMatch.substring(
0,
subscriptionMatch.lastIndexOf('-pnpres')
);
}

@@ -562,4 +637,5 @@

// deprecated -->
announce.actualChannel = (subscriptionMatch != null) ? channel : null;
announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel;
announce.actualChannel = subscriptionMatch != null ? channel : null;
announce.subscribedChannel =
subscriptionMatch != null ? subscriptionMatch : channel;
// <-- deprecated

@@ -598,3 +674,2 @@

}
}

@@ -29,3 +29,3 @@ /* global describe, beforeEach, it, before, afterEach, after */

publishKey: 'myPublishKey',
uuid: 'myUUID'
uuid: 'myUUID',
});

@@ -40,8 +40,12 @@ clock = sinon.useFakeTimers();

it('reports when the network is unreachable', (done) => {
utils.createNock().get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
it('reports when the network is unreachable', done => {
utils
.createNock()
.get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query(true)
.replyWithError({ message: 'Network unavailable', code: 'ENOTFOUND' });
utils.createNock().get('/v2/presence/sub-key/mySubKey/channel/ch1%2Cch2/heartbeat')
utils
.createNock()
.get('/v2/presence/sub-key/mySubKey/channel/ch1%2Cch2/heartbeat')
.query(true)

@@ -54,9 +58,12 @@ .replyWithError({ message: 'Network unavailable', code: 'ENOTFOUND' });

let statusWithoutError = _.omit(statusPayload, 'errorData');
assert.deepEqual({
category: 'PNNetworkIssuesCategory',
error: true,
operation: 'PNSubscribeOperation'
}, statusWithoutError);
assert.deepEqual(
{
category: 'PNNetworkIssuesCategory',
error: true,
operation: 'PNSubscribeOperation',
},
statusWithoutError
);
done();
}
},
});

@@ -67,12 +74,18 @@

it('begins polling and reports reconnects when subscribe is again successful', (done) => {
utils.createNock().get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
it('begins polling and reports reconnects when subscribe is again successful', done => {
utils
.createNock()
.get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query(true)
.replyWithError({ message: 'Network unavailable', code: 'ENOTFOUND' });
utils.createNock().get('/v2/presence/sub-key/mySubKey/channel/ch1%2Cch2/heartbeat')
utils
.createNock()
.get('/v2/presence/sub-key/mySubKey/channel/ch1%2Cch2/heartbeat')
.query(true)
.replyWithError({ message: 'Network unavailable', code: 'ENOTFOUND' });
utils.createNock().get('/time/0')
utils
.createNock()
.get('/time/0')
.query(true)

@@ -84,26 +97,44 @@ .reply(200, [14570763868573725]);

if (statusPayload.category === 'PNNetworkIssuesCategory') {
utils.createNock().get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
utils
.createNock()
.get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query(true)
.reply(200, '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}');
.reply(
200,
'{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}'
);
utils.createNock().get('/v2/presence/sub-key/mySubKey/channel/ch1%2Cch2/heartbeat')
utils
.createNock()
.get('/v2/presence/sub-key/mySubKey/channel/ch1%2Cch2/heartbeat')
.query(true)
.reply(200, '{"status": 200, "message": "OK", "service": "Presence"}');
.reply(
200,
'{"status": 200, "message": "OK", "service": "Presence"}'
);
// Advance the clock so that _performTimeLoop() executes
clock.tick(3500);
done();
} else if (statusPayload.category === 'PNReconnectedCategory') {
assert.deepEqual({
category: 'PNReconnectedCategory',
operation: 'PNSubscribeOperation',
currentTimetoken: 0,
lastTimetoken: 0
}, statusPayload);
assert.deepEqual(
{
category: 'PNReconnectedCategory',
operation: 'PNSubscribeOperation',
currentTimetoken: 0,
lastTimetoken: 0,
},
statusPayload
);
done();
}
}
},
});
pubnub.subscribe({ channels: ['ch1', 'ch2'], withPresence: true });
pubnub.subscribe({
channels: ['ch1', 'ch2'],
withPresence: true,
withHeathbeats: true,
});
});
});

@@ -26,5 +26,22 @@ /* global describe, beforeEach, it, before, afterEach, after */

nock.cleanAll();
pubnub = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', uuid: 'myUUID', autoNetworkDetection: false });
pubnubWithPassingHeartbeats = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', uuid: 'myUUID', announceSuccessfulHeartbeats: true, autoNetworkDetection: false });
pubnubWithLimitedQueue = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', uuid: 'myUUID', requestMessageCountThreshold: 1, autoNetworkDetection: false });
pubnub = new PubNub({
subscribeKey: 'mySubKey',
publishKey: 'myPublishKey',
uuid: 'myUUID',
autoNetworkDetection: false,
});
pubnubWithPassingHeartbeats = new PubNub({
subscribeKey: 'mySubKey',
publishKey: 'myPublishKey',
uuid: 'myUUID',
announceSuccessfulHeartbeats: true,
autoNetworkDetection: false,
});
pubnubWithLimitedQueue = new PubNub({
subscribeKey: 'mySubKey',
publishKey: 'myPublishKey',
uuid: 'myUUID',
requestMessageCountThreshold: 1,
autoNetworkDetection: false,
});
});

@@ -38,14 +55,45 @@

it('passes the correct message information', (done) => {
const scope1 = utils.createNock().get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300 })
.reply(200, '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}');
it('passes the correct message information', done => {
const scope1 = utils
.createNock()
.get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: 300,
})
.reply(
200,
'{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}'
);
const scope2 = utils.createNock().get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300, tt: 3, tr: 1 })
.reply(200, '{"t":{"t":"10","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"i": "client2", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message3"},"b":"coolChan-bnel"}]}');
const scope2 = utils
.createNock()
.get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: 300,
tt: 3,
tr: 1,
})
.reply(
200,
'{"t":{"t":"10","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"i": "client2", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message3"},"b":"coolChan-bnel"}]}'
);
const scope3 = utils.createNock().get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300, tt: 10, tr: 1 })
.reply(200, '{"t":{"t":"20","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"i": "client3", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message10"},"b":"coolChan-bnel", "u": {"cool": "meta"}}]}');
const scope3 = utils
.createNock()
.get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: 300,
tt: 10,
tr: 1,
})
.reply(
200,
'{"t":{"t":"20","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"i": "client3", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message10"},"b":"coolChan-bnel", "u": {"cool": "meta"}}]}'
);

@@ -66,3 +114,3 @@ let incomingPayloads = [];

message: {
text: 'Message'
text: 'Message',
},

@@ -73,3 +121,3 @@ subscribedChannel: 'coolChan-bnel',

timetoken: '14607577960925503',
publisher: 'client1'
publisher: 'client1',
},

@@ -85,3 +133,3 @@ {

timetoken: '14607577960925503',
publisher: 'client2'
publisher: 'client2',
},

@@ -94,3 +142,3 @@ {

userMetadata: {
cool: 'meta'
cool: 'meta',
},

@@ -101,8 +149,8 @@ subscribedChannel: 'coolChan-bnel',

timetoken: '14607577960925503',
publisher: 'client3'
}
publisher: 'client3',
},
]);
done();
}
}
},
});

@@ -113,6 +161,15 @@

it('passes the correct presence information', (done) => {
const scope = utils.createNock().get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300 })
.reply(200, '{"t":{"t":"14614512228786519","r":1},"m":[{"a":"4","f":0,"p":{"t":"14614512228418349","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel-pnpres","d":{"action": "join", "timestamp": 1461451222, "uuid": "4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", "occupancy": 1},"b":"coolChannel-pnpres"}]}');
it('passes the correct presence information', done => {
const scope = utils
.createNock()
.get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: 300,
})
.reply(
200,
'{"t":{"t":"14614512228786519","r":1},"m":[{"a":"4","f":0,"p":{"t":"14614512228418349","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel-pnpres","d":{"action": "join", "timestamp": 1461451222, "uuid": "4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", "occupancy": 1},"b":"coolChannel-pnpres"}]}'
);

@@ -122,16 +179,19 @@ pubnub.addListener({

assert.equal(scope.isDone(), true);
assert.deepEqual({
channel: 'coolChannel',
subscription: null,
actualChannel: null,
occupancy: 1,
subscribedChannel: 'coolChannel-pnpres',
timestamp: 1461451222,
timetoken: '14614512228418349',
uuid: '4a6d5df7-e301-4e73-a7b7-6af9ab484eb0',
action: 'join',
state: undefined
}, presencePayload);
assert.deepEqual(
{
channel: 'coolChannel',
subscription: null,
actualChannel: null,
occupancy: 1,
subscribedChannel: 'coolChannel-pnpres',
timestamp: 1461451222,
timetoken: '14614512228418349',
uuid: '4a6d5df7-e301-4e73-a7b7-6af9ab484eb0',
action: 'join',
state: undefined,
},
presencePayload
);
done();
}
},
});

@@ -142,6 +202,15 @@

it('passes the correct presence information when state is changed', (done) => {
const scope = utils.createNock().get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300 })
.reply(200, '{"t":{"t":"14637536741734954","r":1},"m":[{"a":"4","f":512,"p":{"t":"14637536740940378","r":1},"k":"demo-36","c":"ch10-pnpres","d":{"action": "join", "timestamp": 1463753674, "uuid": "24c9bb19-1fcd-4c40-a6f1-522a8a1329ef", "occupancy": 3},"b":"ch10-pnpres"},{"a":"4","f":512,"p":{"t":"14637536741726901","r":1},"k":"demo-36","c":"ch10-pnpres","d":{"action": "state-change", "timestamp": 1463753674, "data": {"state": "cool"}, "uuid": "24c9bb19-1fcd-4c40-a6f1-522a8a1329ef", "occupancy": 3},"b":"ch10-pnpres"}]}');
it('passes the correct presence information when state is changed', done => {
const scope = utils
.createNock()
.get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: 300,
})
.reply(
200,
'{"t":{"t":"14637536741734954","r":1},"m":[{"a":"4","f":512,"p":{"t":"14637536740940378","r":1},"k":"demo-36","c":"ch10-pnpres","d":{"action": "join", "timestamp": 1463753674, "uuid": "24c9bb19-1fcd-4c40-a6f1-522a8a1329ef", "occupancy": 3},"b":"ch10-pnpres"},{"a":"4","f":512,"p":{"t":"14637536741726901","r":1},"k":"demo-36","c":"ch10-pnpres","d":{"action": "state-change", "timestamp": 1463753674, "data": {"state": "cool"}, "uuid": "24c9bb19-1fcd-4c40-a6f1-522a8a1329ef", "occupancy": 3},"b":"ch10-pnpres"}]}'
);

@@ -153,16 +222,19 @@ pubnub.addListener({

assert.equal(scope.isDone(), true);
assert.deepEqual({
channel: 'ch10',
subscription: null,
actualChannel: null,
occupancy: 3,
subscribedChannel: 'ch10-pnpres',
timestamp: 1463753674,
timetoken: '14637536741726901',
uuid: '24c9bb19-1fcd-4c40-a6f1-522a8a1329ef',
action: 'state-change',
state: { state: 'cool' }
}, presencePayload);
assert.deepEqual(
{
channel: 'ch10',
subscription: null,
actualChannel: null,
occupancy: 3,
subscribedChannel: 'ch10-pnpres',
timestamp: 1463753674,
timetoken: '14637536741726901',
uuid: '24c9bb19-1fcd-4c40-a6f1-522a8a1329ef',
action: 'state-change',
state: { state: 'cool' },
},
presencePayload
);
done();
}
},
});

@@ -173,22 +245,40 @@

it('reports when heartbeats failed', (done) => {
it('reports when heartbeats failed', done => {
pubnub.addListener({
status(statusPayload) {
if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return;
if (
statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation
) {
return;
}
let statusWithoutError = _.omit(statusPayload, 'errorData');
assert.deepEqual({
category: 'PNUnknownCategory',
error: true,
operation: 'PNHeartbeatOperation',
}, statusWithoutError);
assert.deepEqual(
{
category: 'PNUnknownCategory',
error: true,
operation: 'PNHeartbeatOperation',
},
statusWithoutError
);
done();
}
},
});
pubnub.subscribe({ channels: ['ch1', 'ch2'], withPresence: true });
pubnub.subscribe({
channels: ['ch1', 'ch2'],
withPresence: true,
withHeartbeats: true,
});
});
it('reports when heartbeats fail with error code', (done) => {
const scope = utils.createNock().get('/v2/presence/sub-key/mySubKey/channel/ch1%2Cch2/heartbeat')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300, state: '{}' })
it('reports when heartbeats fail with error code', done => {
const scope = utils
.createNock()
.get('/v2/presence/sub-key/mySubKey/channel/ch1%2Cch2/heartbeat')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: 300,
state: '{}',
})
.reply(400, '{"status": 400, "message": "OK", "service": "Presence"}');

@@ -198,22 +288,39 @@

status(statusPayload) {
if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return;
if (
statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation
) {
return;
}
let statusWithoutError = _.omit(statusPayload, 'errorData');
assert.equal(scope.isDone(), true);
assert.deepEqual({
category: 'PNBadRequestCategory',
error: true,
operation: 'PNHeartbeatOperation',
statusCode: 400
}, statusWithoutError);
assert.deepEqual(
{
category: 'PNBadRequestCategory',
error: true,
operation: 'PNHeartbeatOperation',
statusCode: 400,
},
statusWithoutError
);
done();
}
},
});
pubnub.subscribe({ channels: ['ch1', 'ch2'], withPresence: true });
pubnub.subscribe({
channels: ['ch1', 'ch2'],
withPresence: true,
withHeartbeats: true,
});
});
it('reports when heartbeats pass', (done) => {
const scope = utils.createNock().get('/v2/presence/sub-key/mySubKey/channel/ch1%2Cch2/heartbeat')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300, state: '{}' })
it('reports when heartbeats pass', done => {
const scope = utils
.createNock()
.get('/v2/presence/sub-key/mySubKey/channel/ch1%2Cch2/heartbeat')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: 300,
state: '{}',
})
.reply(200, '{"status": 200, "message": "OK", "service": "Presence"}');

@@ -223,20 +330,38 @@

status(statusPayload) {
if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return;
if (
statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation
) {
return;
}
assert.equal(scope.isDone(), true);
assert.deepEqual({
error: false,
operation: 'PNHeartbeatOperation',
statusCode: 200
}, statusPayload);
assert.deepEqual(
{
error: false,
operation: 'PNHeartbeatOperation',
statusCode: 200,
},
statusPayload
);
done();
}
},
});
pubnubWithPassingHeartbeats.subscribe({ channels: ['ch1', 'ch2'], withPresence: true });
pubnubWithPassingHeartbeats.subscribe({
channels: ['ch1', 'ch2'],
withPresence: true,
withHeartbeats: true,
});
});
it('reports when heartbeats pass with heartbeatChannels', (done) => {
const scope = utils.createNock().get('/v2/presence/sub-key/mySubKey/channel/ch1%2Cch2/heartbeat')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300, state: '{}' })
it('reports when heartbeats pass with heartbeatChannels', done => {
const scope = utils
.createNock()
.get('/v2/presence/sub-key/mySubKey/channel/ch1%2Cch2/heartbeat')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: 300,
state: '{}',
})
.reply(200, '{"status": 200, "message": "OK", "service": "Presence"}');

@@ -246,20 +371,38 @@

status(statusPayload) {
if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return;
if (
statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation
) {
return;
}
assert.equal(scope.isDone(), true);
assert.deepEqual({
error: false,
operation: 'PNHeartbeatOperation',
statusCode: 200
}, statusPayload);
assert.deepEqual(
{
error: false,
operation: 'PNHeartbeatOperation',
statusCode: 200,
},
statusPayload
);
done();
}
},
});
pubnubWithPassingHeartbeats.presence({ channels: ['ch1', 'ch2'], connected: true });
pubnubWithPassingHeartbeats.presence({
channels: ['ch1', 'ch2'],
connected: true,
});
});
it('reports when heartbeats pass with heartbeatChannelGroups', (done) => {
const scope = utils.createNock().get('/v2/presence/sub-key/mySubKey/channel/%2C/heartbeat')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300, state: '{}', 'channel-group': 'cg1' })
it('reports when heartbeats pass with heartbeatChannelGroups', done => {
const scope = utils
.createNock()
.get('/v2/presence/sub-key/mySubKey/channel/%2C/heartbeat')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: 300,
state: '{}',
'channel-group': 'cg1',
})
.reply(200, '{"status": 200, "message": "OK", "service": "Presence"}');

@@ -269,48 +412,100 @@

status(statusPayload) {
if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return;
if (
statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation
) {
return;
}
assert.equal(scope.isDone(), true);
assert.deepEqual({
error: false,
operation: 'PNHeartbeatOperation',
statusCode: 200
}, statusPayload);
assert.deepEqual(
{
error: false,
operation: 'PNHeartbeatOperation',
statusCode: 200,
},
statusPayload
);
done();
}
},
});
pubnubWithPassingHeartbeats.presence({ channelGroups: ['cg1'], connected: true });
pubnubWithPassingHeartbeats.presence({
channelGroups: ['cg1'],
connected: true,
});
});
it('reports when the queue is beyond set threshold', (done) => {
const scope = utils.createNock().get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300 })
.reply(200, '{"t":{"t":"14614512228786519","r":1},"m":[{"a":"4","f":0,"p":{"t":"14614512228418349","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel-pnpres","d":{"action": "join", "timestamp": 1461451222, "uuid": "4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", "occupancy": 1},"b":"coolChannel-pnpres"}]}');
it('reports when the queue is beyond set threshold', done => {
const scope = utils
.createNock()
.get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: 300,
})
.reply(
200,
'{"t":{"t":"14614512228786519","r":1},"m":[{"a":"4","f":0,"p":{"t":"14614512228418349","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel-pnpres","d":{"action": "join", "timestamp": 1461451222, "uuid": "4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", "occupancy": 1},"b":"coolChannel-pnpres"}]}'
);
pubnubWithLimitedQueue.addListener({
status(statusPayload) {
if (statusPayload.category !== PubNub.CATEGORIES.PNRequestMessageCountExceededCategory) return;
if (
statusPayload.category !==
PubNub.CATEGORIES.PNRequestMessageCountExceededCategory
) {
return;
}
assert.equal(scope.isDone(), true);
assert.equal(statusPayload.category, PubNub.CATEGORIES.PNRequestMessageCountExceededCategory);
assert.equal(statusPayload.operation, PubNub.OPERATIONS.PNSubscribeOperation);
assert.equal(
statusPayload.category,
PubNub.CATEGORIES.PNRequestMessageCountExceededCategory
);
assert.equal(
statusPayload.operation,
PubNub.OPERATIONS.PNSubscribeOperation
);
done();
}
},
});
pubnubWithLimitedQueue.subscribe({ channels: ['ch1', 'ch2'], withPresence: true });
pubnubWithLimitedQueue.subscribe({
channels: ['ch1', 'ch2'],
withPresence: true,
});
});
it('supports deduping on duplicates', (done) => {
it('supports deduping on duplicates', done => {
pubnub._config.dedupeOnSubscribe = true;
let messageCount = 0;
utils.createNock().get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300 })
.reply(200, '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}');
utils
.createNock()
.get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: 300,
})
.reply(
200,
'{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}'
);
utils.createNock().get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300, tt: 3, tr: 1 })
.reply(200, '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"}]}');
utils
.createNock()
.get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: 300,
tt: 3,
tr: 1,
})
.reply(
200,
'{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"}]}'
);

@@ -320,3 +515,3 @@ pubnub.addListener({

messageCount += 1;
}
},
});

@@ -333,12 +528,32 @@

it('no deduping on duplicates ', (done) => {
it('no deduping on duplicates ', done => {
let messageCount = 0;
utils.createNock().get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300 })
.reply(200, '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}');
utils
.createNock()
.get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: 300,
})
.reply(
200,
'{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}'
);
utils.createNock().get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300, tt: 3, tr: 1 })
.reply(200, '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"}]}');
utils
.createNock()
.get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: 300,
tt: 3,
tr: 1,
})
.reply(
200,
'{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"}]}'
);

@@ -348,3 +563,3 @@ pubnub.addListener({

messageCount += 1;
}
},
});

@@ -362,3 +577,3 @@

it('supports deduping on shawllow queue', (done) => {
it('supports deduping on shawllow queue', done => {
pubnub._config.dedupeOnSubscribe = true;

@@ -368,9 +583,29 @@ pubnub._config.maximumCacheSize = 1;

utils.createNock().get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300 })
.reply(200, '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}');
utils
.createNock()
.get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: 300,
})
.reply(
200,
'{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}'
);
utils.createNock().get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300, tt: 3, tr: 1 })
.reply(200, '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message1"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message2"},"b":"coolChannel"}, {"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message1"},"b":"coolChannel"}]}');
utils
.createNock()
.get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: 300,
tt: 3,
tr: 1,
})
.reply(
200,
'{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message1"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message2"},"b":"coolChannel"}, {"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message1"},"b":"coolChannel"}]}'
);

@@ -380,3 +615,3 @@ pubnub.addListener({

messageCount += 1;
}
},
});

@@ -383,0 +618,0 @@

@@ -22,3 +22,8 @@ /* global describe, beforeEach, it, before, afterEach, after */

nock.cleanAll();
pubnub = new PubNub({ subscribeKey: 'mySubscribeKey', publishKey: 'myPublishKey', uuid: 'myUUID', announceSuccessfulHeartbeats: true });
pubnub = new PubNub({
subscribeKey: 'mySubscribeKey',
publishKey: 'myPublishKey',
uuid: 'myUUID',
announceSuccessfulHeartbeats: true,
});
});

@@ -32,5 +37,12 @@

describe('#heartbeat', () => {
it('supports heartbeating for one channel', (done) => {
const scope = utils.createNock().get('/v2/presence/sub-key/mySubscribeKey/channel/ch1/heartbeat')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: '300', state: '{}' })
it('supports heartbeating for one channel', done => {
const scope = utils
.createNock()
.get('/v2/presence/sub-key/mySubscribeKey/channel/ch1/heartbeat')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: '300',
state: '{}',
})
.reply(200, '{"status": 200, "message": "OK", "service": "Presence"}');

@@ -45,11 +57,18 @@

}
}
},
});
pubnub.subscribe({ channels: ['ch1'] });
pubnub.subscribe({ channels: ['ch1'], withHeartbeats: true });
});
it('supports heartbeating for multiple channels', (done) => {
const scope = utils.createNock().get('/v2/presence/sub-key/mySubscribeKey/channel/ch1%2Cch2/heartbeat')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: '300', state: '{}' })
it('supports heartbeating for multiple channels', done => {
const scope = utils
.createNock()
.get('/v2/presence/sub-key/mySubscribeKey/channel/ch1%2Cch2/heartbeat')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: '300',
state: '{}',
})
.reply(200, '{"status": 200, "message": "OK", "service": "Presence"}');

@@ -64,11 +83,19 @@

}
}
},
});
pubnub.subscribe({ channels: ['ch1', 'ch2'] });
pubnub.subscribe({ channels: ['ch1', 'ch2'], withHeartbeats: true });
});
it('supports heartbeating for one channel group', (done) => {
const scope = utils.createNock().get('/v2/presence/sub-key/mySubscribeKey/channel/%2C/heartbeat')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: '300', state: '{}', 'channel-group': 'cg1' })
it('supports heartbeating for one channel group', done => {
const scope = utils
.createNock()
.get('/v2/presence/sub-key/mySubscribeKey/channel/%2C/heartbeat')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: '300',
state: '{}',
'channel-group': 'cg1',
})
.reply(200, '{"status": 200, "message": "OK", "service": "Presence"}');

@@ -83,11 +110,19 @@

}
}
},
});
pubnub.subscribe({ channelGroups: ['cg1'] });
pubnub.subscribe({ channelGroups: ['cg1'], withHeartbeats: true });
});
it('supports heartbeating for multiple channel group', (done) => {
const scope = utils.createNock().get('/v2/presence/sub-key/mySubscribeKey/channel/%2C/heartbeat')
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: '300', state: '{}', 'channel-group': 'cg1,cg2' })
it('supports heartbeating for multiple channel group', done => {
const scope = utils
.createNock()
.get('/v2/presence/sub-key/mySubscribeKey/channel/%2C/heartbeat')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
heartbeat: '300',
state: '{}',
'channel-group': 'cg1,cg2',
})
.reply(200, '{"status": 200, "message": "OK", "service": "Presence"}');

@@ -102,8 +137,8 @@

}
}
},
});
pubnub.subscribe({ channelGroups: ['cg1', 'cg2'] });
pubnub.subscribe({ channelGroups: ['cg1', 'cg2'], withHeartbeats: true });
});
});
});

@@ -8,3 +8,2 @@ /* global describe, it, __dirname */

let path = require('path');
let yaml = require('js-yaml');

@@ -14,11 +13,8 @@ let packageJSON = require('../../package.json');

let pubnubyml = yaml.safeLoad(fs.readFileSync(path.resolve(__dirname, '../../.pubnub.yml'), 'utf8'));
let readMe = fs.readFileSync(
path.resolve(__dirname, '../../README.md'),
'UTF-8'
);
let readMe = fs.readFileSync(path.resolve(__dirname, '../../README.md'), 'UTF-8');
describe('release should be consistent', () => {
it('with a matching pubnubyml and npm module', () => {
assert.equal(packageJSON.version, pubnubyml.version);
});
it('with bower valid entry point', () => {

@@ -37,5 +33,15 @@ assert.equal(bowerJSON.main, 'dist/web/pubnub.min.js');

it('with updated readme', () => {
assert(readMe.indexOf(`https://cdn.pubnub.com/sdk/javascript/pubnub.${packageJSON.version}.js`) > 1);
assert(readMe.indexOf(`https://cdn.pubnub.com/sdk/javascript/pubnub.${packageJSON.version}.min.js`) > 1);
assert(
readMe.indexOf(
`https://cdn.pubnub.com/sdk/javascript/pubnub.${packageJSON.version}.js`
) > 1
);
assert(
readMe.indexOf(
`https://cdn.pubnub.com/sdk/javascript/pubnub.${
packageJSON.version
}.min.js`
) > 1
);
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc