@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.
- package/README.md +1 -1
- package/dist/access.html +16371 -0
- package/dist/api.html +1503 -0
- package/dist/auth.html +8455 -0
- package/dist/cache.html +1135 -0
- package/dist/content.html +10067 -0
- package/dist/files.html +3415 -0
- package/dist/filter.html +4973 -0
- package/dist/geo.html +3851 -0
- package/dist/global.html +328 -0
- package/dist/index.html +96 -0
- package/dist/main.js +1100 -1126
- package/dist/module-QikStorage-CookieStorageAdapter.html +1177 -0
- package/dist/module-QikStorage-LocalStorageAdapter.html +329 -0
- package/dist/module-QikStorage-StorageAdapter.html +3457 -0
- package/dist/module-QikStorage.html +1445 -0
- package/dist/qik.access.js.html +904 -0
- package/dist/qik.api.js.html +409 -0
- package/dist/{docs/qik.auth.js.html → qik.auth.js.html} +142 -104
- package/dist/qik.cache.js.html +125 -0
- package/dist/qik.content.js.html +967 -0
- package/dist/qik.core.js.html +322 -0
- package/dist/qik.files.js.html +249 -0
- package/dist/{docs/qik.filter.js.html → qik.filter.js.html} +2 -2
- package/dist/qik.geo.js.html +963 -0
- package/dist/qik.socket.js.html +451 -0
- package/dist/qik.storage.js.html +375 -0
- package/dist/qik.system.js.html +117 -0
- package/dist/qik.utils.js.html +1542 -0
- package/dist/socket.html +2975 -0
- package/dist/{docs/styles → styles}/jsdoc.css +2 -2
- package/dist/system.html +523 -0
- package/package.json +2 -2
- package/src/api/qik.access.js +2 -53
- package/src/api/qik.socket.js +51 -10
- package/src/version.js +1 -1
- package/dist/docs/access.html +0 -3826
- package/dist/docs/api.html +0 -1356
- package/dist/docs/auth.html +0 -2180
- package/dist/docs/cache.html +0 -351
- package/dist/docs/content.html +0 -2560
- package/dist/docs/files.html +0 -779
- package/dist/docs/filter.html +0 -1355
- package/dist/docs/index.html +0 -96
- package/dist/docs/qik.access.js.html +0 -790
- package/dist/docs/qik.api.js.html +0 -511
- package/dist/docs/qik.cache.js.html +0 -131
- package/dist/docs/qik.content.js.html +0 -918
- package/dist/docs/qik.core.js.html +0 -301
- package/dist/docs/qik.files.js.html +0 -219
- package/dist/docs/qik.socket.js.html +0 -416
- package/dist/docs/qik.system.js.html +0 -117
- package/dist/docs/qik.utils.js.html +0 -1467
- package/dist/docs/socket.html +0 -810
- package/dist/docs/system.html +0 -197
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.woff2 +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.woff2 +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.svg +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- /package/dist/{docs/scripts → scripts}/collapse.js +0 -0
- /package/dist/{docs/scripts → scripts}/linenumber.js +0 -0
- /package/dist/{docs/scripts → scripts}/nav.js +0 -0
- /package/dist/{docs/scripts → scripts}/polyfill.js +0 -0
- /package/dist/{docs/scripts → scripts}/prettify/Apache-License-2.0.txt +0 -0
- /package/dist/{docs/scripts → scripts}/prettify/lang-css.js +0 -0
- /package/dist/{docs/scripts → scripts}/prettify/prettify.js +0 -0
- /package/dist/{docs/scripts → scripts}/search.js +0 -0
- /package/dist/{docs/styles → styles}/prettify.css +0 -0
|
@@ -1,416 +0,0 @@
|
|
|
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#.allPermissions">allPermissions</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#.canCreate">canCreate</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#.canEraseItem">canEraseItem</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#.canRestoreItem">canRestoreItem</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#.getAllDescendants">getAllDescendants</a></li><li data-type='method'><a href="access.html#.has">has</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#.isOwner">isOwner</a></li></ul></li><li><a href="api.html">api</a><ul class='methods'><li data-type='method'><a href="api.html#.delete">delete</a></li><li data-type='method'><a href="api.html#.generateEndpointURL">generateEndpointURL</a></li><li data-type='method'><a href="api.html#.get">get</a></li><li data-type='method'><a href="api.html#.patch">patch</a></li><li data-type='method'><a href="api.html#.post">post</a></li><li data-type='method'><a href="api.html#.put">put</a></li></ul></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#.ensureValidToken">ensureValidToken</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#.impersonate">impersonate</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#.retrieveUserFromResetToken">retrieveUserFromResetToken</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#.sync">sync</a></li><li data-type='method'><a href="auth.html#.updateUserWithToken">updateUserWithToken</a></li></ul></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#.reset">reset</a></li></ul></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#.delete">delete</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#.glossary">glossary</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#.restore">restore</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#.validateField">validateField</a></li><li data-type='method'><a href="content.html#.variables">variables</a></li></ul></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#.filesize">filesize</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></ul></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#.activeFilterOperators">activeFilterOperators</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#.filterChangeString">filterChangeString</a></li><li data-type='method'><a href="filter.html#.isValidFilter">isValidFilter</a></li></ul></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#.close">close</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#.subscribe">subscribe</a></li><li data-type='method'><a href="socket.html#.unsubscribe">unsubscribe</a></li></ul></li><li><a href="system.html">system</a><ul class='methods'><li data-type='method'><a href="system.html#.countries">countries</a></li></ul></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 the service
|
|
138
|
-
bucket.destroy = function() {
|
|
139
|
-
service.removeAllListeners();
|
|
140
|
-
buckets[key] = null;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return buckets[key];
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
///////////////////////////////////////////////////
|
|
147
|
-
|
|
148
|
-
function ping() {
|
|
149
|
-
broadcast({
|
|
150
|
-
action: 'ping',
|
|
151
|
-
})
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function startHeartbeat() {
|
|
155
|
-
if (timer) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
timer = setInterval(ping, 10000);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function stopHeartbeat() {
|
|
162
|
-
if (!timer) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
clearInterval(timer)
|
|
167
|
-
timer = null;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
///////////////////////////////////////////////////
|
|
171
|
-
|
|
172
|
-
function socketOpened(event) {
|
|
173
|
-
service.debug ? console.log("[socket] Connection open", event) : null;
|
|
174
|
-
service.connected = true;
|
|
175
|
-
|
|
176
|
-
dispatcher.dispatch('connected', event);
|
|
177
|
-
|
|
178
|
-
// startHeartbeat();
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
async function socketClosed(event) {
|
|
182
|
-
if (event.wasClean) {
|
|
183
|
-
service.debug ? console.log(`[socket] Connection closed cleanly, code=${event.code} reason=${event.reason}`) : null;
|
|
184
|
-
} else {
|
|
185
|
-
// e.g. server process killed or network down
|
|
186
|
-
// event.code is usually 1006 in this case
|
|
187
|
-
service.debug ? console.log('[socket] - connection closed due to error', event) : null
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
service.connected = false;
|
|
191
|
-
dispatcher.dispatch('disconnected', event);
|
|
192
|
-
socket = null;
|
|
193
|
-
|
|
194
|
-
if(service.autoreconnect) {
|
|
195
|
-
service.reconnect();
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function socketError(error) {
|
|
200
|
-
console.log('[event] socketError', event);
|
|
201
|
-
service.debug ? console.log("[socket] Error", error) : null;
|
|
202
|
-
dispatcher.dispatch('error', error);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function socketMessageReceived(event) {
|
|
206
|
-
const eventData = JSON.parse(event.data);
|
|
207
|
-
service.debug ? console.log("[socket] message received", eventData) : null;
|
|
208
|
-
|
|
209
|
-
// Dispatch a generic message
|
|
210
|
-
dispatcher.dispatch('message', eventData);
|
|
211
|
-
|
|
212
|
-
if (eventData.channel) {
|
|
213
|
-
dispatcher.dispatch(eventData.channel, eventData);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
async function broadcast(data) {
|
|
218
|
-
socket.send(JSON.stringify(data));
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
///////////////////////////////////////////////////
|
|
222
|
-
|
|
223
|
-
function wait() {
|
|
224
|
-
return new Promise(function(resolve) {
|
|
225
|
-
function check() {
|
|
226
|
-
if (service.connected) {
|
|
227
|
-
return resolve(socket);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
setTimeout(check, 1000);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
check();
|
|
234
|
-
})
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
///////////////////////////////////////////////////
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* @description Connect to the socket service
|
|
241
|
-
* @alias socket.connect
|
|
242
|
-
* @example
|
|
243
|
-
* const connected = await sdk.socket.connect()
|
|
244
|
-
*
|
|
245
|
-
*/
|
|
246
|
-
service.connect = async function() {
|
|
247
|
-
if (socket) {
|
|
248
|
-
|
|
249
|
-
if (!socket.connected) {
|
|
250
|
-
return wait();
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
console.log('[socket] - Socket is already connected');
|
|
254
|
-
return socket;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const accessToken = qik.auth.getCurrentToken();
|
|
258
|
-
|
|
259
|
-
if (!accessToken) {
|
|
260
|
-
service.debug ? console.log('[socket] - Must be authenticated to connect to socket') : null;
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
socket = new WebSocket(`${service.url}?access_token=${accessToken}&windowid=${windowID}`);
|
|
265
|
-
socket.addEventListener('close', socketClosed);
|
|
266
|
-
socket.addEventListener('error', socketError);
|
|
267
|
-
socket.addEventListener('open', socketOpened);
|
|
268
|
-
socket.addEventListener('message', socketMessageReceived);
|
|
269
|
-
service.debug ? console.log('[socket] - Connected with event listeners') : null;
|
|
270
|
-
|
|
271
|
-
return wait();
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* @description Reconnect to the socket service
|
|
277
|
-
* @alias socket.reconnect
|
|
278
|
-
* @example
|
|
279
|
-
* const connected = await sdk.socket.reconnect()
|
|
280
|
-
*
|
|
281
|
-
*/
|
|
282
|
-
service.reconnect = async function() {
|
|
283
|
-
if(service.connected) {
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
service.debug ? console.log(`[socket] reconnecting...`) : null;
|
|
288
|
-
|
|
289
|
-
// Reconnect all listeners
|
|
290
|
-
const result = await service.connect();
|
|
291
|
-
|
|
292
|
-
// Resubscribe to all previously connected channels
|
|
293
|
-
const subscribedChannels = Object.keys(channels);
|
|
294
|
-
subscribedChannels.forEach(function(channel) {
|
|
295
|
-
service.subscribe(channel);
|
|
296
|
-
})
|
|
297
|
-
|
|
298
|
-
return result;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
///////////////////////////////////////////////////
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* @description Close the connection to the socket service
|
|
306
|
-
* @alias socket.close
|
|
307
|
-
* @example
|
|
308
|
-
* const closed = await sdk.socket.close()
|
|
309
|
-
*
|
|
310
|
-
*/
|
|
311
|
-
service.close = async function() {
|
|
312
|
-
if (!socket) {
|
|
313
|
-
console.log('[socket] - Socket is not connected');
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
const previousSetting = service.autoreconnect;
|
|
318
|
-
service.autoreconnect = false;
|
|
319
|
-
socket.close();
|
|
320
|
-
socket.removeEventListener('close', socketClosed);
|
|
321
|
-
socket.removeEventListener('error', socketError);
|
|
322
|
-
socket.removeEventListener('open', socketOpened);
|
|
323
|
-
socket.removeEventListener('message', socketMessageReceived);
|
|
324
|
-
socket = null;
|
|
325
|
-
socketClosed({ wasClean: true });
|
|
326
|
-
service.autoreconnect = previousSetting;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
service.disconnect = service.close;
|
|
330
|
-
|
|
331
|
-
///////////////////////////////////////////////////
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* @description Subscribe to a socket channel
|
|
335
|
-
* @alias socket.subscribe
|
|
336
|
-
* @param {String} key The name of the channel to subscribe to
|
|
337
|
-
* @example
|
|
338
|
-
* const subscribed = await sdk.socket.subscribe('some:cool:alert')
|
|
339
|
-
*
|
|
340
|
-
*/
|
|
341
|
-
service.subscribe = async function(channel) {
|
|
342
|
-
if (!socket) {
|
|
343
|
-
console.log(`[socket] - Can't subscribe to channel as socket is not connected`);
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
broadcast({
|
|
348
|
-
action: 'subscribe',
|
|
349
|
-
channel,
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
channels[channel] = true;
|
|
353
|
-
|
|
354
|
-
dispatcher.dispatch('subscribe', channel)
|
|
355
|
-
service.debug ? console.log(`[socket] - subscribed to ${channel}`) : null;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
///////////////////////////////////////////////////
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* @description Unsubscribe from a socket channel
|
|
362
|
-
* @alias socket.unsubscribe
|
|
363
|
-
* @param {String} key The name of the channel to unsubscribe from
|
|
364
|
-
* @example
|
|
365
|
-
* const unsubscribed = await sdk.socket.unsubscribe('some:cool:alert')
|
|
366
|
-
*
|
|
367
|
-
*/
|
|
368
|
-
service.unsubscribe = async function(channel) {
|
|
369
|
-
if (!socket) {
|
|
370
|
-
console.log(`[socket] - Can't unsubscribe from channel as socket is not connected`);
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
broadcast({
|
|
375
|
-
action: 'unsubscribe',
|
|
376
|
-
channel,
|
|
377
|
-
})
|
|
378
|
-
|
|
379
|
-
delete channels[channel];
|
|
380
|
-
|
|
381
|
-
dispatcher.dispatch('unsubscribe', channel)
|
|
382
|
-
service.debug ? console.log(`[socket] - unsubscribed from ${channel}`) : null;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
///////////////////////////////////////////////////
|
|
386
|
-
|
|
387
|
-
return service;
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
export default QikSocket;</code></pre>
|
|
393
|
-
</article>
|
|
394
|
-
</section>
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
</div>
|
|
402
|
-
|
|
403
|
-
<br class="clear">
|
|
404
|
-
|
|
405
|
-
<footer>
|
|
406
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Thu Sep 28 2023 07:24:39 GMT+1000 (Australian Eastern Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
407
|
-
</footer>
|
|
408
|
-
|
|
409
|
-
<script>prettyPrint();</script>
|
|
410
|
-
<script src="scripts/polyfill.js"></script>
|
|
411
|
-
<script src="scripts/linenumber.js"></script>
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
</body>
|
|
416
|
-
</html>
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
<meta charset="utf-8">
|
|
6
|
-
<title>qik.system.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#.allPermissions">allPermissions</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#.canCreate">canCreate</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#.canEraseItem">canEraseItem</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#.canRestoreItem">canRestoreItem</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#.getAllDescendants">getAllDescendants</a></li><li data-type='method'><a href="access.html#.has">has</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#.isOwner">isOwner</a></li></ul></li><li><a href="api.html">api</a><ul class='methods'><li data-type='method'><a href="api.html#.delete">delete</a></li><li data-type='method'><a href="api.html#.generateEndpointURL">generateEndpointURL</a></li><li data-type='method'><a href="api.html#.get">get</a></li><li data-type='method'><a href="api.html#.patch">patch</a></li><li data-type='method'><a href="api.html#.post">post</a></li><li data-type='method'><a href="api.html#.put">put</a></li></ul></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#.ensureValidToken">ensureValidToken</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#.impersonate">impersonate</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#.retrieveUserFromResetToken">retrieveUserFromResetToken</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#.sync">sync</a></li><li data-type='method'><a href="auth.html#.updateUserWithToken">updateUserWithToken</a></li></ul></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#.reset">reset</a></li></ul></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#.delete">delete</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#.glossary">glossary</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#.restore">restore</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#.validateField">validateField</a></li><li data-type='method'><a href="content.html#.variables">variables</a></li></ul></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#.filesize">filesize</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></ul></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#.activeFilterOperators">activeFilterOperators</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#.filterChangeString">filterChangeString</a></li><li data-type='method'><a href="filter.html#.isValidFilter">isValidFilter</a></li></ul></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#.close">close</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#.subscribe">subscribe</a></li><li data-type='method'><a href="socket.html#.unsubscribe">unsubscribe</a></li></ul></li><li><a href="system.html">system</a><ul class='methods'><li data-type='method'><a href="system.html#.countries">countries</a></li></ul></li></ul>
|
|
31
|
-
</nav>
|
|
32
|
-
|
|
33
|
-
<div id="main">
|
|
34
|
-
|
|
35
|
-
<h1 class="page-title">qik.system.js</h1>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
<section>
|
|
44
|
-
<article>
|
|
45
|
-
<pre class="prettyprint source linenums"><code>///////////////////////////////////////////////////
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Creates a new QikSystem instance.
|
|
49
|
-
* This module provides a number of helper functions for the system
|
|
50
|
-
* @alias system
|
|
51
|
-
* @constructor
|
|
52
|
-
* @hideconstructor
|
|
53
|
-
* @param {QikCore} 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.
|
|
54
|
-
*/
|
|
55
|
-
export default function(qik) {
|
|
56
|
-
|
|
57
|
-
///////////////////////////////////////////////////
|
|
58
|
-
|
|
59
|
-
var service = {}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
63
|
-
|
|
64
|
-
var inflightCountries;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @alias system.countries
|
|
68
|
-
* @description Helper function for retrieving a full list of all countries, their ISO codes
|
|
69
|
-
* and phone number prefixes. Helpful for populating dropdown lists.
|
|
70
|
-
* @example
|
|
71
|
-
* const countries = await sdk.system.countries()
|
|
72
|
-
*/
|
|
73
|
-
service.countries = async function() {
|
|
74
|
-
|
|
75
|
-
if (!inflightCountries) {
|
|
76
|
-
|
|
77
|
-
inflightCountries = new Promise(async function(resolve, reject) {
|
|
78
|
-
qik.api.get(`/system/countries`)
|
|
79
|
-
.then(function(res) {
|
|
80
|
-
return resolve(res.data);
|
|
81
|
-
})
|
|
82
|
-
.catch(reject);
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return inflightCountries;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
///////////////////////////////////////////////////
|
|
90
|
-
|
|
91
|
-
return service;
|
|
92
|
-
|
|
93
|
-
}</code></pre>
|
|
94
|
-
</article>
|
|
95
|
-
</section>
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
</div>
|
|
103
|
-
|
|
104
|
-
<br class="clear">
|
|
105
|
-
|
|
106
|
-
<footer>
|
|
107
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Thu Sep 28 2023 07:24:39 GMT+1000 (Australian Eastern Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
108
|
-
</footer>
|
|
109
|
-
|
|
110
|
-
<script>prettyPrint();</script>
|
|
111
|
-
<script src="scripts/polyfill.js"></script>
|
|
112
|
-
<script src="scripts/linenumber.js"></script>
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
</body>
|
|
117
|
-
</html>
|