anear-js-api 0.4.6 → 0.4.7
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/lib/api/AnearApi.js
CHANGED
|
@@ -8,38 +8,34 @@ class AnearApi extends ApiService {
|
|
|
8
8
|
super(apiKey, apiVersion)
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
getAccount() {
|
|
12
12
|
logger.debug("API: GET /accounts")
|
|
13
13
|
|
|
14
|
-
return
|
|
14
|
+
return this.get("accounts")
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
getEvent(eventId) {
|
|
18
18
|
logger.debug(`API: GET event ${eventId}`)
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
return json
|
|
20
|
+
return this.get("events", {id: eventId})
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
getAppZones(appId) {
|
|
25
24
|
logger.debug(`API: GET app_zones ${appId}`)
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
return json
|
|
26
|
+
return this.get("app_zones", {id: appId})
|
|
29
27
|
}
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
getApp(appId) {
|
|
32
30
|
logger.debug(`API: GET app ${appId}`)
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
return json
|
|
32
|
+
return this.get("apps", {id: appId})
|
|
36
33
|
}
|
|
37
34
|
|
|
38
|
-
|
|
35
|
+
getZoneEvents(zoneId) {
|
|
39
36
|
logger.debug(`API: GET zone_events ${zoneId}`)
|
|
40
37
|
|
|
41
|
-
|
|
42
|
-
return json
|
|
38
|
+
return this.get("zone_events", {id: zoneId})
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
async transitionEvent(eventId, eventName='next') {
|
|
@@ -52,11 +48,10 @@ class AnearApi extends ApiService {
|
|
|
52
48
|
return attrs
|
|
53
49
|
}
|
|
54
50
|
|
|
55
|
-
|
|
51
|
+
getEventParticipantJson(participantId, geoLocation) {
|
|
56
52
|
logger.debug(`API: GET event_participant ${participantId}`)
|
|
57
53
|
|
|
58
|
-
|
|
59
|
-
return json
|
|
54
|
+
return this.get("event_participants", {id: participantId})
|
|
60
55
|
}
|
|
61
56
|
}
|
|
62
57
|
|
|
@@ -61,7 +61,7 @@ class AnearMessaging {
|
|
|
61
61
|
initRealtime(clientOptions) {
|
|
62
62
|
logger.debug("new Ably.Realtime connection..., log level: ", AblyLogLevel)
|
|
63
63
|
|
|
64
|
-
this.realtime = new Ably.Realtime(clientOptions)
|
|
64
|
+
this.realtime = new Ably.Realtime.Promise(clientOptions)
|
|
65
65
|
|
|
66
66
|
const connectedCallback = async () => {
|
|
67
67
|
await this.getAppInfo(AppId)
|
package/lib/models/AnearEvent.js
CHANGED
|
@@ -218,21 +218,31 @@ class AnearEvent extends JsonApiResource {
|
|
|
218
218
|
async participantEnter(participant) {
|
|
219
219
|
// Called each time a participant ENTERs (attaches to) the Event's Action Channel.
|
|
220
220
|
// This could be when joining an event for the first time, rejoining, or after a browser
|
|
221
|
-
// refresh/reconnect. If the participant exists in this.participants,
|
|
222
|
-
//
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
this.participants.
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
221
|
+
// refresh/reconnect. If the participant exists in Storage and in this.participants,
|
|
222
|
+
// its probably due to a browser refresh, and we call Refresh. Else, its either a brand
|
|
223
|
+
// new participant or an anearEvent recovery after crash, and so we invoke new participant enter
|
|
224
|
+
//
|
|
225
|
+
if (participant.exists()) { // persisted in storage?
|
|
226
|
+
if (this.participants.exists(participant)) {
|
|
227
|
+
logger.debug(`AnearEvent: participant ${participant.id} exists. Refreshing...`)
|
|
228
|
+
|
|
229
|
+
// Likely here due to participant browser refresh
|
|
230
|
+
// get the existing participant, turn off his timer and send refresh event to StateMachine
|
|
231
|
+
const existingParticipant = this.participants.get(participant)
|
|
232
|
+
existingParticipant.interruptTimer()
|
|
233
|
+
this.anearStateMachine.sendRefreshEvent({participant: existingParticipant})
|
|
234
|
+
await existingParticipant.update()
|
|
235
|
+
} else {
|
|
236
|
+
// Likely here due to prior AnearEvent error and this is a event reload and restart
|
|
237
|
+
// add the participants record back into Participants and update persisted copy
|
|
238
|
+
this.participants.add(participant)
|
|
239
|
+
this.anearStateMachine.sendJoinEvent({ participant })
|
|
240
|
+
await participant.update()
|
|
241
|
+
}
|
|
231
242
|
} else {
|
|
243
|
+
// New Participant first-time join this AnearEvent
|
|
232
244
|
this.participants.add(participant) // add the participants record
|
|
233
|
-
|
|
234
245
|
this.anearStateMachine.sendJoinEvent({ participant })
|
|
235
|
-
|
|
236
246
|
await participant.persist()
|
|
237
247
|
}
|
|
238
248
|
}
|
|
@@ -360,8 +370,8 @@ class AnearEvent extends JsonApiResource {
|
|
|
360
370
|
await this.messaging.detachAll(this.id)
|
|
361
371
|
}
|
|
362
372
|
|
|
363
|
-
|
|
364
|
-
logger.
|
|
373
|
+
logDebugMessage(...args) {
|
|
374
|
+
logger.debug(...args)
|
|
365
375
|
}
|
|
366
376
|
|
|
367
377
|
logError(context, event) {
|
|
@@ -46,7 +46,15 @@ class Participants {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
exists({id}) {
|
|
49
|
-
|
|
49
|
+
const emptyObject = (obj) => {
|
|
50
|
+
return Object.keys(obj).length === 0 && Object.getPrototypeOf(obj) === Object.prototype
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const participant = this.getById(id)
|
|
54
|
+
|
|
55
|
+
if (!participant) { return false } // id not found
|
|
56
|
+
|
|
57
|
+
return !emptyObject(participant)
|
|
50
58
|
}
|
|
51
59
|
|
|
52
60
|
get({id}) {
|