miakapi 3.0.31 → 4.0.0-alpha.0
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/LICENSE +15 -0
- package/README.md +358 -0
- package/contracts/miakapp-v3.json +6 -0
- package/dist/access-token-provider.d.ts +8 -0
- package/dist/access-token-provider.d.ts.map +1 -0
- package/dist/access-token-provider.js +167 -0
- package/dist/access-token-provider.js.map +1 -0
- package/dist/api.d.ts +224 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +47 -0
- package/dist/api.js.map +1 -0
- package/dist/browser-api.d.ts +113 -0
- package/dist/browser-api.d.ts.map +1 -0
- package/dist/browser-api.js +2 -0
- package/dist/browser-api.js.map +1 -0
- package/dist/browser-client.d.ts +3 -0
- package/dist/browser-client.d.ts.map +1 -0
- package/dist/browser-client.js +678 -0
- package/dist/browser-client.js.map +1 -0
- package/dist/browser-relay-credential-provider.d.ts +3 -0
- package/dist/browser-relay-credential-provider.d.ts.map +1 -0
- package/dist/browser-relay-credential-provider.js +243 -0
- package/dist/browser-relay-credential-provider.js.map +1 -0
- package/dist/browser.d.ts +4 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +4 -0
- package/dist/browser.js.map +1 -0
- package/dist/coordinator.d.ts +3 -0
- package/dist/coordinator.d.ts.map +1 -0
- package/dist/coordinator.js +544 -0
- package/dist/coordinator.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/browser-errors.d.ts +31 -0
- package/dist/internal/browser-errors.d.ts.map +1 -0
- package/dist/internal/browser-errors.js +69 -0
- package/dist/internal/browser-errors.js.map +1 -0
- package/dist/internal/browser-socket.d.ts +8 -0
- package/dist/internal/browser-socket.d.ts.map +1 -0
- package/dist/internal/browser-socket.js +204 -0
- package/dist/internal/browser-socket.js.map +1 -0
- package/dist/internal/calls.d.ts +33 -0
- package/dist/internal/calls.d.ts.map +1 -0
- package/dist/internal/calls.js +525 -0
- package/dist/internal/calls.js.map +1 -0
- package/dist/internal/control-plane-response.d.ts +10 -0
- package/dist/internal/control-plane-response.d.ts.map +1 -0
- package/dist/internal/control-plane-response.js +283 -0
- package/dist/internal/control-plane-response.js.map +1 -0
- package/dist/internal/declarations.d.ts +62 -0
- package/dist/internal/declarations.d.ts.map +1 -0
- package/dist/internal/declarations.js +427 -0
- package/dist/internal/declarations.js.map +1 -0
- package/dist/internal/errors.d.ts +31 -0
- package/dist/internal/errors.d.ts.map +1 -0
- package/dist/internal/errors.js +72 -0
- package/dist/internal/errors.js.map +1 -0
- package/dist/internal/events.d.ts +27 -0
- package/dist/internal/events.d.ts.map +1 -0
- package/dist/internal/events.js +207 -0
- package/dist/internal/events.js.map +1 -0
- package/dist/internal/presence.d.ts +15 -0
- package/dist/internal/presence.d.ts.map +1 -0
- package/dist/internal/presence.js +99 -0
- package/dist/internal/presence.js.map +1 -0
- package/dist/internal/resources.d.ts +33 -0
- package/dist/internal/resources.d.ts.map +1 -0
- package/dist/internal/resources.js +136 -0
- package/dist/internal/resources.js.map +1 -0
- package/dist/internal/runtime.d.ts +34 -0
- package/dist/internal/runtime.d.ts.map +1 -0
- package/dist/internal/runtime.js +17 -0
- package/dist/internal/runtime.js.map +1 -0
- package/dist/internal/session.d.ts +33 -0
- package/dist/internal/session.d.ts.map +1 -0
- package/dist/internal/session.js +199 -0
- package/dist/internal/session.js.map +1 -0
- package/dist/internal/socket.d.ts +6 -0
- package/dist/internal/socket.d.ts.map +1 -0
- package/dist/internal/socket.js +176 -0
- package/dist/internal/socket.js.map +1 -0
- package/dist/internal/state.d.ts +21 -0
- package/dist/internal/state.d.ts.map +1 -0
- package/dist/internal/state.js +133 -0
- package/dist/internal/state.js.map +1 -0
- package/dist/internal/user-calls.d.ts +27 -0
- package/dist/internal/user-calls.d.ts.map +1 -0
- package/dist/internal/user-calls.js +325 -0
- package/dist/internal/user-calls.js.map +1 -0
- package/dist/internal/user-session.d.ts +36 -0
- package/dist/internal/user-session.d.ts.map +1 -0
- package/dist/internal/user-session.js +250 -0
- package/dist/internal/user-session.js.map +1 -0
- package/dist/internal/user-state.d.ts +21 -0
- package/dist/internal/user-state.d.ts.map +1 -0
- package/dist/internal/user-state.js +240 -0
- package/dist/internal/user-state.js.map +1 -0
- package/dist/internal/validation.d.ts +32 -0
- package/dist/internal/validation.d.ts.map +1 -0
- package/dist/internal/validation.js +553 -0
- package/dist/internal/validation.js.map +1 -0
- package/dist/protocol/codec.d.ts +75 -0
- package/dist/protocol/codec.d.ts.map +1 -0
- package/dist/protocol/codec.js +1091 -0
- package/dist/protocol/codec.js.map +1 -0
- package/dist/protocol/session.d.ts +14 -0
- package/dist/protocol/session.d.ts.map +1 -0
- package/dist/protocol/session.js +125 -0
- package/dist/protocol/session.js.map +1 -0
- package/dist/protocol/user-session.d.ts +14 -0
- package/dist/protocol/user-session.d.ts.map +1 -0
- package/dist/protocol/user-session.js +116 -0
- package/dist/protocol/user-session.js.map +1 -0
- package/package.json +57 -9
- package/.eslintrc.js +0 -16
- package/.gitattributes +0 -2
- package/main.js +0 -305
- package/miakode.js +0 -56
- package/screenshots/bigGrid.jpg +0 -0
- package/screenshots/formExample.jpg +0 -0
- package/screenshots/properties&table.jpg +0 -0
- package/test.js +0 -45
package/main.js
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
const https = require('https');
|
|
2
|
-
const WebSocketClient = require('websocket').client;
|
|
3
|
-
const miakode = require('./miakode');
|
|
4
|
-
|
|
5
|
-
function getHome(homeID) {
|
|
6
|
-
return new Promise((cb, err) => {
|
|
7
|
-
https.get(`https://firestore.googleapis.com/v1/projects
|
|
8
|
-
/miakapp-3/databases/(default)/documents/homes/${homeID}`, (res) => {
|
|
9
|
-
let data = '';
|
|
10
|
-
res.on('data', (c) => { data += c; });
|
|
11
|
-
res.on('close', () => {
|
|
12
|
-
data = JSON.parse(data);
|
|
13
|
-
if (data.fields && data.fields.name) {
|
|
14
|
-
cb({
|
|
15
|
-
id: homeID,
|
|
16
|
-
name: data.fields.name.stringValue,
|
|
17
|
-
server: data.fields.server.stringValue,
|
|
18
|
-
});
|
|
19
|
-
} else err(new Error('Wrong homeID'));
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function parsePacket(packet) {
|
|
26
|
-
if (!packet.binaryData) return { type: 'unknown' };
|
|
27
|
-
|
|
28
|
-
const parsed = packet.binaryData.toString();
|
|
29
|
-
return {
|
|
30
|
-
type: parsed[0],
|
|
31
|
-
data: parsed.substring(1),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const connect = async (credentials, {
|
|
36
|
-
onReady, onHomeUpdate, onUserLogin, onUserAction,
|
|
37
|
-
}) => {
|
|
38
|
-
const homeDoc = await getHome(credentials.home);
|
|
39
|
-
if (!homeDoc.server) throw new Error('There is no selected server for this home');
|
|
40
|
-
|
|
41
|
-
const client = new WebSocketClient();
|
|
42
|
-
function newSocket() {
|
|
43
|
-
console.log('Connecting to', homeDoc.server);
|
|
44
|
-
client.connect(`wss://${homeDoc.server}/${homeDoc.id}/`, null, '//coordinator.miakapp');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
let socket = null;
|
|
48
|
-
|
|
49
|
-
function sendPacket(type, data) {
|
|
50
|
-
if (socket) socket.sendBytes(Buffer.from(`${type}${data}`));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
client.on('connect', (s) => {
|
|
54
|
-
console.log('Coordinator connected');
|
|
55
|
-
socket = s;
|
|
56
|
-
|
|
57
|
-
s.on('message', (packet) => {
|
|
58
|
-
const msg = parsePacket(packet);
|
|
59
|
-
|
|
60
|
-
if (msg.type === '\x30') { // PING
|
|
61
|
-
sendPacket('\x40', msg.data);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (msg.type === '\x31') { // USERLIST
|
|
66
|
-
const users = msg.data.split('\x00').filter((u) => u).map((u) => {
|
|
67
|
-
const [id, displayName, groups] = u.split('\x01');
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
id: id.substring(2),
|
|
71
|
-
displayName,
|
|
72
|
-
isAdmin: (id[0] === '1'),
|
|
73
|
-
notifications: (id[1] === '1'),
|
|
74
|
-
groups: groups.split('\x02').filter((g) => g),
|
|
75
|
-
};
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
onHomeUpdate(users);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (msg.type === '\x32') { // USER CONNECT
|
|
83
|
-
const parsed = miakode.string.decode(msg.data);
|
|
84
|
-
const userClient = parsed.substring(1).split('@');
|
|
85
|
-
|
|
86
|
-
onUserLogin({
|
|
87
|
-
type: ['DISCONNECT', 'CONNECT'][parsed[0]],
|
|
88
|
-
connectionUID: userClient[0],
|
|
89
|
-
user: userClient[1],
|
|
90
|
-
});
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (msg.type === '\x33') { // USER ACTION
|
|
95
|
-
const [user, type, id, name, value] = miakode.array.decode(msg.data);
|
|
96
|
-
onUserAction({
|
|
97
|
-
user,
|
|
98
|
-
type: (type === '1') ? 'input' : 'click',
|
|
99
|
-
input: { id, name, value },
|
|
100
|
-
});
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (msg.type === '\x00') { // LOGGED
|
|
105
|
-
onReady();
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
console.log('Unknown packet', msg);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
sendPacket('\x04', miakode.array.encode([
|
|
113
|
-
credentials.home,
|
|
114
|
-
credentials.id,
|
|
115
|
-
credentials.secret,
|
|
116
|
-
]));
|
|
117
|
-
|
|
118
|
-
s.on('close', (code, desc) => {
|
|
119
|
-
console.log('CLOSE', code, desc);
|
|
120
|
-
if ([4001, 4005].includes(code)) return;
|
|
121
|
-
setTimeout(newSocket, 1000);
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
client.on('connectFailed', () => {
|
|
126
|
-
console.log('Coordinator failed connect');
|
|
127
|
-
setTimeout(newSocket, 1000);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
newSocket();
|
|
131
|
-
|
|
132
|
-
return {
|
|
133
|
-
emitCallback(data) {
|
|
134
|
-
sendPacket('\x41', miakode.object.encode(data));
|
|
135
|
-
},
|
|
136
|
-
emitNotif(userID, {
|
|
137
|
-
title, body, tag, image,
|
|
138
|
-
}) {
|
|
139
|
-
sendPacket('\x42', miakode.array.encode([
|
|
140
|
-
userID, title, body, tag, image,
|
|
141
|
-
]));
|
|
142
|
-
},
|
|
143
|
-
reconnect() {
|
|
144
|
-
if (socket && socket.close) {
|
|
145
|
-
socket.close();
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
};
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* User login event data
|
|
153
|
-
* @typedef {Object} UserLoginEvent
|
|
154
|
-
* @property {User} user
|
|
155
|
-
* @property {'CONNECT' | 'DISCONNECT'} type Event type
|
|
156
|
-
* @property {number} connectionUID ID of connection
|
|
157
|
-
*/
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* DOM input (or button) element in a Miakapp page
|
|
161
|
-
* @typedef InputElement
|
|
162
|
-
* @property {string} id ID of DOM element
|
|
163
|
-
* @property {string} name Name of DOM element
|
|
164
|
-
* @property {string} value Value of input element (if exists)
|
|
165
|
-
*/
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* User action event data
|
|
169
|
-
* @typedef {Object} UserActionEvent
|
|
170
|
-
* @property {User} user User who interacted with an input
|
|
171
|
-
* @property {'click' | 'input'} type Event type ('click' or 'input')
|
|
172
|
-
* @property {InputElement} input Input the user interacted with
|
|
173
|
-
*/
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Represents a push notification
|
|
177
|
-
* @typedef {Object} Notification
|
|
178
|
-
* @property {string} title Notification title
|
|
179
|
-
* @property {string} body Notification body
|
|
180
|
-
* @property {string=} tag Notification tag
|
|
181
|
-
* @property {string=} image Notification image
|
|
182
|
-
*/
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* User instance
|
|
186
|
-
* @typedef {Object} User
|
|
187
|
-
* @property {string} id ID of the user
|
|
188
|
-
* @property {string} displayName Display name of the user
|
|
189
|
-
* @property {boolean} isAdmin True if the user is admin of the home
|
|
190
|
-
* @property {boolean} notifications True if the user has enabled notifications
|
|
191
|
-
* @property {string[]} groups List of group names of the user
|
|
192
|
-
* @property {(notification: Notification) => void} sendPush Send push notification
|
|
193
|
-
*/
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Instance of miakapp home
|
|
197
|
-
* @typedef {Object} Home
|
|
198
|
-
* @property {User[]} users List of users who have access to the home
|
|
199
|
-
* @property {Object<string, string>} variables Dynamic variables to inject in your pages
|
|
200
|
-
* @property {(modifs: {}) => void} commit Send data modifications to users
|
|
201
|
-
* @property {(userID: string, notification: Notification) => void
|
|
202
|
-
* } sendNotif Send push notification to user
|
|
203
|
-
* @property {(callback: () => void) => void} onReady Event that handles when API is ready
|
|
204
|
-
* @property {(callback: (users: User[]) => void) => void
|
|
205
|
-
* } onUpdate Event that handles when an update of home settings happens
|
|
206
|
-
* @property {(callback: (event: UserLoginEvent) => void) => void
|
|
207
|
-
* } onUserLogin Event that handles when a user connects or disconnects
|
|
208
|
-
* @property {(callback: (action: UserActionEvent) => void) => void
|
|
209
|
-
* } onUserAction Event that handles when a user interact with a page
|
|
210
|
-
* @property {() => void} reconnect Restart connection to the server
|
|
211
|
-
*/
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Creates a home instance
|
|
215
|
-
* @param {string} home Home ID (in your URL)
|
|
216
|
-
* @param {string} id Coordinator ID (default is "main")
|
|
217
|
-
* @param {string} secret Coordinator secret token
|
|
218
|
-
* @returns {Home} Returns an instance of home
|
|
219
|
-
*/
|
|
220
|
-
module.exports = function Miakapi(home, id, secret) {
|
|
221
|
-
/** @type {(() => void)[]} */
|
|
222
|
-
const readyCallbacks = [];
|
|
223
|
-
/** @type {((users: User[]) => void)[]} */
|
|
224
|
-
const userlistUpdateCallbacks = [];
|
|
225
|
-
/** @type {((event: UserLoginEvent) => void)[]} */
|
|
226
|
-
const userLoginCallbacks = [];
|
|
227
|
-
/** @type {((action: UserActionEvent) => void)[]} */
|
|
228
|
-
const userActionCallbacks = [];
|
|
229
|
-
|
|
230
|
-
const client = {
|
|
231
|
-
emitCallback() { return false; },
|
|
232
|
-
emitNotif() { return false; },
|
|
233
|
-
reconnect() { return false; },
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
/** @type {Home} */
|
|
237
|
-
const thisHome = {
|
|
238
|
-
users: [],
|
|
239
|
-
variables: {},
|
|
240
|
-
|
|
241
|
-
commit(modifs = {}) {
|
|
242
|
-
Object.assign(this.variables, modifs);
|
|
243
|
-
client.emitCallback(this.variables);
|
|
244
|
-
},
|
|
245
|
-
|
|
246
|
-
sendNotif(userID, notification = {}) {
|
|
247
|
-
client.emitNotif(userID, notification);
|
|
248
|
-
},
|
|
249
|
-
|
|
250
|
-
onReady(callback) {
|
|
251
|
-
readyCallbacks.push(callback);
|
|
252
|
-
},
|
|
253
|
-
onUpdate(callback) {
|
|
254
|
-
userlistUpdateCallbacks.push(callback);
|
|
255
|
-
},
|
|
256
|
-
onUserLogin(callback) {
|
|
257
|
-
userLoginCallbacks.push(callback);
|
|
258
|
-
},
|
|
259
|
-
onUserAction(callback) {
|
|
260
|
-
userActionCallbacks.push(callback);
|
|
261
|
-
},
|
|
262
|
-
|
|
263
|
-
reconnect() {
|
|
264
|
-
client.reconnect();
|
|
265
|
-
},
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
connect({ home, id, secret }, {
|
|
269
|
-
onReady() {
|
|
270
|
-
readyCallbacks.forEach((h) => h());
|
|
271
|
-
},
|
|
272
|
-
onHomeUpdate(data) {
|
|
273
|
-
thisHome.users = data.map((u) => ({
|
|
274
|
-
...u,
|
|
275
|
-
sendPush(notification) {
|
|
276
|
-
client.emitNotif(u.id, notification);
|
|
277
|
-
},
|
|
278
|
-
}));
|
|
279
|
-
|
|
280
|
-
userlistUpdateCallbacks.forEach((h) => h(thisHome.users));
|
|
281
|
-
},
|
|
282
|
-
onUserLogin(data) {
|
|
283
|
-
const eventData = {
|
|
284
|
-
...data,
|
|
285
|
-
user: thisHome.users.find((u) => u.id === data.user),
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
userLoginCallbacks.forEach((h) => h(eventData));
|
|
289
|
-
},
|
|
290
|
-
onUserAction(data) {
|
|
291
|
-
const eventData = {
|
|
292
|
-
...data,
|
|
293
|
-
user: thisHome.users.find((u) => u.id === data.user),
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
userActionCallbacks.forEach((h) => h(eventData));
|
|
297
|
-
},
|
|
298
|
-
}).then(({ emitCallback, emitNotif, reconnect }) => {
|
|
299
|
-
client.emitCallback = emitCallback;
|
|
300
|
-
client.emitNotif = emitNotif;
|
|
301
|
-
client.reconnect = reconnect;
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
return thisHome;
|
|
305
|
-
};
|
package/miakode.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
object: {
|
|
3
|
-
encode(o = {}) {
|
|
4
|
-
let e = Object.keys(o).map((k) => `${k}\x01${o[k]}`).join('\x00').split('');
|
|
5
|
-
let m = null;
|
|
6
|
-
e.forEach((c) => { m = (!m || m > c) ? c.charCodeAt(0) : m; });
|
|
7
|
-
e = e.map((c) => String.fromCharCode(c.charCodeAt(0) - m)).join('');
|
|
8
|
-
|
|
9
|
-
return `${String.fromCharCode(m)}${e}`;
|
|
10
|
-
},
|
|
11
|
-
|
|
12
|
-
decode(s) {
|
|
13
|
-
const m = s[0].charCodeAt(0);
|
|
14
|
-
let e = s.substring(1).split('');
|
|
15
|
-
e = e.map((c) => String.fromCharCode(c.charCodeAt(0) + m)).join('');
|
|
16
|
-
const o = {};
|
|
17
|
-
e.split('\x00').forEach((l) => {
|
|
18
|
-
const p = l.split('\x01');
|
|
19
|
-
[, o[p[0]]] = p;
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
return o;
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
array: {
|
|
27
|
-
encode(a = []) {
|
|
28
|
-
let e = a.join('\x00').split('');
|
|
29
|
-
let m = null;
|
|
30
|
-
e.forEach((c) => { m = (!m || m > c) ? c.charCodeAt(0) : m; });
|
|
31
|
-
e = e.map((c) => String.fromCharCode(c.charCodeAt(0) - m)).join('');
|
|
32
|
-
|
|
33
|
-
return `${String.fromCharCode(m)}${e}`;
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
decode: (s) => s.substring(1).split('')
|
|
37
|
-
.map((c) => String.fromCharCode(c.charCodeAt(0) + s[0].charCodeAt(0)))
|
|
38
|
-
.join('')
|
|
39
|
-
.split('\x00'),
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
string: {
|
|
43
|
-
encode(s = '') {
|
|
44
|
-
let e = s.split('');
|
|
45
|
-
let m = null;
|
|
46
|
-
e.forEach((c) => { m = (!m || m > c) ? c.charCodeAt(0) : m; });
|
|
47
|
-
e = e.map((c) => String.fromCharCode(c.charCodeAt(0) - m)).join('');
|
|
48
|
-
|
|
49
|
-
return `${String.fromCharCode(m)}${e}`;
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
decode: (s = '') => s.substring(1).split('')
|
|
53
|
-
.map((c) => String.fromCharCode(c.charCodeAt(0) + s[0].charCodeAt(0)))
|
|
54
|
-
.join(''),
|
|
55
|
-
},
|
|
56
|
-
};
|
package/screenshots/bigGrid.jpg
DELETED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/test.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const Miakapi = require('./main');
|
|
2
|
-
const credentials = require('./miakapiCredentials.json');
|
|
3
|
-
|
|
4
|
-
const home = Miakapi(
|
|
5
|
-
credentials.home,
|
|
6
|
-
credentials.coordID,
|
|
7
|
-
credentials.coordSecret,
|
|
8
|
-
);
|
|
9
|
-
|
|
10
|
-
console.log('Connecting...');
|
|
11
|
-
|
|
12
|
-
home.onReady(() => {
|
|
13
|
-
console.log('Ready !', home);
|
|
14
|
-
home.users.forEach((user) => {
|
|
15
|
-
console.log('Sending notification to', user.displayName);
|
|
16
|
-
|
|
17
|
-
user.sendPush({
|
|
18
|
-
title: 'Notification test 1',
|
|
19
|
-
body: 'Test user.sendPush',
|
|
20
|
-
tag: 'test1',
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
home.sendNotif(user.id, {
|
|
24
|
-
title: 'Notification test 2',
|
|
25
|
-
body: 'Test home.sendNotif',
|
|
26
|
-
tag: 'test2',
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
home.onUpdate((users) => {
|
|
32
|
-
console.log('Home update !', users);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
home.onUserAction((action) => {
|
|
36
|
-
console.log('User action :', action);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
setInterval(() => {
|
|
40
|
-
home.variables.timestamp = Date.now();
|
|
41
|
-
home.commit({
|
|
42
|
-
'global.timestamp': Date.now(),
|
|
43
|
-
'global.invert': !home.variables['global.invert'],
|
|
44
|
-
});
|
|
45
|
-
}, 5000);
|