Skip to content

Commit 5945f98

Browse files
are-pubnubparfeonClient Engineering Bot
authored
feat: allow multiple origins in config (#231)
* feat: allow multiple origins in config * PubNub SDK v4.35.0 release. Co-authored-by: Serhii Mamontov <[email protected]> Co-authored-by: Client Engineering Bot <60980775+Client Engineering [email protected]>
1 parent d4180ec commit 5945f98

File tree

19 files changed

+251
-89
lines changed

19 files changed

+251
-89
lines changed

.pubnub.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
---
22
changelog:
3+
- date: 2021-12-02
4+
version: v4.35.0
5+
changes:
6+
- type: feature
7+
text: "Allows to specify multiple origins in the config, which enables domain sharding for custom origins."
38
- date: 2021-12-01
49
version: v4.34.2
510
changes:
@@ -1076,7 +1081,7 @@ supported-platforms:
10761081
- "Ubuntu 14.04 and up"
10771082
- "Windows 7 and up"
10781083
version: "Pubnub Javascript for Node"
1079-
version: "4.34.2"
1084+
version: "4.35.0"
10801085
sdks:
10811086
-
10821087
full-name: PubNub Javascript SDK
@@ -1095,7 +1100,7 @@ sdks:
10951100
distribution-type: source
10961101
distribution-repository: GitHub release
10971102
package-name: pubnub.js
1098-
location: https://github.com/pubnub/javascript/archive/refs/tags/v4.34.2.zip
1103+
location: https://github.com/pubnub/javascript/archive/refs/tags/v4.35.0.zip
10991104
requires:
11001105
-
11011106
name: "agentkeepalive"
@@ -1859,7 +1864,7 @@ sdks:
18591864
distribution-type: library
18601865
distribution-repository: GitHub release
18611866
package-name: pubnub.js
1862-
location: https://github.com/pubnub/javascript/releases/download/v4.34.2/pubnub.4.34.2.js
1867+
location: https://github.com/pubnub/javascript/releases/download/v4.35.0/pubnub.4.35.0.js
18631868
requires:
18641869
-
18651870
name: "agentkeepalive"

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v4.35.0
2+
December 02 2021
3+
4+
#### Added
5+
- Allows to specify multiple origins in the config, which enables domain sharding for custom origins.
6+
17
## v4.34.2
28
December 01 2021
39

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ You will need the publish and subscribe keys to authenticate your app. Get your
2222
npm install pubnub
2323
```
2424
* or download one of our builds from our CDN:
25-
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.34.2.js
26-
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.34.2.min.js
25+
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.35.0.js
26+
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.35.0.min.js
2727
2828
2. Configure your keys:
2929

dist/titanium/pubnub.js

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! 4.34.2 / Consumer */
1+
/*! 4.35.0 / Consumer */
22
exports["PubNub"] =
33
/******/ (function(modules) { // webpackBootstrap
44
/******/ // The module cache
@@ -366,6 +366,14 @@ var _flow_interfaces = __webpack_require__(2);
366366
var PRESENCE_TIMEOUT_MINIMUM = 20;
367367
var PRESENCE_TIMEOUT_DEFAULT = 300;
368368

369+
var makeDefaultOrigins = function makeDefaultOrigins() {
370+
return Array.from({
371+
length: 20
372+
}, function (_, i) {
373+
return "ps".concat(i + 1, ".pndsn.com");
374+
});
375+
};
376+
369377
var _default = function () {
370378
function _default(_ref) {
371379
var _setup$fileUploadPubl, _setup$useRandomIVs;
@@ -423,7 +431,12 @@ var _default = function () {
423431
this.setAuthKey(setup.authKey);
424432
this.setCipherKey(setup.cipherKey);
425433
this.setFilterExpression(setup.filterExpression);
426-
this.origin = setup.origin || 'ps.pndsn.com';
434+
435+
if (typeof setup.origin !== 'string' && !Array.isArray(setup.origin) && setup.origin !== undefined) {
436+
throw new Error('Origin must be either undefined, a string or a list of strings.');
437+
}
438+
439+
this.origin = setup.origin || makeDefaultOrigins();
427440
this.secure = setup.ssl || false;
428441
this.restore = setup.restore || false;
429442
this.proxy = setup.proxy;
@@ -575,7 +588,7 @@ var _default = function () {
575588
}, {
576589
key: "getVersion",
577590
value: function getVersion() {
578-
return '4.34.2';
591+
return '4.35.0';
579592
}
580593
}, {
581594
key: "_addPnsdkSuffix",
@@ -8638,7 +8651,8 @@ var _default = function _default(modules, _ref) {
86388651
var channel = _ref.channel,
86398652
id = _ref.id,
86408653
name = _ref.name;
8641-
var config = modules.config;
8654+
var config = modules.config,
8655+
networking = modules.networking;
86428656

86438657
if (!channel) {
86448658
throw new _endpoint.PubNubError('Validation failed, check status for details', (0, _endpoint.createValidationError)("channel can't be empty"));
@@ -8674,10 +8688,10 @@ var _default = function _default(modules, _ref) {
86748688
}).join('&');
86758689

86768690
if (queryParams !== '') {
8677-
return "https://".concat(config.origin).concat(url, "?").concat(queryParams);
8691+
return "".concat(networking.getStandardOrigin()).concat(url, "?").concat(queryParams);
86788692
}
86798693

8680-
return "https://".concat(config.origin).concat(url);
8694+
return "".concat(networking.getStandardOrigin()).concat(url);
86818695
};
86828696

86838697
exports["default"] = _default;
@@ -13265,11 +13279,9 @@ var _default = function () {
1326513279
(0, _classCallCheck2["default"])(this, _default);
1326613280
(0, _defineProperty2["default"])(this, "_modules", void 0);
1326713281
(0, _defineProperty2["default"])(this, "_config", void 0);
13268-
(0, _defineProperty2["default"])(this, "_maxSubDomain", void 0);
1326913282
(0, _defineProperty2["default"])(this, "_currentSubDomain", void 0);
1327013283
(0, _defineProperty2["default"])(this, "_standardOrigin", void 0);
1327113284
(0, _defineProperty2["default"])(this, "_subscribeOrigin", void 0);
13272-
(0, _defineProperty2["default"])(this, "_providedFQDN", void 0);
1327313285
(0, _defineProperty2["default"])(this, "_requestTimeout", void 0);
1327413286
(0, _defineProperty2["default"])(this, "_coreParams", void 0);
1327513287
this._modules = {};
@@ -13282,28 +13294,33 @@ var _default = function () {
1328213294
key: "init",
1328313295
value: function init(config) {
1328413296
this._config = config;
13285-
this._maxSubDomain = 20;
13286-
this._currentSubDomain = Math.floor(Math.random() * this._maxSubDomain);
13287-
this._providedFQDN = (this._config.secure ? 'https://' : 'http://') + this._config.origin;
13297+
13298+
if (Array.isArray(this._config.origin)) {
13299+
this._currentSubDomain = Math.floor(Math.random() * this._config.origin.length);
13300+
} else {
13301+
this._currentSubDomain = 0;
13302+
}
13303+
1328813304
this._coreParams = {};
1328913305
this.shiftStandardOrigin();
1329013306
}
1329113307
}, {
1329213308
key: "nextOrigin",
1329313309
value: function nextOrigin() {
13294-
if (!this._providedFQDN.match(/ps\.pndsn\.com$/i)) {
13295-
return this._providedFQDN;
13310+
var protocol = this._config.secure ? 'https://' : 'http://';
13311+
13312+
if (typeof this._config.origin === 'string') {
13313+
return "".concat(protocol).concat(this._config.origin);
1329613314
}
1329713315

13298-
var newSubDomain;
1329913316
this._currentSubDomain += 1;
1330013317

13301-
if (this._currentSubDomain >= this._maxSubDomain) {
13302-
this._currentSubDomain = 1;
13318+
if (this._currentSubDomain >= this._config.origin.length) {
13319+
this._currentSubDomain = 0;
1330313320
}
1330413321

13305-
newSubDomain = this._currentSubDomain.toString();
13306-
return this._providedFQDN.replace('ps.pndsn.com', "ps".concat(newSubDomain, ".pndsn.com"));
13322+
var origin = this._config.origin[this._currentSubDomain];
13323+
return "".concat(protocol).concat(origin);
1330713324
}
1330813325
}, {
1330913326
key: "hasModule",

dist/titanium/pubnub.min.js

Lines changed: 2 additions & 2 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: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! 4.34.2 / Consumer */
1+
/*! 4.35.0 / Consumer */
22
(function webpackUniversalModuleDefinition(root, factory) {
33
if(typeof exports === 'object' && typeof module === 'object')
44
module.exports = factory();
@@ -376,6 +376,14 @@ var _flow_interfaces = __webpack_require__(2);
376376
var PRESENCE_TIMEOUT_MINIMUM = 20;
377377
var PRESENCE_TIMEOUT_DEFAULT = 300;
378378

379+
var makeDefaultOrigins = function makeDefaultOrigins() {
380+
return Array.from({
381+
length: 20
382+
}, function (_, i) {
383+
return "ps".concat(i + 1, ".pndsn.com");
384+
});
385+
};
386+
379387
var _default = function () {
380388
function _default(_ref) {
381389
var _setup$fileUploadPubl, _setup$useRandomIVs;
@@ -433,7 +441,12 @@ var _default = function () {
433441
this.setAuthKey(setup.authKey);
434442
this.setCipherKey(setup.cipherKey);
435443
this.setFilterExpression(setup.filterExpression);
436-
this.origin = setup.origin || 'ps.pndsn.com';
444+
445+
if (typeof setup.origin !== 'string' && !Array.isArray(setup.origin) && setup.origin !== undefined) {
446+
throw new Error('Origin must be either undefined, a string or a list of strings.');
447+
}
448+
449+
this.origin = setup.origin || makeDefaultOrigins();
437450
this.secure = setup.ssl || false;
438451
this.restore = setup.restore || false;
439452
this.proxy = setup.proxy;
@@ -585,7 +598,7 @@ var _default = function () {
585598
}, {
586599
key: "getVersion",
587600
value: function getVersion() {
588-
return '4.34.2';
601+
return '4.35.0';
589602
}
590603
}, {
591604
key: "_addPnsdkSuffix",
@@ -11467,7 +11480,8 @@ var _default = function _default(modules, _ref) {
1146711480
var channel = _ref.channel,
1146811481
id = _ref.id,
1146911482
name = _ref.name;
11470-
var config = modules.config;
11483+
var config = modules.config,
11484+
networking = modules.networking;
1147111485

1147211486
if (!channel) {
1147311487
throw new _endpoint.PubNubError('Validation failed, check status for details', (0, _endpoint.createValidationError)("channel can't be empty"));
@@ -11503,10 +11517,10 @@ var _default = function _default(modules, _ref) {
1150311517
}).join('&');
1150411518

1150511519
if (queryParams !== '') {
11506-
return "https://".concat(config.origin).concat(url, "?").concat(queryParams);
11520+
return "".concat(networking.getStandardOrigin()).concat(url, "?").concat(queryParams);
1150711521
}
1150811522

11509-
return "https://".concat(config.origin).concat(url);
11523+
return "".concat(networking.getStandardOrigin()).concat(url);
1151011524
};
1151111525

1151211526
exports["default"] = _default;
@@ -16094,11 +16108,9 @@ var _default = function () {
1609416108
(0, _classCallCheck2["default"])(this, _default);
1609516109
(0, _defineProperty2["default"])(this, "_modules", void 0);
1609616110
(0, _defineProperty2["default"])(this, "_config", void 0);
16097-
(0, _defineProperty2["default"])(this, "_maxSubDomain", void 0);
1609816111
(0, _defineProperty2["default"])(this, "_currentSubDomain", void 0);
1609916112
(0, _defineProperty2["default"])(this, "_standardOrigin", void 0);
1610016113
(0, _defineProperty2["default"])(this, "_subscribeOrigin", void 0);
16101-
(0, _defineProperty2["default"])(this, "_providedFQDN", void 0);
1610216114
(0, _defineProperty2["default"])(this, "_requestTimeout", void 0);
1610316115
(0, _defineProperty2["default"])(this, "_coreParams", void 0);
1610416116
this._modules = {};
@@ -16111,28 +16123,33 @@ var _default = function () {
1611116123
key: "init",
1611216124
value: function init(config) {
1611316125
this._config = config;
16114-
this._maxSubDomain = 20;
16115-
this._currentSubDomain = Math.floor(Math.random() * this._maxSubDomain);
16116-
this._providedFQDN = (this._config.secure ? 'https://' : 'http://') + this._config.origin;
16126+
16127+
if (Array.isArray(this._config.origin)) {
16128+
this._currentSubDomain = Math.floor(Math.random() * this._config.origin.length);
16129+
} else {
16130+
this._currentSubDomain = 0;
16131+
}
16132+
1611716133
this._coreParams = {};
1611816134
this.shiftStandardOrigin();
1611916135
}
1612016136
}, {
1612116137
key: "nextOrigin",
1612216138
value: function nextOrigin() {
16123-
if (!this._providedFQDN.match(/ps\.pndsn\.com$/i)) {
16124-
return this._providedFQDN;
16139+
var protocol = this._config.secure ? 'https://' : 'http://';
16140+
16141+
if (typeof this._config.origin === 'string') {
16142+
return "".concat(protocol).concat(this._config.origin);
1612516143
}
1612616144

16127-
var newSubDomain;
1612816145
this._currentSubDomain += 1;
1612916146

16130-
if (this._currentSubDomain >= this._maxSubDomain) {
16131-
this._currentSubDomain = 1;
16147+
if (this._currentSubDomain >= this._config.origin.length) {
16148+
this._currentSubDomain = 0;
1613216149
}
1613316150

16134-
newSubDomain = this._currentSubDomain.toString();
16135-
return this._providedFQDN.replace('ps.pndsn.com', "ps".concat(newSubDomain, ".pndsn.com"));
16151+
var origin = this._config.origin[this._currentSubDomain];
16152+
return "".concat(protocol).concat(origin);
1613616153
}
1613716154
}, {
1613816155
key: "hasModule",

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: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)