anear-js-api 0.4.8 → 0.4.10
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 +6 -0
- package/lib/models/AnearEvent.js +30 -31
- package/package.json +1 -1
- package/tests/AnearEvent.test.js +1 -0
package/lib/api/AnearApi.js
CHANGED
|
@@ -53,6 +53,12 @@ class AnearApi extends ApiService {
|
|
|
53
53
|
|
|
54
54
|
return this.get("event_participants", {id: participantId})
|
|
55
55
|
}
|
|
56
|
+
|
|
57
|
+
getUser(userId) {
|
|
58
|
+
logger.debug(`API: GET user ${userId}`)
|
|
59
|
+
|
|
60
|
+
return this.get("users", {id: userId})
|
|
61
|
+
}
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
module.exports = AnearApi
|
package/lib/models/AnearEvent.js
CHANGED
|
@@ -64,14 +64,13 @@ class AnearEvent extends JsonApiResource {
|
|
|
64
64
|
return this.relationships.zone.data.id
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
getClonedEvent() {
|
|
68
68
|
// if the current event was a clone of previous event, fetch if from
|
|
69
69
|
// Peristence and return
|
|
70
70
|
const clonedEventData = this.relationships["cloned-event"].data
|
|
71
71
|
if (!clonedEventData) return null
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
return clonedEvent
|
|
73
|
+
return this.constructor.getFromStorage(clonedEventData.id)
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
async clonedEventContext() {
|
|
@@ -123,16 +122,16 @@ class AnearEvent extends JsonApiResource {
|
|
|
123
122
|
return !this.hasFlag("no_spectators")
|
|
124
123
|
}
|
|
125
124
|
|
|
126
|
-
|
|
127
|
-
return
|
|
125
|
+
spectatorCount() {
|
|
126
|
+
return this.messaging.getSpectatorCount(this)
|
|
128
127
|
}
|
|
129
128
|
|
|
130
129
|
isParticipantEventCreator(RParticipant) {
|
|
131
130
|
return participant.userId === this.userId
|
|
132
131
|
}
|
|
133
132
|
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
publishEventParticipantsMessage(message, timeoutMsecs=0) {
|
|
134
|
+
return this.messaging.publishEventParticipantsMessage(
|
|
136
135
|
this,
|
|
137
136
|
this.participants.active(),
|
|
138
137
|
this.css,
|
|
@@ -153,12 +152,12 @@ class AnearEvent extends JsonApiResource {
|
|
|
153
152
|
logger.debug(`mutex ${name} released!`)
|
|
154
153
|
}
|
|
155
154
|
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
publishEventSpectatorsMessage(message) {
|
|
156
|
+
return this.messaging.publishEventSpectatorsMessage(this, this.css, message)
|
|
158
157
|
}
|
|
159
158
|
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
publishEventPrivateMessage(participant, message, timeoutMsecs=0) {
|
|
160
|
+
return this.messaging.publishEventPrivateMessage(
|
|
162
161
|
this,
|
|
163
162
|
participant,
|
|
164
163
|
PrivateDisplayMessageType,
|
|
@@ -168,8 +167,8 @@ class AnearEvent extends JsonApiResource {
|
|
|
168
167
|
)
|
|
169
168
|
}
|
|
170
169
|
|
|
171
|
-
|
|
172
|
-
|
|
170
|
+
publishEventTransitionMessage(newState) {
|
|
171
|
+
return this.messaging.publishEventTransitionMessage(
|
|
173
172
|
this,
|
|
174
173
|
newState
|
|
175
174
|
)
|
|
@@ -207,20 +206,20 @@ class AnearEvent extends JsonApiResource {
|
|
|
207
206
|
}
|
|
208
207
|
}
|
|
209
208
|
|
|
210
|
-
|
|
209
|
+
participantExit(participant) {
|
|
211
210
|
// this informs the state machine that the participant has exited the event
|
|
212
211
|
// and removes that participant completely
|
|
213
212
|
this.anearStateMachine.sendParticipantExitEvent({ participant })
|
|
214
|
-
|
|
213
|
+
return this.participantPurge(participant)
|
|
215
214
|
}
|
|
216
215
|
|
|
217
216
|
spectatorView(userId) {
|
|
218
217
|
this.anearStateMachine.sendSpectatorViewEvent({userId})
|
|
219
218
|
}
|
|
220
219
|
|
|
221
|
-
|
|
220
|
+
participantPurge(participant) {
|
|
222
221
|
this.participants.purge(participant)
|
|
223
|
-
|
|
222
|
+
return participant.remove()
|
|
224
223
|
}
|
|
225
224
|
|
|
226
225
|
participantAction(participant, actionEventName, actionPayload) {
|
|
@@ -262,24 +261,24 @@ class AnearEvent extends JsonApiResource {
|
|
|
262
261
|
await this.transitionEvent('next')
|
|
263
262
|
}
|
|
264
263
|
|
|
265
|
-
|
|
266
|
-
|
|
264
|
+
transitionLive() {
|
|
265
|
+
return this.transitionNextNext()
|
|
267
266
|
}
|
|
268
267
|
|
|
269
|
-
|
|
270
|
-
|
|
268
|
+
transitionClosed() {
|
|
269
|
+
return this.transitionNextNext()
|
|
271
270
|
}
|
|
272
271
|
|
|
273
|
-
|
|
274
|
-
|
|
272
|
+
transitionCanceled() {
|
|
273
|
+
return this.transitionEvent('cancel')
|
|
275
274
|
}
|
|
276
275
|
|
|
277
|
-
|
|
276
|
+
closeOutParticipants() {
|
|
278
277
|
// upon exiting the event, this will clean up any participants remaining
|
|
279
278
|
return Promise.all(
|
|
280
279
|
this.participants.all.map(
|
|
281
|
-
|
|
282
|
-
|
|
280
|
+
p => {
|
|
281
|
+
return this.messaging.closeParticipant(
|
|
283
282
|
this,
|
|
284
283
|
p.id,
|
|
285
284
|
async (anearEvent, participant) => {
|
|
@@ -291,12 +290,12 @@ class AnearEvent extends JsonApiResource {
|
|
|
291
290
|
)
|
|
292
291
|
}
|
|
293
292
|
|
|
294
|
-
|
|
295
|
-
// remove participants from Participants class and from Storage
|
|
293
|
+
purgeParticipants() {
|
|
294
|
+
// remove participants and host from Participants class and from Storage
|
|
296
295
|
const all = this.participants.all
|
|
297
296
|
if (this.participants.host) all.push(this.participants.host)
|
|
298
297
|
|
|
299
|
-
|
|
298
|
+
return Promise.all(
|
|
300
299
|
all.map(p => this.participantPurge(p))
|
|
301
300
|
)
|
|
302
301
|
}
|
|
@@ -326,8 +325,8 @@ class AnearEvent extends JsonApiResource {
|
|
|
326
325
|
await this.closeMessaging()
|
|
327
326
|
}
|
|
328
327
|
|
|
329
|
-
|
|
330
|
-
|
|
328
|
+
closeMessaging () {
|
|
329
|
+
return this.messaging.detachAll(this.id)
|
|
331
330
|
}
|
|
332
331
|
|
|
333
332
|
logDebugMessage(...args) {
|
package/package.json
CHANGED