anear-js-api 0.4.9 → 0.4.11

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
@@ -7,6 +7,7 @@ const AppId = process.env.ANEARAPP_APP_ID
7
7
 
8
8
  const BroadcastMessageType = 'broadcast'
9
9
  const PublicDisplayMessageType = 'public_display'
10
+ const PrivateDisplayMessageType = 'private_display'
10
11
  const ActionMessageType = 'client_action'
11
12
  const CreateEventMessageType = 'create_event'
12
13
  const ExitEventMessageType = 'exit_event'
@@ -67,7 +68,7 @@ class AnearMessaging {
67
68
  await this.getAppInfo(AppId)
68
69
  logger.debug("Ably connected!")
69
70
  await this.setupCreateEventChannel()
70
- await this.reloadAnyEventsInProgress(AppId)
71
+ // await this.reloadAnyEventsInProgress(AppId) WHEN THIS WORKS or IS IMPORTANT...FIX!
71
72
  }
72
73
 
73
74
  this.realtime.connection.on("connected", connectedCallback)
@@ -476,16 +477,19 @@ class AnearMessaging {
476
477
  )
477
478
  }
478
479
 
479
- async publishEventSpectatorsMessage(anearEvent, css, message, messageType = PublicDisplayMessageType) {
480
+ // you can pass in timeout params if you want the spectator display
481
+ // to show current anear-timer status
482
+ publishEventSpectatorsMessage(anearEvent, css, message, timeoutMsecs = 0, timeRemaining = 0) {
483
+
480
484
  const channel = this.eventChannels[anearEvent.id].spectators
481
485
 
482
- await this.publishMessage(
486
+ return this.publishMessage(
483
487
  channel,
484
- messageType,
488
+ PublicDisplayMessageType,
485
489
  css,
486
490
  message,
487
- 0,
488
- 0
491
+ timeoutMsecs,
492
+ timeRemaining
489
493
  )
490
494
  }
491
495
 
@@ -504,13 +508,13 @@ class AnearMessaging {
504
508
  return [startTimers, timeoutMsecs]
505
509
  }
506
510
 
507
- async publishEventParticipantsMessage(anearEvent, participants, css, message, timeoutMsecs=0) {
511
+ publishEventParticipantsMessage(anearEvent, participants, css, message, timeoutMsecs=0) {
508
512
  const eventId = anearEvent.id
509
513
  const channel = this.eventChannels[eventId].participants
510
514
 
511
515
  const [startTimers, timeRemaining] = this.setMultipleParticipantTimers(participants, timeoutMsecs)
512
516
 
513
- await this.publishMessage(
517
+ const promise = this.publishMessage(
514
518
  channel,
515
519
  PublicDisplayMessageType,
516
520
  css,
@@ -518,13 +522,15 @@ class AnearMessaging {
518
522
  timeoutMsecs,
519
523
  timeRemaining
520
524
  )
525
+
521
526
  startTimers()
527
+
528
+ return promise
522
529
  }
523
530
 
524
- async publishEventPrivateMessage(
531
+ publishEventPrivateMessage(
525
532
  anearEvent,
526
533
  participant,
527
- messageType,
528
534
  css,
529
535
  message,
530
536
  timeoutMsecs=0) {
@@ -535,18 +541,21 @@ class AnearMessaging {
535
541
 
536
542
  const [startTimer, timeRemaining] = participant.ensureTimer(timeoutMsecs)
537
543
 
538
- await this.publishMessage(
544
+ const promise = this.publishMessage(
539
545
  channel,
540
- messageType,
546
+ PrivateDisplayMessageType,
541
547
  css,
542
548
  message,
543
549
  timeoutMsecs,
544
550
  timeRemaining
545
551
  )
552
+
546
553
  startTimer()
554
+
555
+ return promise
547
556
  }
548
557
 
549
- async publishMessage(
558
+ publishMessage(
550
559
  channel,
551
560
  messageType,
552
561
  css,
@@ -562,24 +571,24 @@ class AnearMessaging {
562
571
 
563
572
  logger.debug(`publishMessage(timeoutMsecs=${timeoutMsecs}}, timeRemaining=${timeRemaining})`)
564
573
 
565
- await this.publishChannelMessage(
574
+ return this.publishChannelMessage(
566
575
  channel,
567
576
  messageType,
568
577
  payload
569
578
  )
570
579
  }
571
580
 
572
- async publishEventTransitionMessage(anearEvent, newState) {
581
+ publishEventTransitionMessage(anearEvent, newState) {
573
582
  const channel = this.eventChannels[anearEvent.id].events
574
583
  const payload = {content: {state: newState}}
575
584
 
576
585
  logger.debug(`publishEventTransitionMessage: event ${anearEvent.id} transitioning to ${newState}`)
577
586
 
578
- await this.publishChannelMessage(channel, EventTransitionMessageType, payload)
587
+ return this.publishChannelMessage(channel, EventTransitionMessageType, payload)
579
588
  }
580
589
 
581
- async publishChannelMessage(channel, messageType, payload) {
582
- await channel.publish(
590
+ publishChannelMessage(channel, messageType, payload) {
591
+ return channel.publish(
583
592
  messageType,
584
593
  payload
585
594
  )
@@ -8,8 +8,6 @@ const JsonApiResource = require('./JsonApiResource')
8
8
  const Participants = require('../utils/Participants')
9
9
  const logger = require('../utils/Logger')
10
10
 
11
- const PrivateDisplayMessageType = 'private_display'
12
-
13
11
  const PlayableStates = ['closing', 'closed', 'canceled']
14
12
 
15
13
  class AnearEvent extends JsonApiResource {
@@ -152,15 +150,14 @@ class AnearEvent extends JsonApiResource {
152
150
  logger.debug(`mutex ${name} released!`)
153
151
  }
154
152
 
155
- publishEventSpectatorsMessage(message) {
156
- return this.messaging.publishEventSpectatorsMessage(this, this.css, message)
153
+ publishEventSpectatorsMessage(message, timeoutMsecs = 0) {
154
+ return this.messaging.publishEventSpectatorsMessage(this, this.css, message, timeoutMsecs)
157
155
  }
158
156
 
159
157
  publishEventPrivateMessage(participant, message, timeoutMsecs=0) {
160
158
  return this.messaging.publishEventPrivateMessage(
161
159
  this,
162
160
  participant,
163
- PrivateDisplayMessageType,
164
161
  this.css,
165
162
  message,
166
163
  timeoutMsecs
@@ -84,6 +84,10 @@ class AnearParticipant extends JsonApiResource {
84
84
  return this.attributes['private-channel-name']
85
85
  }
86
86
 
87
+ get timerStatus() {
88
+ return this.timer.currentStatus
89
+ }
90
+
87
91
  ensureTimer(timeoutMsecs) {
88
92
  // this is called when a new timer is being started for a privateMessage
89
93
  // sent to a participant, or public message to all participants
@@ -20,6 +20,14 @@ class ParticipantTimer {
20
20
  this.runTimer(now, timeoutMsecs)
21
21
  }
22
22
 
23
+ get currentStatus() {
24
+ return {
25
+ state: this.state,
26
+ timeoutMsecs: this.timeoutMsecs,
27
+ timeRemaining: this.interrupt()
28
+ }
29
+ }
30
+
23
31
  timerExpired() {
24
32
  logger.debug(`TIMEOUT!! timer expired for participant ${this.participantId}`)
25
33
  this.state = Expired
@@ -28,6 +36,7 @@ class ParticipantTimer {
28
36
 
29
37
  runTimer(now, timeoutMsecs) {
30
38
  this.startedAt = now
39
+ this.timeoutMsecs = timeoutMsecs // original timeout duration
31
40
  this.timeRemaining = timeoutMsecs
32
41
  this.state = Running
33
42
  this.id = setTimeout(() => this.timerExpired(), timeoutMsecs)
@@ -80,6 +89,8 @@ class ParticipantTimer {
80
89
  this.id = null
81
90
  this.state = Off
82
91
  this.startedAt = null
92
+ this.timeoutMsecs = 0
93
+ this.timeRemaining = 0
83
94
  }
84
95
 
85
96
  checkTimerIs(state) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anear-js-api",
3
- "version": "0.4.9",
3
+ "version": "0.4.11",
4
4
  "description": "Javascript Developer API for Anear Apps",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {