Skip to content

Commit 7a285b3

Browse files
authored
Merge pull request #103 from Filsh/master
Support secure connection
2 parents 23ab6fb + 697f580 commit 7a285b3

File tree

15 files changed

+67
-22
lines changed

15 files changed

+67
-22
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
*__note:__ the # at the end of lines are the pull request numbers on GitHub*
22

3+
# 2.0.2
4+
5+
* https://github.com/kuzzleio/sdk-javascript/releases/tag/2.0.2
6+
37
# 2.0.0
48

59
* https://github.com/kuzzleio/sdk-javascript/releases/tag/2.0.0

dist/kuzzle.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/kuzzle.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.

dist/kuzzle.min.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.

dist/kuzzle.min.map

Lines changed: 1 addition & 0 deletions
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": "kuzzle-sdk",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "Official Javascript SDK for Kuzzle",
55
"author": "The Kuzzle Team <support@kuzzle.io>",
66
"repository": {

src/kuzzle.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ module.exports = Kuzzle = function (host, options, cb) {
119119
value: (options && typeof options.ioPort === 'number') ? options.ioPort : 7512,
120120
enumerable: true
121121
},
122+
sslConnection: {
123+
value: (options && typeof options.sslConnection === 'boolean') ? options.sslConnection : false,
124+
enumerable: true
125+
},
122126
autoQueue: {
123127
value: false,
124128
enumerable: true,
@@ -311,7 +315,7 @@ Kuzzle.prototype.connect = function () {
311315
var self = this;
312316

313317
if (!self.network) {
314-
self.network = networkWrapper(self.host, self.wsPort, self.ioPort);
318+
self.network = networkWrapper(self.host, self.wsPort, self.ioPort, self.sslConnection);
315319
}
316320

317321
if (['initializing', 'ready', 'disconnected', 'error', 'offline'].indexOf(this.state) === -1) {
@@ -1451,5 +1455,3 @@ Kuzzle.prototype.stopQueuing = function () {
14511455

14521456
return this;
14531457
};
1454-
1455-

src/networkWrapper/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
* @returns {Object} tnstantiated WebSocket/Socket.IO object
77
*/
88

9-
function network(host, wsPort, ioPort) {
9+
function network(host, wsPort, ioPort, sslConnection) {
1010
// Web browser / NodeJS websocket handling
1111
if (typeof window !== 'undefined') {
1212
// use native websockets if the browser supports it
1313
if (typeof WebSocket !== 'undefined') {
14-
return new (require('./wrappers/wsbrowsers'))(host, wsPort);
14+
return new (require('./wrappers/wsbrowsers'))(host, wsPort, sslConnection);
1515
}
1616
// otherwise fallback to socket.io, if available
1717
else if (window.io) {
18-
return new (require('./wrappers/socketio'))(host, ioPort);
18+
return new (require('./wrappers/socketio'))(host, ioPort, sslConnection);
1919
}
2020

2121
throw new Error('Aborting: no websocket support detected and no socket.io library loaded either.');
2222
}
2323

24-
return new (require('./wrappers/wsnode'))(host, wsPort);
24+
return new (require('./wrappers/wsnode'))(host, wsPort, sslConnection);
2525
}
2626

2727
module.exports = network;

src/networkWrapper/wrappers/socketio.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
function SocketIO(host, port) {
1+
function SocketIO(host, port, ssl) {
22
this.host = host;
33
this.port = port;
4+
this.ssl = ssl;
45
this.socket = null;
56

67
/**
@@ -11,7 +12,7 @@ function SocketIO(host, port) {
1112
* @param {int} reconnectionDelay
1213
*/
1314
this.connect = function (autoReconnect, reconnectionDelay) {
14-
this.socket = window.io('http://' + this.host + ':' + this.port, {
15+
this.socket = window.io((this.ssl ? 'https://' : 'http://') + this.host + ':' + this.port, {
1516
reconnection: autoReconnect,
1617
reconnectionDelay: reconnectionDelay,
1718
forceNew: true

src/networkWrapper/wrappers/wsbrowsers.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
function WSBrowsers(host, port) {
1+
function WSBrowsers(host, port, ssl) {
22
var self = this;
33
this.host = host;
44
this.port = port;
5+
this.ssl = ssl;
56
this.client = null;
67
this.retrying = false;
78

@@ -28,7 +29,7 @@ function WSBrowsers(host, port) {
2829
* @returns {Object} Socket
2930
*/
3031
this.connect = function (autoReconnect, reconnectionDelay) {
31-
this.client = new WebSocket('ws://' + this.host + ':' + this.port);
32+
this.client = new WebSocket((this.ssl ? 'wss://' : 'ws://') + this.host + ':' + this.port);
3233

3334
this.client.onopen = function () {
3435
if (self.retrying) {

0 commit comments

Comments
 (0)