@qikdev/sdk 1.0.1 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +1 -1
  2. package/dist/access.html +16371 -0
  3. package/dist/api.html +1503 -0
  4. package/dist/auth.html +8455 -0
  5. package/dist/cache.html +1135 -0
  6. package/dist/content.html +10067 -0
  7. package/dist/files.html +3415 -0
  8. package/dist/filter.html +4973 -0
  9. package/dist/geo.html +3851 -0
  10. package/dist/global.html +328 -0
  11. package/dist/index.html +96 -0
  12. package/dist/main.js +1100 -1126
  13. package/dist/module-QikStorage-CookieStorageAdapter.html +1177 -0
  14. package/dist/module-QikStorage-LocalStorageAdapter.html +329 -0
  15. package/dist/module-QikStorage-StorageAdapter.html +3457 -0
  16. package/dist/module-QikStorage.html +1445 -0
  17. package/dist/qik.access.js.html +904 -0
  18. package/dist/qik.api.js.html +409 -0
  19. package/dist/{docs/qik.auth.js.html → qik.auth.js.html} +142 -104
  20. package/dist/qik.cache.js.html +125 -0
  21. package/dist/qik.content.js.html +967 -0
  22. package/dist/qik.core.js.html +322 -0
  23. package/dist/qik.files.js.html +249 -0
  24. package/dist/{docs/qik.filter.js.html → qik.filter.js.html} +2 -2
  25. package/dist/qik.geo.js.html +963 -0
  26. package/dist/qik.socket.js.html +451 -0
  27. package/dist/qik.storage.js.html +375 -0
  28. package/dist/qik.system.js.html +117 -0
  29. package/dist/qik.utils.js.html +1542 -0
  30. package/dist/socket.html +2975 -0
  31. package/dist/{docs/styles → styles}/jsdoc.css +2 -2
  32. package/dist/system.html +523 -0
  33. package/package.json +2 -2
  34. package/src/api/qik.access.js +2 -53
  35. package/src/api/qik.socket.js +51 -10
  36. package/src/version.js +1 -1
  37. package/dist/docs/access.html +0 -3826
  38. package/dist/docs/api.html +0 -1356
  39. package/dist/docs/auth.html +0 -2180
  40. package/dist/docs/cache.html +0 -351
  41. package/dist/docs/content.html +0 -2560
  42. package/dist/docs/files.html +0 -779
  43. package/dist/docs/filter.html +0 -1355
  44. package/dist/docs/index.html +0 -96
  45. package/dist/docs/qik.access.js.html +0 -790
  46. package/dist/docs/qik.api.js.html +0 -511
  47. package/dist/docs/qik.cache.js.html +0 -131
  48. package/dist/docs/qik.content.js.html +0 -918
  49. package/dist/docs/qik.core.js.html +0 -301
  50. package/dist/docs/qik.files.js.html +0 -219
  51. package/dist/docs/qik.socket.js.html +0 -416
  52. package/dist/docs/qik.system.js.html +0 -117
  53. package/dist/docs/qik.utils.js.html +0 -1467
  54. package/dist/docs/socket.html +0 -810
  55. package/dist/docs/system.html +0 -197
  56. /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.eot +0 -0
  57. /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.ttf +0 -0
  58. /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.woff +0 -0
  59. /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.woff2 +0 -0
  60. /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.eot +0 -0
  61. /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.ttf +0 -0
  62. /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.woff +0 -0
  63. /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.woff2 +0 -0
  64. /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  65. /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.svg +0 -0
  66. /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  67. /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  68. /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  69. /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  70. /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +0 -0
  71. /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  72. /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  73. /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  74. /package/dist/{docs/scripts → scripts}/collapse.js +0 -0
  75. /package/dist/{docs/scripts → scripts}/linenumber.js +0 -0
  76. /package/dist/{docs/scripts → scripts}/nav.js +0 -0
  77. /package/dist/{docs/scripts → scripts}/polyfill.js +0 -0
  78. /package/dist/{docs/scripts → scripts}/prettify/Apache-License-2.0.txt +0 -0
  79. /package/dist/{docs/scripts → scripts}/prettify/lang-css.js +0 -0
  80. /package/dist/{docs/scripts → scripts}/prettify/prettify.js +0 -0
  81. /package/dist/{docs/scripts → scripts}/search.js +0 -0
  82. /package/dist/{docs/styles → styles}/prettify.css +0 -0
@@ -0,0 +1,451 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+
5
+ <meta charset="utf-8">
6
+ <title>qik.socket.js - Documentation</title>
7
+
8
+
9
+ <script src="scripts/prettify/prettify.js"></script>
10
+ <script src="scripts/prettify/lang-css.js"></script>
11
+ <!--[if lt IE 9]>
12
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
13
+ <![endif]-->
14
+ <link type="text/css" rel="stylesheet" href="styles/prettify.css">
15
+ <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
16
+ <script src="scripts/nav.js" defer></script>
17
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
18
+ </head>
19
+ <body>
20
+
21
+ <input type="checkbox" id="nav-trigger" class="nav-trigger" />
22
+ <label for="nav-trigger" class="navicon-button x">
23
+ <div class="navicon"></div>
24
+ </label>
25
+
26
+ <label for="nav-trigger" class="overlay"></label>
27
+
28
+ <nav >
29
+
30
+ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="access.html">access</a><ul class='methods'><li data-type='method'><a href="access.html#.actionableScopes">actionableScopes</a></li><li data-type='method'><a href="access.html#.actionableScopes">actionableScopes</a></li><li data-type='method'><a href="access.html#.allPermissions">allPermissions</a></li><li data-type='method'><a href="access.html#.allPermissions">allPermissions</a></li><li data-type='method'><a href="access.html#.allPermissionTypes">allPermissionTypes</a></li><li data-type='method'><a href="access.html#.allPermissionTypes">allPermissionTypes</a></li><li data-type='method'><a href="access.html#.allUserScopes">allUserScopes</a></li><li data-type='method'><a href="access.html#.allUserScopes">allUserScopes</a></li><li data-type='method'><a href="access.html#.canCreate">canCreate</a></li><li data-type='method'><a href="access.html#.canCreate">canCreate</a></li><li data-type='method'><a href="access.html#.canDeleteItem">canDeleteItem</a></li><li data-type='method'><a href="access.html#.canDeleteItem">canDeleteItem</a></li><li data-type='method'><a href="access.html#.canEditItem">canEditItem</a></li><li data-type='method'><a href="access.html#.canEditItem">canEditItem</a></li><li data-type='method'><a href="access.html#.canEraseItem">canEraseItem</a></li><li data-type='method'><a href="access.html#.canEraseItem">canEraseItem</a></li><li data-type='method'><a href="access.html#.canKnowOf">canKnowOf</a></li><li data-type='method'><a href="access.html#.canKnowOf">canKnowOf</a></li><li data-type='method'><a href="access.html#.canListItem">canListItem</a></li><li data-type='method'><a href="access.html#.canListItem">canListItem</a></li><li data-type='method'><a href="access.html#.canRestoreItem">canRestoreItem</a></li><li data-type='method'><a href="access.html#.canRestoreItem">canRestoreItem</a></li><li data-type='method'><a href="access.html#.canViewItem">canViewItem</a></li><li data-type='method'><a href="access.html#.canViewItem">canViewItem</a></li><li data-type='method'><a href="access.html#.checkActionAccess">checkActionAccess</a></li><li data-type='method'><a href="access.html#.checkActionAccess">checkActionAccess</a></li><li data-type='method'><a href="access.html#.getAllDescendants">getAllDescendants</a></li><li data-type='method'><a href="access.html#.getAllDescendants">getAllDescendants</a></li><li data-type='method'><a href="access.html#.has">has</a></li><li data-type='method'><a href="access.html#.has">has</a></li><li data-type='method'><a href="access.html#.hasFeature">hasFeature</a></li><li data-type='method'><a href="access.html#.hasFeature">hasFeature</a></li><li data-type='method'><a href="access.html#.hashPermissions">hashPermissions</a></li><li data-type='method'><a href="access.html#.hashPermissions">hashPermissions</a></li><li data-type='method'><a href="access.html#.isAdministrator">isAdministrator</a></li><li data-type='method'><a href="access.html#.isAdministrator">isAdministrator</a></li><li data-type='method'><a href="access.html#.isAssignee">isAssignee</a></li><li data-type='method'><a href="access.html#.isAssignee">isAssignee</a></li><li data-type='method'><a href="access.html#.isOwner">isOwner</a></li><li data-type='method'><a href="access.html#.isOwner">isOwner</a></li></ul></li><li></li><li><a href="api.html">api</a><ul class='methods'><li data-type='method'><a href="api.html#.generateEndpointURL">generateEndpointURL</a></li><li data-type='method'><a href="api.html#.generateEndpointURL">generateEndpointURL</a></li></ul></li><li></li><li><a href="auth.html">auth</a><ul class='methods'><li data-type='method'><a href="auth.html#.changeOrganisation">changeOrganisation</a></li><li data-type='method'><a href="auth.html#.changeOrganisation">changeOrganisation</a></li><li data-type='method'><a href="auth.html#.ensureValidToken">ensureValidToken</a></li><li data-type='method'><a href="auth.html#.ensureValidToken">ensureValidToken</a></li><li data-type='method'><a href="auth.html#.getCurrentToken">getCurrentToken</a></li><li data-type='method'><a href="auth.html#.getCurrentToken">getCurrentToken</a></li><li data-type='method'><a href="auth.html#.getCurrentUser">getCurrentUser</a></li><li data-type='method'><a href="auth.html#.getCurrentUser">getCurrentUser</a></li><li data-type='method'><a href="auth.html#.impersonate">impersonate</a></li><li data-type='method'><a href="auth.html#.impersonate">impersonate</a></li><li data-type='method'><a href="auth.html#.login">login</a></li><li data-type='method'><a href="auth.html#.login">login</a></li><li data-type='method'><a href="auth.html#.logout">logout</a></li><li data-type='method'><a href="auth.html#.logout">logout</a></li><li data-type='method'><a href="auth.html#.retrieveUserFromResetToken">retrieveUserFromResetToken</a></li><li data-type='method'><a href="auth.html#.retrieveUserFromResetToken">retrieveUserFromResetToken</a></li><li data-type='method'><a href="auth.html#.sendResetPasswordRequest">sendResetPasswordRequest</a></li><li data-type='method'><a href="auth.html#.sendResetPasswordRequest">sendResetPasswordRequest</a></li><li data-type='method'><a href="auth.html#.set">set</a></li><li data-type='method'><a href="auth.html#.set">set</a></li><li data-type='method'><a href="auth.html#.sync">sync</a></li><li data-type='method'><a href="auth.html#.sync">sync</a></li><li data-type='method'><a href="auth.html#.updateUserWithToken">updateUserWithToken</a></li><li data-type='method'><a href="auth.html#.updateUserWithToken">updateUserWithToken</a></li></ul></li><li></li><li><a href="cache.html">cache</a><ul class='methods'><li data-type='method'><a href="cache.html#.get">get</a></li><li data-type='method'><a href="cache.html#.get">get</a></li><li data-type='method'><a href="cache.html#.reset">reset</a></li><li data-type='method'><a href="cache.html#.reset">reset</a></li></ul></li><li></li><li><a href="content.html">content</a><ul class='methods'><li data-type='method'><a href="content.html#.create">create</a></li><li data-type='method'><a href="content.html#.create">create</a></li><li data-type='method'><a href="content.html#.delete">delete</a></li><li data-type='method'><a href="content.html#.delete">delete</a></li><li data-type='method'><a href="content.html#.get">get</a></li><li data-type='method'><a href="content.html#.get">get</a></li><li data-type='method'><a href="content.html#.getFromSlug">getFromSlug</a></li><li data-type='method'><a href="content.html#.getFromSlug">getFromSlug</a></li><li data-type='method'><a href="content.html#.glossary">glossary</a></li><li data-type='method'><a href="content.html#.glossary">glossary</a></li><li data-type='method'><a href="content.html#.list">list</a></li><li data-type='method'><a href="content.html#.list">list</a></li><li data-type='method'><a href="content.html#.patch">patch</a></li><li data-type='method'><a href="content.html#.patch">patch</a></li><li data-type='method'><a href="content.html#.restore">restore</a></li><li data-type='method'><a href="content.html#.restore">restore</a></li><li data-type='method'><a href="content.html#.scopeGlossary">scopeGlossary</a></li><li data-type='method'><a href="content.html#.scopeGlossary">scopeGlossary</a></li><li data-type='method'><a href="content.html#.update">update</a></li><li data-type='method'><a href="content.html#.update">update</a></li><li data-type='method'><a href="content.html#.validateField">validateField</a></li><li data-type='method'><a href="content.html#.validateField">validateField</a></li><li data-type='method'><a href="content.html#.variables">variables</a></li><li data-type='method'><a href="content.html#.variables">variables</a></li></ul></li><li></li><li><a href="files.html">files</a><ul class='methods'><li data-type='method'><a href="files.html#.downloadUrl">downloadUrl</a></li><li data-type='method'><a href="files.html#.downloadUrl">downloadUrl</a></li><li data-type='method'><a href="files.html#.duration">duration</a></li><li data-type='method'><a href="files.html#.duration">duration</a></li><li data-type='method'><a href="files.html#.filesize">filesize</a></li><li data-type='method'><a href="files.html#.filesize">filesize</a></li><li data-type='method'><a href="files.html#.getBinaryTypeFromMime">getBinaryTypeFromMime</a></li><li data-type='method'><a href="files.html#.getBinaryTypeFromMime">getBinaryTypeFromMime</a></li><li data-type='method'><a href="files.html#.mediaUrl">mediaUrl</a></li><li data-type='method'><a href="files.html#.mediaUrl">mediaUrl</a></li></ul></li><li></li><li><a href="filter.html">filter</a><ul class='methods'><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterOperators">activeFilterOperators</a></li><li data-type='method'><a href="filter.html#.activeFilterOperators">activeFilterOperators</a></li><li data-type='method'><a href="filter.html#.activeFilters">activeFilters</a></li><li data-type='method'><a href="filter.html#.activeFilters">activeFilters</a></li><li data-type='method'><a href="filter.html#.activeFilterValues">activeFilterValues</a></li><li data-type='method'><a href="filter.html#.activeFilterValues">activeFilterValues</a></li><li data-type='method'><a href="filter.html#.filterChangeString">filterChangeString</a></li><li data-type='method'><a href="filter.html#.filterChangeString">filterChangeString</a></li><li data-type='method'><a href="filter.html#.isValidFilter">isValidFilter</a></li><li data-type='method'><a href="filter.html#.isValidFilter">isValidFilter</a></li></ul></li><li></li><li><a href="geo.html">geo</a><ul class='methods'><li data-type='method'><a href="geo.html#.distance">distance</a></li><li data-type='method'><a href="geo.html#.distance">distance</a></li><li data-type='method'><a href="geo.html#.getDefaultCountry">getDefaultCountry</a></li><li data-type='method'><a href="geo.html#.getDefaultCountry">getDefaultCountry</a></li><li data-type='method'><a href="geo.html#.getDefaultTimezone">getDefaultTimezone</a></li><li data-type='method'><a href="geo.html#.getDefaultTimezone">getDefaultTimezone</a></li><li data-type='method'><a href="geo.html#.getPosition">getPosition</a></li><li data-type='method'><a href="geo.html#.getPosition">getPosition</a></li><li data-type='method'><a href="geo.html#.stopWatchPosition">stopWatchPosition</a></li><li data-type='method'><a href="geo.html#.stopWatchPosition">stopWatchPosition</a></li><li data-type='method'><a href="geo.html#.stopWatchPosition">stopWatchPosition</a></li><li data-type='method'><a href="geo.html#.stopWatchPosition">stopWatchPosition</a></li></ul></li><li></li><li><a href="module-QikStorage-CookieStorageAdapter.html">CookieStorageAdapter</a><ul class='methods'><li data-type='method'><a href="module-QikStorage-CookieStorageAdapter.html#getCookieOptions">getCookieOptions</a></li><li data-type='method'><a href="module-QikStorage-CookieStorageAdapter.html#getCookieOptions">getCookieOptions</a></li><li data-type='method'><a href="module-QikStorage-CookieStorageAdapter.html#isCookieMode">isCookieMode</a></li><li data-type='method'><a href="module-QikStorage-CookieStorageAdapter.html#isCookieMode">isCookieMode</a></li></ul></li><li></li><li><a href="module-QikStorage-LocalStorageAdapter.html">LocalStorageAdapter</a></li><li></li><li><a href="module-QikStorage-StorageAdapter.html">StorageAdapter</a><ul class='methods'><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#clearUser">clearUser</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#clearUser">clearUser</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getAccessToken">getAccessToken</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getAccessToken">getAccessToken</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getRefreshToken">getRefreshToken</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getRefreshToken">getRefreshToken</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getTokenExpiry">getTokenExpiry</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getTokenExpiry">getTokenExpiry</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getUser">getUser</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getUser">getUser</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#isAvailable">isAvailable</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#isAvailable">isAvailable</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#setUser">setUser</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#setUser">setUser</a></li></ul></li><li></li><li><a href="socket.html">socket</a><ul class='methods'><li data-type='method'><a href="socket.html#.channel">channel</a></li><li data-type='method'><a href="socket.html#.channel">channel</a></li><li data-type='method'><a href="socket.html#.close">close</a></li><li data-type='method'><a href="socket.html#.close">close</a></li><li data-type='method'><a href="socket.html#.connect">connect</a></li><li data-type='method'><a href="socket.html#.connect">connect</a></li><li data-type='method'><a href="socket.html#.reconnect">reconnect</a></li><li data-type='method'><a href="socket.html#.reconnect">reconnect</a></li><li data-type='method'><a href="socket.html#.subscribe">subscribe</a></li><li data-type='method'><a href="socket.html#.subscribe">subscribe</a></li><li data-type='method'><a href="socket.html#.unsubscribe">unsubscribe</a></li><li data-type='method'><a href="socket.html#.unsubscribe">unsubscribe</a></li></ul></li><li></li><li><a href="system.html">system</a><ul class='methods'><li data-type='method'><a href="system.html#.countries">countries</a></li><li data-type='method'><a href="system.html#.countries">countries</a></li></ul></li><li></li></ul><h3>Modules</h3><ul><li><a href="module-QikStorage.html">QikStorage</a><ul class='methods'><li data-type='method'><a href="module-QikStorage.html#.createStorageAdapter">createStorageAdapter</a></li><li data-type='method'><a href="module-QikStorage.html#.createStorageAdapter">createStorageAdapter</a></li></ul></li><li></li></ul><h3>Global</h3><ul><li><a href="global.html#EventDispatcher">EventDispatcher</a></li></ul>
31
+ </nav>
32
+
33
+ <div id="main">
34
+
35
+ <h1 class="page-title">qik.socket.js</h1>
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+ <section>
44
+ <article>
45
+ <pre class="prettyprint source linenums"><code>import { EventDispatcher } from './qik.utils.js';
46
+
47
+ ///////////////////////////////////////////////////
48
+
49
+ /**
50
+ * Creates a new instance of QikSocket a module of the SDK
51
+ * that contains all helper functions to do with realtime sockets
52
+ * @name socket
53
+ * @constructor
54
+ * @hideconstructor
55
+ * @param {QikAPI} qik A reference to the parent instance of the QikCore module. This module is usually created by a QikCore instance that passes itself in as the first argument.
56
+ */
57
+
58
+ const QikSocket = function(qik, mode) {
59
+
60
+ mode = mode || 'production';
61
+
62
+ if (!qik.auth) {
63
+ throw new Error(`Can't Instantiate QikSocket before QikAuth exists`);
64
+ }
65
+
66
+
67
+ const windowID = qik.utils.guid();
68
+
69
+ ///////////////////////////////////////////////////
70
+
71
+ let service = {
72
+ debug: false,
73
+ url: `wss://iqtm6zjz3l.execute-api.ap-southeast-2.amazonaws.com/${mode}`,
74
+ connected: false,
75
+ windowID,
76
+ autoreconnect:true,
77
+ }
78
+
79
+ let socket;
80
+ let timer;
81
+ let buckets = {};
82
+ const channels = {};
83
+
84
+
85
+
86
+ //Create a new dispatcher
87
+ const dispatcher = new EventDispatcher();
88
+ dispatcher.bootstrap(service);
89
+
90
+ ///////////////////////////////////////////////////
91
+
92
+ function getSubscriptions() {
93
+ return Object.keys(buckets);
94
+ }
95
+
96
+ ///////////////////////////////////////////////////
97
+
98
+
99
+ /**
100
+ * @description Create an event dispatcher instance and subscribe to a new socket channel.
101
+ * This can then be used to receive socket events for this channel
102
+ * @alias socket.channel
103
+ * @param {String} key The key or name of the channel to subscribe to
104
+ * @example
105
+ * const socketChannel = await sdk.socket.channel('awesome:notifications')
106
+ * socketChannel.addEventListener('message', function(message) {
107
+ * console.log('Received a new message from the socket')
108
+ * })
109
+ *
110
+ * // Disconnect from this channel and remove all listeners
111
+ * socketChannel.destroy();
112
+ *
113
+ */
114
+ service.channel = async function(key) {
115
+ if (buckets[key]) {
116
+ return buckets[key];
117
+ }
118
+
119
+ const bucket = new EventDispatcher();
120
+ buckets[key] = bucket;
121
+
122
+ if (!service.connected) {
123
+ // Return the socket
124
+ await service.connect();
125
+ }
126
+
127
+ // Subscribe to this channel
128
+ service.subscribe(key);
129
+
130
+ // Listen for all relevant events
131
+ service.addEventListener(key, dispatchMessage);
132
+
133
+ function dispatchMessage(message) {
134
+ bucket.dispatch('message', message);
135
+ }
136
+
137
+ // Destroy this channel - stop receiving its events and tell the
138
+ // server to unsubscribe. Only touches this channel's own listeners,
139
+ // leaving every other channel (and connection-level listeners) intact.
140
+ bucket.destroy = function() {
141
+ service.removeEventListener(key, dispatchMessage);
142
+ service.unsubscribe(key);
143
+ bucket.removeAllListeners();
144
+ delete buckets[key];
145
+ }
146
+
147
+ return buckets[key];
148
+ }
149
+
150
+ ///////////////////////////////////////////////////
151
+
152
+ function ping() {
153
+ broadcast({
154
+ action: 'ping',
155
+ })
156
+ }
157
+
158
+ function startHeartbeat() {
159
+ if (timer) {
160
+ return;
161
+ }
162
+ timer = setInterval(ping, 10000);
163
+ }
164
+
165
+ function stopHeartbeat() {
166
+ if (!timer) {
167
+ return;
168
+ }
169
+
170
+ clearInterval(timer)
171
+ timer = null;
172
+ }
173
+
174
+ ///////////////////////////////////////////////////
175
+
176
+ function socketOpened(event) {
177
+ service.debug ? console.log("[socket] Connection open", event) : null;
178
+ service.connected = true;
179
+
180
+ dispatcher.dispatch('connected', event);
181
+
182
+ // startHeartbeat();
183
+ }
184
+
185
+ async function socketClosed(event) {
186
+ if (event.wasClean) {
187
+ service.debug ? console.log(`[socket] Connection closed cleanly, code=${event.code} reason=${event.reason}`) : null;
188
+ } else {
189
+ // e.g. server process killed or network down
190
+ // event.code is usually 1006 in this case
191
+ service.debug ? console.log('[socket] - connection closed due to error', event) : null
192
+ }
193
+
194
+ service.connected = false;
195
+ dispatcher.dispatch('disconnected', event);
196
+ socket = null;
197
+
198
+ if(service.autoreconnect) {
199
+ service.reconnect();
200
+ }
201
+ }
202
+
203
+ function socketError(error) {
204
+ console.log('[event] socketError', event);
205
+ service.debug ? console.log("[socket] Error", error) : null;
206
+ dispatcher.dispatch('error', error);
207
+ }
208
+
209
+ function socketMessageReceived(event) {
210
+ const eventData = JSON.parse(event.data);
211
+ service.debug ? console.log("[socket] message received", eventData) : null;
212
+
213
+ // Dispatch a generic message
214
+ dispatcher.dispatch('message', eventData);
215
+
216
+ if (eventData.channel) {
217
+ dispatcher.dispatch(eventData.channel, eventData);
218
+ }
219
+ }
220
+
221
+ async function broadcast(data) {
222
+ socket.send(JSON.stringify(data));
223
+ }
224
+
225
+ ///////////////////////////////////////////////////
226
+
227
+ function wait() {
228
+ return new Promise(function(resolve) {
229
+ function check() {
230
+ if (service.connected) {
231
+ return resolve(socket);
232
+ }
233
+
234
+ setTimeout(check, 1000);
235
+ }
236
+
237
+ check();
238
+ })
239
+ }
240
+
241
+ ///////////////////////////////////////////////////
242
+
243
+ /**
244
+ * @description Connect to the socket service
245
+ * @alias socket.connect
246
+ * @example
247
+ * const connected = await sdk.socket.connect()
248
+ *
249
+ */
250
+ service.connect = async function() {
251
+ if (socket) {
252
+
253
+ if (!socket.connected) {
254
+ return wait();
255
+ }
256
+
257
+ console.log('[socket] - Socket is already connected');
258
+ return socket;
259
+ }
260
+
261
+ const accessToken = qik.auth.getCurrentToken();
262
+
263
+ if (!accessToken) {
264
+ service.debug ? console.log('[socket] - Must be authenticated to connect to socket') : null;
265
+ return;
266
+ }
267
+
268
+ socket = new WebSocket(`${service.url}?access_token=${accessToken}&amp;windowid=${windowID}`);
269
+ socket.addEventListener('close', socketClosed);
270
+ socket.addEventListener('error', socketError);
271
+ socket.addEventListener('open', socketOpened);
272
+ socket.addEventListener('message', socketMessageReceived);
273
+ service.debug ? console.log('[socket] - Connected with event listeners') : null;
274
+
275
+ return wait();
276
+ }
277
+
278
+
279
+ /**
280
+ * @description Reconnect to the socket service
281
+ * @alias socket.reconnect
282
+ * @example
283
+ * const connected = await sdk.socket.reconnect()
284
+ *
285
+ */
286
+ service.reconnect = async function() {
287
+ if(service.connected) {
288
+ return;
289
+ }
290
+
291
+ service.debug ? console.log(`[socket] reconnecting...`) : null;
292
+
293
+ // Reconnect all listeners
294
+ const result = await service.connect();
295
+
296
+ // Resubscribe to all previously connected channels
297
+ const subscribedChannels = Object.keys(channels);
298
+ subscribedChannels.forEach(function(channel) {
299
+ service.subscribe(channel);
300
+ })
301
+
302
+ return result;
303
+ }
304
+
305
+
306
+ ///////////////////////////////////////////////////
307
+
308
+ /**
309
+ * @description Close the connection to the socket service
310
+ * @alias socket.close
311
+ * @example
312
+ * const closed = await sdk.socket.close()
313
+ *
314
+ */
315
+ service.close = async function() {
316
+ if (!socket) {
317
+ console.log('[socket] - Socket is not connected');
318
+ return;
319
+ }
320
+
321
+ const previousSetting = service.autoreconnect;
322
+ service.autoreconnect = false;
323
+ socket.close();
324
+ socket.removeEventListener('close', socketClosed);
325
+ socket.removeEventListener('error', socketError);
326
+ socket.removeEventListener('open', socketOpened);
327
+ socket.removeEventListener('message', socketMessageReceived);
328
+ socket = null;
329
+ socketClosed({ wasClean: true });
330
+ service.autoreconnect = previousSetting;
331
+ }
332
+
333
+ service.disconnect = service.close;
334
+
335
+ ///////////////////////////////////////////////////
336
+
337
+ /**
338
+ * @description Subscribe to a socket channel
339
+ * @alias socket.subscribe
340
+ * @param {String} key The name of the channel to subscribe to
341
+ * @example
342
+ * const subscribed = await sdk.socket.subscribe('some:cool:alert')
343
+ *
344
+ */
345
+ service.subscribe = async function(channel) {
346
+ if (!socket) {
347
+ console.log(`[socket] - Can't subscribe to channel as socket is not connected`);
348
+ return;
349
+ }
350
+
351
+ broadcast({
352
+ action: 'subscribe',
353
+ channel,
354
+ })
355
+
356
+ channels[channel] = true;
357
+
358
+ dispatcher.dispatch('subscribe', channel)
359
+ service.debug ? console.log(`[socket] - subscribed to ${channel}`) : null;
360
+ }
361
+
362
+ ///////////////////////////////////////////////////
363
+
364
+ /**
365
+ * @description Unsubscribe from a socket channel
366
+ * @alias socket.unsubscribe
367
+ * @param {String} key The name of the channel to unsubscribe from
368
+ * @example
369
+ * const unsubscribed = await sdk.socket.unsubscribe('some:cool:alert')
370
+ *
371
+ */
372
+ service.unsubscribe = async function(channel) {
373
+ if (!socket) {
374
+ console.log(`[socket] - Can't unsubscribe from channel as socket is not connected`);
375
+ return;
376
+ }
377
+
378
+ broadcast({
379
+ action: 'unsubscribe',
380
+ channel,
381
+ })
382
+
383
+ delete channels[channel];
384
+
385
+ dispatcher.dispatch('unsubscribe', channel)
386
+ service.debug ? console.log(`[socket] - unsubscribed from ${channel}`) : null;
387
+ }
388
+
389
+ ///////////////////////////////////////////////////
390
+
391
+ // Reconnect the socket whenever the authenticated organisation changes.
392
+ // The WebSocket authenticates with an access token at connect time, so the
393
+ // connection stays bound to whichever organisation was active when it
394
+ // opened. Switching organisations issues a new token but leaves the socket
395
+ // untouched, so without this it keeps streaming the previous
396
+ // organisation's events. Reconnecting re-authenticates with the new token.
397
+ let currentOrganisationID = qik.utils.id(qik.auth.getCurrentUser()?.organisation);
398
+
399
+ qik.auth.addEventListener('change', async function(user) {
400
+ const organisationID = qik.utils.id(user?.organisation);
401
+
402
+ // Ignore auth changes that don't change the organisation (e.g. routine
403
+ // access token refreshes) so we don't churn the connection needlessly.
404
+ if (organisationID === currentOrganisationID) {
405
+ return;
406
+ }
407
+
408
+ currentOrganisationID = organisationID;
409
+
410
+ // Nothing to reconnect if the socket was never opened.
411
+ if (!socket) {
412
+ return;
413
+ }
414
+
415
+ service.debug ? console.log('[socket] - organisation changed, reconnecting') : null;
416
+ await service.close();
417
+ await service.reconnect();
418
+ });
419
+
420
+ ///////////////////////////////////////////////////
421
+
422
+ return service;
423
+
424
+ }
425
+
426
+
427
+ export default QikSocket;</code></pre>
428
+ </article>
429
+ </section>
430
+
431
+
432
+
433
+
434
+
435
+
436
+ </div>
437
+
438
+ <br class="clear">
439
+
440
+ <footer>
441
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Mon Jun 01 2026 23:37:17 GMT+1000 (Australian Eastern Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
442
+ </footer>
443
+
444
+ <script>prettyPrint();</script>
445
+ <script src="scripts/polyfill.js"></script>
446
+ <script src="scripts/linenumber.js"></script>
447
+
448
+
449
+
450
+ </body>
451
+ </html>