diff --git a/doc/7/core-classes/kuzzle/constructor/index.md b/doc/7/core-classes/kuzzle/constructor/index.md
index d496a7e4a..7ce3b9f94 100644
--- a/doc/7/core-classes/kuzzle/constructor/index.md
+++ b/doc/7/core-classes/kuzzle/constructor/index.md
@@ -41,7 +41,7 @@ Kuzzle SDK instance options.
| `autoQueue` |
boolean
(`false`) | Automatically queue all requests during offline mode |
| `autoReplay` | boolean
(`false`) | Automatically replay queued requests on a `reconnected` event |
| `autoResubscribe` | boolean
(`true`) | Automatically renew all subscriptions on a `reconnected` event |
-| `cookieAuth` | boolean
(`false`) | Uses cookie to store token, this option set `offlineMode` to `auto` and `autoResubscribe` to `true` |
+| `cookieAuth` | boolean
(`false`) | Uses cookie to store token |
| `deprecationWarning` | boolean
(`true`) | Show deprecation warning in development (hidden either way in production) |
| `eventTimeout` | number
(`200`) | Time (in ms) during which a similar event is ignored |
| `offlineMode` | string
(`manual`) | Offline mode configuration. Can be `manual` or `auto` |
diff --git a/package-lock.json b/package-lock.json
index 686077c7b..e832ea61b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "kuzzle-sdk",
- "version": "7.6.2",
+ "version": "7.6.3",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/package.json b/package.json
index 7aae85fa0..b93bdc628 100644
--- a/package.json
+++ b/package.json
@@ -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 ",
"repository": {
diff --git a/src/protocols/WebSocket.ts b/src/protocols/WebSocket.ts
index 2f675dd55..0bdd1c534 100644
--- a/src/protocols/WebSocket.ts
+++ b/src/protocols/WebSocket.ts
@@ -81,7 +81,7 @@ export default class WebSocketProtocol extends BaseProtocolRealtime {
/**
* Connect to the websocket server
*/
- connect (): Promise {
+ _connect (): Promise {
return new Promise((resolve, reject) => {
const url = `${this.ssl ? 'wss' : 'ws'}://${this.host}:${this.port}`;
@@ -211,6 +211,14 @@ export default class WebSocketProtocol extends BaseProtocolRealtime {
});
}
+ connect (): Promise {
+ 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');
diff --git a/test/protocol/WebSocket.test.js b/test/protocol/WebSocket.test.js
index e69d60160..056211862 100644
--- a/test/protocol/WebSocket.test.js
+++ b/test/protocol/WebSocket.test.js
@@ -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, [], {}, ''];