Skip to content

Commit 9a65f02

Browse files
authored
Merge pull request #114 from pubnub/develop
Release 4.18.0
2 parents 9a1f6dc + 29e40e8 commit 9a65f02

File tree

19 files changed

+180
-43
lines changed

19 files changed

+180
-43
lines changed

.pubnub.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
name: javascript
2-
version: 4.17.0
2+
version: 4.18.0
33
schema: 1
44
scm: github.com/pubnub/javascript
55
files:
66
- dist/web/pubnub.js
77
- dist/web/pubnub.min.js
88
changelog:
9+
- version: v4.18.0
10+
date: 2017-11-20
11+
changes:
12+
- type: improvement
13+
text: keepAlive is now initialized globally instead of per-call, allowing better connection reuse
14+
- type: feature
15+
text: added sdkName configuration parameter which allow completely override pnsdk in request query
916
- version: v4.17.0
1017
date: 2017-10-19
1118
changes:

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11

2+
## [v4.18.0](https://github.com/pubnub/javascript/tree/v4.18.0)
3+
November-20-2017
4+
5+
6+
[Full Changelog](https://github.com/pubnub/javascript/compare/v4.17.0...v4.18.0)
7+
8+
9+
- ⭐ keepAlive is now initialized globally instead of per-call, allowing better connection reuse
10+
- 🌟 added sdkName configuration parameter which allow completely override pnsdk in request query
11+
12+
13+
214
## [v4.17.0](https://github.com/pubnub/javascript/tree/v4.17.0)
315
October-19-2017
416

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ please use the [master_3x](https://github.com/pubnub/javascript/tree/master_3x)
1919
- If you **need help** or have a **general question**, contact <[email protected]>
2020

2121
## CDN Links
22-
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.17.0.min.js
23-
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.17.0.js
22+
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.18.0.min.js
23+
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.18.0.js

dist/titanium/pubnub.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! 4.17.0 / Consumer */
1+
/*! 4.18.0 / Consumer */
22
(function webpackUniversalModuleDefinition(root, factory) {
33
if(typeof exports === 'object' && typeof module === 'object')
44
module.exports = factory();
@@ -429,6 +429,7 @@ return /******/ (function(modules) { // webpackBootstrap
429429
this.secretKey = setup.secretKey || setup.secret_key;
430430
this.subscribeKey = setup.subscribeKey || setup.subscribe_key;
431431
this.publishKey = setup.publishKey || setup.publish_key;
432+
this.sdkName = setup.sdkName;
432433
this.sdkFamily = setup.sdkFamily;
433434
this.partnerId = setup.partnerId;
434435
this.setAuthKey(setup.authKey);
@@ -572,7 +573,7 @@ return /******/ (function(modules) { // webpackBootstrap
572573
}, {
573574
key: 'getVersion',
574575
value: function getVersion() {
575-
return '4.17.0';
576+
return '4.18.0';
576577
}
577578
}, {
578579
key: '_decideUUID',
@@ -2417,6 +2418,10 @@ return /******/ (function(modules) { // webpackBootstrap
24172418
}
24182419

24192420
function generatePNSDK(config) {
2421+
if (config.sdkName) {
2422+
return config.sdkName;
2423+
}
2424+
24202425
var base = 'PubNub-JS-' + config.sdkFamily;
24212426

24222427
if (config.partnerId) {

dist/titanium/pubnub.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web/pubnub.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! 4.17.0 / Consumer */
1+
/*! 4.18.0 / Consumer */
22
(function webpackUniversalModuleDefinition(root, factory) {
33
if(typeof exports === 'object' && typeof module === 'object')
44
module.exports = factory();
@@ -451,6 +451,7 @@ return /******/ (function(modules) { // webpackBootstrap
451451
this.secretKey = setup.secretKey || setup.secret_key;
452452
this.subscribeKey = setup.subscribeKey || setup.subscribe_key;
453453
this.publishKey = setup.publishKey || setup.publish_key;
454+
this.sdkName = setup.sdkName;
454455
this.sdkFamily = setup.sdkFamily;
455456
this.partnerId = setup.partnerId;
456457
this.setAuthKey(setup.authKey);
@@ -594,7 +595,7 @@ return /******/ (function(modules) { // webpackBootstrap
594595
}, {
595596
key: 'getVersion',
596597
value: function getVersion() {
597-
return '4.17.0';
598+
return '4.18.0';
598599
}
599600
}, {
600601
key: '_decideUUID',
@@ -2439,6 +2440,10 @@ return /******/ (function(modules) { // webpackBootstrap
24392440
}
24402441

24412442
function generatePNSDK(config) {
2443+
if (config.sdkName) {
2444+
return config.sdkName;
2445+
}
2446+
24422447
var base = 'PubNub-JS-' + config.sdkFamily;
24432448

24442449
if (config.partnerId) {

dist/web/pubnub.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/components/config.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/components/config.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/components/endpoint.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/components/endpoint.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/networking/modules/node.js

Lines changed: 11 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/networking/modules/node.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pubnub",
3-
"version": "4.17.0",
3+
"version": "4.18.0",
44
"author": "PubNub <[email protected]>",
55
"description": "Publish & Subscribe Real-time Messaging with PubNub",
66
"bin": {},

src/core/components/config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ export default class {
2727
*/
2828
instanceId: string;
2929

30+
/*
31+
If the SDK is running as part of another SDK built atop of it, allow a custom pnsdk with name and version.
32+
*/
33+
sdkName: string;
34+
3035
/*
3136
keep track of the SDK family for identifier generator
3237
*/
@@ -130,6 +135,7 @@ export default class {
130135
this.secretKey = setup.secretKey || setup.secret_key;
131136
this.subscribeKey = setup.subscribeKey || setup.subscribe_key;
132137
this.publishKey = setup.publishKey || setup.publish_key;
138+
this.sdkName = setup.sdkName;
133139
this.sdkFamily = setup.sdkFamily;
134140
this.partnerId = setup.partnerId;
135141
this.setAuthKey(setup.authKey);
@@ -218,7 +224,7 @@ export default class {
218224
setSendBeaconConfig(val: boolean): this { this._useSendBeacon = val; return this; }
219225

220226
getVersion(): string {
221-
return '4.17.0';
227+
return '4.18.0';
222228
}
223229

224230
_decideUUID(providedUUID: string): string {

src/core/components/endpoint.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ function decideURL(endpoint, modules, incomingParams) {
3232
}
3333

3434
function generatePNSDK(config: Config): string {
35+
if (config.sdkName) {
36+
return config.sdkName;
37+
}
38+
3539
let base = `PubNub-JS-${config.sdkFamily}`;
3640

3741
if (config.partnerId) {

src/networking/modules/node.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,25 @@ import superagent from 'superagent';
44
import superagentProxy from 'superagent-proxy';
55
import AgentKeepAlive from 'agentkeepalive';
66

7+
let keepAliveAgent: (AgentKeepAlive | AgentKeepAlive.HttpsAgent) = null;
8+
let keepAliveSecureAgent: (AgentKeepAlive | AgentKeepAlive.HttpsAgent) = null;
9+
710
superagentProxy(superagent);
811

912
export function proxy(superagentConstruct: superagent) {
1013
return superagentConstruct.proxy(this._config.proxy);
1114
}
1215

1316
export function keepAlive(superagentConstruct: superagent) {
14-
let AgentClass = null;
15-
let agent = null;
16-
17-
if (this._config.secure) {
18-
AgentClass = AgentKeepAlive.HttpsAgent;
19-
} else {
20-
AgentClass = AgentKeepAlive;
21-
}
22-
23-
if (this._config.keepAliveSettings) {
17+
let agent = this._config.secure ? keepAliveSecureAgent : keepAliveAgent;
18+
if (agent === null) {
19+
let AgentClass = this._config.secure ? AgentKeepAlive.HttpsAgent : AgentKeepAlive;
2420
agent = new AgentClass(this._config.keepAliveSettings);
25-
} else {
26-
agent = new AgentClass();
21+
if (this._config.secure) {
22+
keepAliveSecureAgent = agent;
23+
} else {
24+
keepAliveAgent = agent;
25+
}
2726
}
2827

2928
return superagentConstruct.agent(agent);

test/integration/components/networking.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import packageJSON from '../../../package.json';
1010
describe('#components/networking', () => {
1111
let pubnub;
1212
let pubnubPartner;
13+
let pubnubSDKName;
1314

1415
before(() => {
1516
nock.disableNetConnect();
@@ -23,6 +24,7 @@ describe('#components/networking', () => {
2324
nock.cleanAll();
2425
pubnub = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', uuid: 'myUUID' });
2526
pubnubPartner = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', uuid: 'myUUID', partnerId: 'alligator' });
27+
pubnubSDKName = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', uuid: 'myUUID', sdkName: 'custom-sdk/1.0.0' });
2628
});
2729

2830
describe('supports user-agent generation with partner', () => {
@@ -39,6 +41,20 @@ describe('#components/networking', () => {
3941
});
4042
});
4143

44+
describe('supports PNSDK generation with custom SDK name', () => {
45+
it('returns a correct response object', (done) => {
46+
utils.createNock().get('/time/0')
47+
.query({ uuid: 'myUUID', pnsdk: 'custom-sdk/1.0.0' })
48+
.reply(200, [14570763868573725]);
49+
50+
pubnubSDKName.time((status) => {
51+
assert.equal(status.error, false);
52+
assert.equal(status.statusCode, 200);
53+
done();
54+
});
55+
});
56+
});
57+
4258
describe('callback handling', () => {
4359
it('returns a correct status object', (done) => {
4460
utils.createNock().get('/time/0')

test/unit/networking.test.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* global describe, it, before, after */
2+
3+
import superagent from 'superagent';
4+
import sinon from 'sinon';
5+
import nock from 'nock';
6+
import assert from 'assert';
7+
8+
import Networking from '../../src/networking';
9+
import { del, get, post } from '../../src/networking/modules/web-node';
10+
import { keepAlive, proxy } from '../../src/networking/modules/node';
11+
12+
describe('keep-alive agent', () => {
13+
before(() => nock.disableNetConnect());
14+
after(() => nock.enableNetConnect());
15+
16+
const setupNetwork = (shouldSecure, enableKeepAlive) => {
17+
const config = { origin: 'ps.pndsn.com', secure: shouldSecure, keepAlive: enableKeepAlive, logVerbosity: false };
18+
const networking = new Networking({ keepAlive, del, get, post, proxy });
19+
networking.init(config);
20+
21+
return networking;
22+
};
23+
24+
it('should not create if \'keepAlive\' is \'false\'', () => {
25+
const networking = setupNetwork(false, false);
26+
const superagentGetSpy = sinon.spy(superagent, 'get');
27+
28+
networking.GET({}, { url: '/time/0' }, () => {});
29+
assert(superagentGetSpy.called, 'superagent not called with get');
30+
assert(superagentGetSpy.returnValues[0], 'request instance not created');
31+
assert(!superagentGetSpy.returnValues[0]._agent, 'keep-alive agent should not be created');
32+
33+
superagentGetSpy.restore();
34+
});
35+
36+
it('should create agent for insecure connection', () => {
37+
const networking = setupNetwork(false, true);
38+
const superagentGetSpy = sinon.spy(superagent, 'get');
39+
40+
networking.GET({}, { url: '/time/0' }, () => {});
41+
assert(superagentGetSpy.returnValues[0]._agent, 'keep-alive agent not created');
42+
assert(superagentGetSpy.returnValues[0]._agent.defaultPort !== 443, 'keep-alive agent should access TLS (80) port');
43+
44+
superagentGetSpy.restore();
45+
});
46+
47+
it('should re-use created agent for insecure connection', () => {
48+
const networking = setupNetwork(false, true);
49+
const superagentGetSpy = sinon.spy(superagent, 'get');
50+
51+
networking.GET({}, { url: '/time/0' }, () => {});
52+
networking.GET({}, { url: '/time/0' }, () => {});
53+
assert(superagentGetSpy.returnValues[0]._agent === superagentGetSpy.returnValues[1]._agent, 'same user-agent should be used');
54+
55+
superagentGetSpy.restore();
56+
});
57+
58+
it('should create agent for secure connection', () => {
59+
const networking = setupNetwork(true, true);
60+
const superagentGetSpy = sinon.spy(superagent, 'get');
61+
62+
networking.GET({}, { url: '/time/0' }, () => {});
63+
assert(superagentGetSpy.returnValues[0]._agent, 'keep-alive agent not created');
64+
assert(superagentGetSpy.returnValues[0]._agent.defaultPort === 443, 'keep-alive agent should access SSL (443) port');
65+
66+
superagentGetSpy.restore();
67+
});
68+
69+
it('should re-use created agent for secure connection', () => {
70+
const networking = setupNetwork(true, true);
71+
const superagentGetSpy = sinon.spy(superagent, 'get');
72+
73+
networking.GET({}, { url: '/time/0' }, () => {});
74+
networking.GET({}, { url: '/time/0' }, () => {});
75+
assert(superagentGetSpy.returnValues[0]._agent === superagentGetSpy.returnValues[1]._agent, 'same user-agent should be used');
76+
77+
superagentGetSpy.restore();
78+
});
79+
});

0 commit comments

Comments
 (0)