quiq-chat
Advanced tools
Comparing version 1.8.3 to 1.8.4
@@ -260,3 +260,3 @@ 'use strict'; | ||
var version = "1.8.3"; | ||
var version = "1.8.4"; | ||
@@ -385,3 +385,3 @@ // | ||
}).then(function (res) { | ||
if (_onNewSession) _onNewSession(res.tokenId); | ||
if (res && res.tokenId && _onNewSession) _onNewSession(res.tokenId); | ||
}); | ||
@@ -649,13 +649,26 @@ }; | ||
case 0: | ||
_context2.prev = 0; | ||
_context2.next = 3; | ||
if (!_this2.initialized) { | ||
_context2.next = 2; | ||
break; | ||
} | ||
return _context2.abrupt('return'); | ||
case 2: | ||
_context2.prev = 2; | ||
_this2.initialized = true; | ||
// Order Matters here. Ensure we successfully complete this fetchConversation request before connecting to | ||
// the websocket below! | ||
_context2.next = 6; | ||
return login(); | ||
case 3: | ||
case 6: | ||
onInit(); | ||
_context2.next = 6; | ||
_context2.next = 9; | ||
return getConversation(); | ||
case 6: | ||
case 9: | ||
_ref3 = _context2.sent; | ||
@@ -672,6 +685,6 @@ messages = _ref3.messages; | ||
disconnectSocket(); // Ensure we only have one websocket connection open | ||
_context2.next = 14; | ||
_context2.next = 17; | ||
return fetchWebsocketInfo(); | ||
case 14: | ||
case 17: | ||
wsInfo = _context2.sent; | ||
@@ -684,8 +697,8 @@ | ||
} | ||
_context2.next = 23; | ||
_context2.next = 26; | ||
break; | ||
case 19: | ||
_context2.prev = 19; | ||
_context2.t0 = _context2['catch'](0); | ||
case 22: | ||
_context2.prev = 22; | ||
_context2.t0 = _context2['catch'](2); | ||
@@ -698,3 +711,3 @@ disconnectSocket(); | ||
case 23: | ||
case 26: | ||
case 'end': | ||
@@ -704,3 +717,3 @@ return _context2.stop(); | ||
} | ||
}, _callee2, _this2, [[0, 19]]); | ||
}, _callee2, _this2, [[2, 22]]); | ||
})); | ||
@@ -710,2 +723,3 @@ | ||
disconnectSocket(); | ||
_this2.initialized = false; | ||
}; | ||
@@ -1017,2 +1031,3 @@ | ||
this.trackingId = null; | ||
this.initialized = false; | ||
@@ -1019,0 +1034,0 @@ setGlobals({ |
{ | ||
"name": "quiq-chat", | ||
"version": "1.8.3", | ||
"version": "1.8.4", | ||
"description": "Library to help with network requests to create a webchat client for Quiq Messaging", | ||
@@ -5,0 +5,0 @@ "main": "build/quiq-chat.js", |
@@ -47,3 +47,3 @@ // @flow | ||
const API = (ApiCalls: Object); | ||
let client: ?QuiqChatClient; | ||
let client: QuiqChatClient; | ||
const mockCookies = (cookies: any); | ||
@@ -71,2 +71,6 @@ | ||
describe('start', () => { | ||
it('sets initialized flag to "true"', () => { | ||
expect(client.initialized).toBe(true); | ||
}); | ||
it('calls login', () => { | ||
@@ -93,2 +97,42 @@ expect(API.login).toBeCalled(); | ||
describe('start with "initialized" set to true', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
client = new QuiqChatClient(host, contactPoint) | ||
.onNewMessages(onNewMessages) | ||
.onAgentTyping(onAgentTyping) | ||
.onError(onError) | ||
.onErrorResolved(onErrorResolved) | ||
.onConnectionStatusChange(onConnectionStatusChange) | ||
.onRegistration(onRegistration) | ||
.onNewSession(onNewSession) | ||
.onBurn(onBurn); | ||
client.initialized = true; | ||
client.start(); | ||
}); | ||
it('does not call login', () => { | ||
expect(API.login).not.toBeCalled(); | ||
}); | ||
it('does not call onNewMessages', () => { | ||
expect(onNewMessages).not.toBeCalled(); | ||
}); | ||
it('does not try to disconnect the websocket before making a new connection', () => { | ||
expect(disconnectSocket).not.toBeCalled(); | ||
}); | ||
it('does not connect the websocket', () => { | ||
expect(connectSocket).not.toBeCalled(); | ||
}); | ||
it('does not call onConnectionStatusChange', () => { | ||
expect(onConnectionStatusChange).not.toBeCalled(); | ||
}); | ||
}); | ||
describe('start with an error', () => { | ||
@@ -95,0 +139,0 @@ beforeEach(() => { |
@@ -83,3 +83,3 @@ // @flow | ||
).then(res => { | ||
if (_onNewSession) _onNewSession(res.tokenId); | ||
if (res && res.tokenId && _onNewSession) _onNewSession(res.tokenId); | ||
}); | ||
@@ -86,0 +86,0 @@ |
@@ -30,2 +30,3 @@ // @flow | ||
trackingId: ?string; | ||
initialized: boolean; | ||
@@ -41,2 +42,3 @@ constructor(host: string, contactPoint: string) { | ||
this.trackingId = null; | ||
this.initialized = false; | ||
@@ -118,3 +120,8 @@ setGlobals({ | ||
start = async (): Promise<?QuiqChatClient> => { | ||
// Avoid race conditions by only running start() once | ||
if (this.initialized) return; | ||
try { | ||
this.initialized = true; | ||
// Order Matters here. Ensure we successfully complete this fetchConversation request before connecting to | ||
@@ -151,2 +158,3 @@ // the websocket below! | ||
disconnectSocket(); | ||
this.initialized = false; | ||
}; | ||
@@ -153,0 +161,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
749020
8547