Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/7/core-classes/kuzzle/constructor/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Kuzzle SDK instance options.
| `autoQueue` | <pre>boolean</pre><br/>(`false`) | Automatically queue all requests during offline mode |
| `autoReplay` | <pre>boolean</pre><br/>(`false`) | Automatically replay queued requests on a `reconnected` event |
| `autoResubscribe` | <pre>boolean</pre><br/>(`true`) | Automatically renew all subscriptions on a `reconnected` event |
| `cookieAuth` | <pre>boolean</pre><br/>(`false`) | Uses cookie to store token, this option set `offlineMode` to `auto` and `autoResubscribe` to `true` |
| `cookieAuth` | <pre>boolean</pre><br/>(`false`) | Uses cookie to store token |
| `deprecationWarning` | <pre>boolean</pre><br />(`true`) | Show deprecation warning in development (hidden either way in production) |
| `eventTimeout` | <pre>number</pre><br/>(`200`) | Time (in ms) during which a similar event is ignored |
| `offlineMode` | <pre>string</pre><br/>(`manual`) | Offline mode configuration. Can be `manual` or `auto` |
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kuzzle-sdk",
"version": "7.6.2",
"version": "7.6.3",
"description": "Official Javascript SDK for Kuzzle",
"author": "The Kuzzle Team <[email protected]>",
"repository": {
Expand Down
10 changes: 9 additions & 1 deletion src/protocols/WebSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class WebSocketProtocol extends BaseProtocolRealtime {
/**
* Connect to the websocket server
*/
connect (): Promise<void> {
_connect (): Promise<void> {
return new Promise((resolve, reject) => {
const url = `${this.ssl ? 'wss' : 'ws'}://${this.host}:${this.port}`;

Expand Down Expand Up @@ -211,6 +211,14 @@ export default class WebSocketProtocol extends BaseProtocolRealtime {
});
}

connect (): Promise<void> {
if (this.cookieSupport) {
return this._httpProtocol.connect()
.then(() => this._connect());
}
return this._connect();
}

enableCookieSupport () {
if (typeof XMLHttpRequest === 'undefined') {
throw new Error('Support for cookie cannot be enabled outside of a browser');
Expand Down
24 changes: 24 additions & 0 deletions test/protocol/WebSocket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,30 @@ describe('WebSocket networking module', () => {
});
});

describe('#connect', () => {
it('connect should call the connect method of the HttpProtocol when cookieSupport is true', async () => {
websocket._cookieSupport = true;
websocket._httpProtocol = {
connect: sinon.stub().resolves()
};
websocket._connect = sinon.stub().resolves();
await websocket.connect();
await should(websocket._httpProtocol.connect).be.called();
await should(websocket._connect).be.called();
});

it('connect should not call the connect method of the HttpProtocol when cookieSupport is false', async () => {
websocket._cookieSupport = false;
websocket._httpProtocol = {
connect: sinon.stub().resolves()
};
websocket._connect = sinon.stub().resolves();
await websocket.connect();
await should(websocket._httpProtocol.connect).not.be.called();
await should(websocket._connect).be.called();
});
});

describe('#constructor', () => {
it('should throw if an invalid host is provided', () => {
const invalidHosts = [undefined, null, 123, false, true, [], {}, ''];
Expand Down