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.
@@ -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
@@ -64,14 +64,13 @@ class AnearEvent extends JsonApiResource {
64
64
  return this.relationships.zone.data.id
65
65
  }
66
66
 
67
- async getClonedEvent() {
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
- const clonedEvent = await this.constructor.getFromStorage(clonedEventData.id)
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
- async spectatorCount() {
127
- return await this.messaging.getSpectatorCount(this)
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
- async publishEventParticipantsMessage(message, timeoutMsecs=0) {
135
- await this.messaging.publishEventParticipantsMessage(
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
- async publishEventSpectatorsMessage(message) {
157
- await this.messaging.publishEventSpectatorsMessage(this, this.css, message)
155
+ publishEventSpectatorsMessage(message) {
156
+ return this.messaging.publishEventSpectatorsMessage(this, this.css, message)
158
157
  }
159
158
 
160
- async publishEventPrivateMessage(participant, message, timeoutMsecs=0) {
161
- await this.messaging.publishEventPrivateMessage(
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
- async publishEventTransitionMessage(newState) {
172
- await this.messaging.publishEventTransitionMessage(
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
- async participantExit(participant) {
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
- await this.participantPurge(participant)
213
+ return this.participantPurge(participant)
215
214
  }
216
215
 
217
216
  spectatorView(userId) {
218
217
  this.anearStateMachine.sendSpectatorViewEvent({userId})
219
218
  }
220
219
 
221
- async participantPurge(participant) {
220
+ participantPurge(participant) {
222
221
  this.participants.purge(participant)
223
- await participant.remove()
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
- async transitionLive() {
266
- await this.transitionNextNext()
264
+ transitionLive() {
265
+ return this.transitionNextNext()
267
266
  }
268
267
 
269
- async transitionClosed() {
270
- await this.transitionNextNext()
268
+ transitionClosed() {
269
+ return this.transitionNextNext()
271
270
  }
272
271
 
273
- async transitionCanceled() {
274
- await this.transitionEvent('cancel')
272
+ transitionCanceled() {
273
+ return this.transitionEvent('cancel')
275
274
  }
276
275
 
277
- async closeOutParticipants() {
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
- async p => {
282
- await this.messaging.closeParticipant(
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
- async purgeParticipants() {
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
- await Promise.all(
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
- async closeMessaging () {
330
- await this.messaging.detachAll(this.id)
328
+ closeMessaging () {
329
+ return this.messaging.detachAll(this.id)
331
330
  }
332
331
 
333
332
  logDebugMessage(...args) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anear-js-api",
3
- "version": "0.4.8",
3
+ "version": "0.4.10",
4
4
  "description": "Javascript Developer API for Anear Apps",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -276,6 +276,7 @@ test('purge all participants', async () => {
276
276
  await t.purgeParticipants()
277
277
 
278
278
  expect(t.participants.all).toHaveLength(0)
279
+ expect(t.participants.host).toBe(null)
279
280
 
280
281
  await t.remove()
281
282
  })