quiq-chat
Advanced tools
Comparing version 1.15.0 to 1.15.2
@@ -167,3 +167,3 @@ 'use strict'; | ||
var setQuiqUserTakenMeaningfulAction = function setQuiqUserTakenMeaningfulAction(visible) { | ||
store.set('quiq-user-taken-meaningful-action', visible, expireInDays(1)); | ||
store.set('quiq-user-taken-meaningful-action', visible, expireInMinutes(30)); | ||
}; | ||
@@ -210,3 +210,3 @@ var setAccessToken = function setAccessToken(token) { | ||
var version = "1.15.0"; | ||
var version = "1.15.2"; | ||
@@ -1065,6 +1065,2 @@ function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
// Start calling the keepAlive endpoint | ||
// TODO: Check this back in when we're ready | ||
// startHeartbeat(); | ||
if (_onNewSession) { | ||
@@ -1084,6 +1080,2 @@ _onNewSession(res.tokenId); | ||
// TODO: Check this back in with the heartbeat stuff | ||
// .then(stopHeartbeat); | ||
var init = function init() { | ||
@@ -1265,3 +1257,3 @@ if (!inLocalDevelopment()) Raven.config('https://5622397f17c44165a039d3b91d3e0193@sentry.io/170102', { | ||
if (!(_this2.textMessages.length > 0)) { | ||
if (!(getQuiqUserTakenMeaningfulAction() && _this2.textMessages.length > 0)) { | ||
_context2.next = 18; | ||
@@ -1347,7 +1339,27 @@ break; | ||
this.joinChat = function () { | ||
setQuiqChatContainerVisible(true); | ||
return joinChat(); | ||
}; | ||
this.joinChat = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() { | ||
return regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
_context4.next = 2; | ||
return _this2.getMessages(); | ||
case 2: | ||
if (_this2._hasUserJoinedConversation()) { | ||
_context4.next = 5; | ||
break; | ||
} | ||
setQuiqChatContainerVisible(true); | ||
return _context4.abrupt('return', joinChat()); | ||
case 5: | ||
case 'end': | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee4, _this2); | ||
})); | ||
this.leaveChat = function () { | ||
@@ -1359,7 +1371,7 @@ setQuiqChatContainerVisible(false); | ||
this.sendMessage = function () { | ||
var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(text) { | ||
var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(text) { | ||
var oldTrackingId; | ||
return regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
return regeneratorRuntime.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
@@ -1369,7 +1381,7 @@ oldTrackingId = _this2.trackingId; | ||
if (_this2.connected) { | ||
_context4.next = 4; | ||
_context5.next = 4; | ||
break; | ||
} | ||
_context4.next = 4; | ||
_context5.next = 4; | ||
return _this2._establishWebSocketConnection(); | ||
@@ -1379,3 +1391,3 @@ | ||
if (!(oldTrackingId === _this2.trackingId)) { | ||
_context4.next = 9; | ||
_context5.next = 9; | ||
break; | ||
@@ -1388,14 +1400,14 @@ } | ||
return _context4.abrupt('return', addMessage(text)); | ||
return _context5.abrupt('return', addMessage(text)); | ||
case 9: | ||
case 'end': | ||
return _context4.stop(); | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee4, _this2); | ||
}, _callee5, _this2); | ||
})); | ||
return function (_x2) { | ||
return _ref6.apply(this, arguments); | ||
return _ref7.apply(this, arguments); | ||
}; | ||
@@ -1409,7 +1421,7 @@ }(); | ||
this.sendRegistration = function () { | ||
var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(fields) { | ||
var _ref8 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(fields) { | ||
var result; | ||
return regeneratorRuntime.wrap(function _callee5$(_context5) { | ||
return regeneratorRuntime.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
@@ -1419,7 +1431,7 @@ _this2._setTimeUntilInactive(MINUTES_UNTIL_INACTIVE); | ||
setQuiqUserTakenMeaningfulAction(true); | ||
_context5.next = 5; | ||
_context6.next = 5; | ||
return sendRegistration(fields); | ||
case 5: | ||
result = _context5.sent; | ||
result = _context6.sent; | ||
@@ -1431,14 +1443,14 @@ | ||
return _context5.abrupt('return', result); | ||
return _context6.abrupt('return', result); | ||
case 8: | ||
case 'end': | ||
return _context5.stop(); | ||
return _context6.stop(); | ||
} | ||
} | ||
}, _callee5, _this2); | ||
}, _callee6, _this2); | ||
})); | ||
return function (_x3) { | ||
return _ref7.apply(this, arguments); | ||
return _ref8.apply(this, arguments); | ||
}; | ||
@@ -1467,14 +1479,26 @@ }(); | ||
this._establishWebSocketConnection = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() { | ||
this._hasUserJoinedConversation = function () { | ||
if (!_this2.events) { | ||
return false; | ||
} | ||
var joinOrLeaveEvents = _this2.events.filter(function (e) { | ||
return [MessageTypes.JOIN, MessageTypes.LEAVE].includes(e.type); | ||
}); | ||
return joinOrLeaveEvents.length > 0 && joinOrLeaveEvents[joinOrLeaveEvents.length - 1].type === MessageTypes.JOIN; | ||
}; | ||
this._establishWebSocketConnection = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() { | ||
var wsInfo; | ||
return regeneratorRuntime.wrap(function _callee6$(_context6) { | ||
return regeneratorRuntime.wrap(function _callee7$(_context7) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
switch (_context7.prev = _context7.next) { | ||
case 0: | ||
_this2._disconnectSocket(); // Ensure we only have one websocket connection open | ||
_context6.next = 3; | ||
_context7.next = 3; | ||
return fetchWebsocketInfo(); | ||
case 3: | ||
wsInfo = _context6.sent; | ||
wsInfo = _context7.sent; | ||
@@ -1485,6 +1509,6 @@ _this2._connectSocket(wsInfo); | ||
case 'end': | ||
return _context6.stop(); | ||
return _context7.stop(); | ||
} | ||
} | ||
}, _callee6, _this2); | ||
}, _callee7, _this2); | ||
})); | ||
@@ -1527,9 +1551,9 @@ | ||
this._handleNewSession = function () { | ||
var _ref9 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(newTrackingId) { | ||
return regeneratorRuntime.wrap(function _callee7$(_context7) { | ||
var _ref10 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8(newTrackingId) { | ||
return regeneratorRuntime.wrap(function _callee8$(_context8) { | ||
while (1) { | ||
switch (_context7.prev = _context7.next) { | ||
switch (_context8.prev = _context8.next) { | ||
case 0: | ||
if (!(_this2.trackingId && newTrackingId !== _this2.trackingId)) { | ||
_context7.next = 7; | ||
_context8.next = 7; | ||
break; | ||
@@ -1549,3 +1573,3 @@ } | ||
// (Connection establishment handler will refresh messages) | ||
_context7.next = 7; | ||
_context8.next = 7; | ||
return _this2._establishWebSocketConnection(); | ||
@@ -1559,10 +1583,10 @@ | ||
case 'end': | ||
return _context7.stop(); | ||
return _context8.stop(); | ||
} | ||
} | ||
}, _callee7, _this2); | ||
}, _callee8, _this2); | ||
})); | ||
return function (_x4) { | ||
return _ref9.apply(this, arguments); | ||
return _ref10.apply(this, arguments); | ||
}; | ||
@@ -1611,16 +1635,16 @@ }(); | ||
this._handleConnectionEstablish = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() { | ||
var _ref11, messages, events; | ||
this._handleConnectionEstablish = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9() { | ||
var _ref12, messages, events; | ||
return regeneratorRuntime.wrap(function _callee8$(_context8) { | ||
return regeneratorRuntime.wrap(function _callee9$(_context9) { | ||
while (1) { | ||
switch (_context8.prev = _context8.next) { | ||
switch (_context9.prev = _context9.next) { | ||
case 0: | ||
_context8.next = 2; | ||
_context9.next = 2; | ||
return getConversation(); | ||
case 2: | ||
_ref11 = _context8.sent; | ||
messages = _ref11.messages; | ||
events = _ref11.events; | ||
_ref12 = _context9.sent; | ||
messages = _ref12.messages; | ||
events = _ref12.events; | ||
@@ -1638,6 +1662,6 @@ | ||
case 'end': | ||
return _context8.stop(); | ||
return _context9.stop(); | ||
} | ||
} | ||
}, _callee8, _this2); | ||
}, _callee9, _this2); | ||
})); | ||
@@ -1681,10 +1705,10 @@ | ||
clearTimeout(_this2.clientInactiveTimer); | ||
_this2.clientInactiveTimer = setTimeout(_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9() { | ||
return regeneratorRuntime.wrap(function _callee9$(_context9) { | ||
_this2.clientInactiveTimer = setTimeout(_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() { | ||
return regeneratorRuntime.wrap(function _callee10$(_context10) { | ||
while (1) { | ||
switch (_context9.prev = _context9.next) { | ||
switch (_context10.prev = _context10.next) { | ||
case 0: | ||
// Leaving a console log in to give context to the atmosphere console message 'Websocket closed normally' | ||
log$1.info('Client timeout due to inactivity. Closing websocket.'); | ||
_context9.next = 3; | ||
_context10.next = 3; | ||
return _this2.leaveChat(); | ||
@@ -1701,6 +1725,6 @@ | ||
case 'end': | ||
return _context9.stop(); | ||
return _context10.stop(); | ||
} | ||
} | ||
}, _callee9, _this2); | ||
}, _callee10, _this2); | ||
})), minutes * 60 * 1000 + 1000 // add a second to avoid timing issues | ||
@@ -1707,0 +1731,0 @@ ); |
{ | ||
"name": "quiq-chat", | ||
"version": "1.15.0", | ||
"description": "Library to help with network requests to create a webchat client for Quiq Messaging", | ||
"version": "1.15.2", | ||
"description": | ||
"Library to help with network requests to create a webchat client for Quiq Messaging", | ||
"main": "build/quiq-chat.js", | ||
@@ -10,3 +11,4 @@ "repository": "https://github.com/Quiq/quiq-chat", | ||
"lint": "node ./node_modules/eslint/bin/eslint.js src/", | ||
"test": "flow && jest --env=jsdom --coverage && node ./node_modules/eslint/bin/eslint.js src/ --quiet", | ||
"test": | ||
"flow && jest --env=jsdom --coverage && node ./node_modules/eslint/bin/eslint.js src/ --quiet", | ||
"flow": "flow", | ||
@@ -22,19 +24,13 @@ "jest": "jest --watch --env=jsdom", | ||
"jest": { | ||
"modulePaths": [ | ||
"src", | ||
"node_modules" | ||
], | ||
"modulePaths": ["src", "node_modules"], | ||
"rootDir": ".", | ||
"setupFiles": [ | ||
"./jest.setup.js" | ||
], | ||
"setupFiles": ["./jest.setup.js"], | ||
"notify": true | ||
}, | ||
"keywords": [ | ||
"quiq" | ||
], | ||
"keywords": ["quiq"], | ||
"author": "nate.norberg@goquiq.com", | ||
"license": "MIT", | ||
"dependencies": { | ||
"atmosphere.js": "https://github.com/Quiq/atmosphere-js/tarball/cf35c913143cf2c391b6bcb694ae8a47794a1b88", | ||
"atmosphere.js": | ||
"https://github.com/Quiq/atmosphere-js/tarball/cf35c913143cf2c391b6bcb694ae8a47794a1b88", | ||
"isomorphic-fetch": "2.2.1", | ||
@@ -41,0 +37,0 @@ "lodash": "4.17.4", |
@@ -26,17 +26,2 @@ // @flow | ||
let keepAliveInterval: number; | ||
// eslint-disable-next-line no-unused-vars | ||
const startHeartbeat = () => { | ||
clearInterval(keepAliveInterval); | ||
keepAlive(); | ||
keepAliveInterval = setInterval(keepAlive, 60 * 1000); | ||
}; | ||
// eslint-disable-next-line no-unused-vars | ||
const stopHeartbeat = () => { | ||
clearInterval(keepAliveInterval); | ||
}; | ||
export const joinChat = () => quiqFetch(`${getUrlForContactPoint()}/join`, {method: 'POST'}); | ||
@@ -106,6 +91,2 @@ | ||
// Start calling the keepAlive endpoint | ||
// TODO: Check this back in when we're ready | ||
// startHeartbeat(); | ||
if (_onNewSession) { | ||
@@ -125,3 +106,1 @@ _onNewSession(res.tokenId); | ||
export const logout = () => quiqFetch(getSessionApiUrl(), {method: 'DELETE'}); | ||
// TODO: Check this back in with the heartbeat stuff | ||
// .then(stopHeartbeat); |
@@ -146,3 +146,3 @@ // @flow | ||
if (this.textMessages.length > 0) { | ||
if (storage.getQuiqUserTakenMeaningfulAction() && this.textMessages.length > 0) { | ||
await this._establishWebSocketConnection(); | ||
@@ -179,6 +179,12 @@ } | ||
/** API wrappers: these return Promises around the API response * */ | ||
joinChat = async () => { | ||
await this.getMessages(); | ||
joinChat = () => { | ||
storage.setQuiqChatContainerVisible(true); | ||
return API.joinChat(); | ||
// These events are going to be managed entirely by the server in the near future. | ||
// For now, we have this logic in place to prevent multiple join events from showing | ||
// up on page turns. | ||
if (!this._hasUserJoinedConversation()) { | ||
storage.setQuiqChatContainerVisible(true); | ||
return API.joinChat(); | ||
} | ||
}; | ||
@@ -235,2 +241,17 @@ | ||
_hasUserJoinedConversation = (): boolean => { | ||
if (!this.events) { | ||
return false; | ||
} | ||
const joinOrLeaveEvents = this.events.filter(e => | ||
[MessageTypes.JOIN, MessageTypes.LEAVE].includes(e.type), | ||
); | ||
return ( | ||
joinOrLeaveEvents.length > 0 && | ||
joinOrLeaveEvents[joinOrLeaveEvents.length - 1].type === MessageTypes.JOIN | ||
); | ||
}; | ||
/** Private Members * */ | ||
@@ -237,0 +258,0 @@ _establishWebSocketConnection = async () => { |
@@ -35,3 +35,3 @@ // @flow | ||
export const setQuiqUserTakenMeaningfulAction = (visible: boolean) => { | ||
store.set('quiq-user-taken-meaningful-action', visible, expireInDays(1)); | ||
store.set('quiq-user-taken-meaningful-action', visible, expireInMinutes(30)); | ||
}; | ||
@@ -38,0 +38,0 @@ export const setAccessToken = (token: string) => { |
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
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
1294160
6013