Skip to content

Commit c1c6ecf

Browse files
authored
Merge 1a626f8 into 6dfbf13
2 parents 6dfbf13 + 1a626f8 commit c1c6ecf

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

doc/7/core-classes/kuzzle/constructor/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Kuzzle SDK instance options.
4141
| `autoQueue` | <pre>boolean</pre><br/>(`false`) | Automatically queue all requests during offline mode |
4242
| `autoReplay` | <pre>boolean</pre><br/>(`false`) | Automatically replay queued requests on a `reconnected` event |
4343
| `autoResubscribe` | <pre>boolean</pre><br/>(`true`) | Automatically renew all subscriptions on a `reconnected` event |
44-
| `cookieAuth` | <pre>boolean</pre><br/>(`false`) | Uses cookie to store token, this option set `offlineMode` to `auto` and `autoResubscribe` to `true` |
44+
| `cookieAuth` | <pre>boolean</pre><br/>(`false`) | Uses cookie to store token |
4545
| `deprecationWarning` | <pre>boolean</pre><br />(`true`) | Show deprecation warning in development (hidden either way in production) |
4646
| `eventTimeout` | <pre>number</pre><br/>(`200`) | Time (in ms) during which a similar event is ignored |
4747
| `offlineMode` | <pre>string</pre><br/>(`manual`) | Offline mode configuration. Can be `manual` or `auto` |

package-lock.json

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": "kuzzle-sdk",
3-
"version": "7.6.2",
3+
"version": "7.6.3",
44
"description": "Official Javascript SDK for Kuzzle",
55
"author": "The Kuzzle Team <[email protected]>",
66
"repository": {

src/protocols/WebSocket.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default class WebSocketProtocol extends BaseProtocolRealtime {
8181
/**
8282
* Connect to the websocket server
8383
*/
84-
connect (): Promise<void> {
84+
_connect (): Promise<void> {
8585
return new Promise((resolve, reject) => {
8686
const url = `${this.ssl ? 'wss' : 'ws'}://${this.host}:${this.port}`;
8787

@@ -211,6 +211,14 @@ export default class WebSocketProtocol extends BaseProtocolRealtime {
211211
});
212212
}
213213

214+
connect (): Promise<void> {
215+
if (this.cookieSupport) {
216+
return this._httpProtocol.connect()
217+
.then(() => this._connect());
218+
}
219+
return this._connect();
220+
}
221+
214222
enableCookieSupport () {
215223
if (typeof XMLHttpRequest === 'undefined') {
216224
throw new Error('Support for cookie cannot be enabled outside of a browser');

test/protocol/WebSocket.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,30 @@ describe('WebSocket networking module', () => {
509509
});
510510
});
511511

512+
describe('#connect', () => {
513+
it('connect should call the connect method of the HttpProtocol when cookieSupport is true', async () => {
514+
websocket._cookieSupport = true;
515+
websocket._httpProtocol = {
516+
connect: sinon.stub().resolves()
517+
};
518+
websocket._connect = sinon.stub().resolves();
519+
await websocket.connect();
520+
await should(websocket._httpProtocol.connect).be.called();
521+
await should(websocket._connect).be.called();
522+
});
523+
524+
it('connect should not call the connect method of the HttpProtocol when cookieSupport is false', async () => {
525+
websocket._cookieSupport = false;
526+
websocket._httpProtocol = {
527+
connect: sinon.stub().resolves()
528+
};
529+
websocket._connect = sinon.stub().resolves();
530+
await websocket.connect();
531+
await should(websocket._httpProtocol.connect).not.be.called();
532+
await should(websocket._connect).be.called();
533+
});
534+
});
535+
512536
describe('#constructor', () => {
513537
it('should throw if an invalid host is provided', () => {
514538
const invalidHosts = [undefined, null, 123, false, true, [], {}, ''];

0 commit comments

Comments
 (0)