anear-js-api 0.3.16 → 0.3.19

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.
@@ -18,8 +18,6 @@ const PRESENCE_ENTER = 'enter'
18
18
  const PRESENCE_LEAVE = 'leave'
19
19
  const ALREADY_PRESENT = 'present'
20
20
 
21
- // any channel messages sent with 5 secs (5s) of initial attach will be delivered
22
- // to the subscribers
23
21
  const ChannelParams = {params: {rewind: "5s"}}
24
22
 
25
23
 
@@ -261,7 +259,7 @@ class AnearMessaging {
261
259
 
262
260
  return Promise.all(
263
261
  allParticipants.map(
264
- async participant => await this.processParticipantEnter(
262
+ participant => this.processParticipantEnter(
265
263
  anearEvent,
266
264
  participant.id,
267
265
  participant.geoLocation
@@ -316,11 +314,16 @@ class AnearMessaging {
316
314
 
317
315
  await this.attachChannel(actionsChannel)
318
316
 
319
- await this.subscribePresenceEventWithHistory(
317
+ this.subscribePresenceEvent(
320
318
  actionsChannel,
321
319
  PRESENCE_ENTER,
322
320
  async message => await this.participantEnterMessagingCallback(anearEvent, message)
323
321
  )
322
+ this.subscribePresenceEvent(
323
+ actionsChannel,
324
+ ALREADY_PRESENT,
325
+ async message => await this.participantEnterMessagingCallback(anearEvent, message)
326
+ )
324
327
  this.subscribeEventMessages(
325
328
  actionsChannel,
326
329
  ActionMessageType,
@@ -166,7 +166,7 @@ class AnearEvent extends JsonApiResource {
166
166
  async publishEventParticipantsMessage(message, timeoutMsecs=0) {
167
167
  await this.messaging.publishEventParticipantsMessage(
168
168
  this,
169
- this.participants.active,
169
+ this.participants.active(),
170
170
  this.css,
171
171
  message,
172
172
  timeoutMsecs
@@ -23,9 +23,6 @@ class Participants {
23
23
  this._host = init.host
24
24
  this.idleMsecs = init.idleMsecs // how long Active participants
25
25
  this.purgeMsecs = init.purgeMsecs
26
-
27
- this._actives = null // cached participants who are ActiveState
28
- this._idles = null // cached participants who are IdleState
29
26
  }
30
27
 
31
28
  toJSON() {
@@ -63,28 +60,24 @@ class Participants {
63
60
  sort((ca, cb) => ca.timestamp - cb.timestamp)
64
61
  }
65
62
 
66
- active(cached = true) {
67
- if (!cached) this._actives = null
68
- this._actives = this._actives || Object.values(this._participants).filter(c => c.state === ActiveState)
69
- return this._actives
63
+ active() {
64
+ return Object.values(this._participants).filter(c => c.state === ActiveState)
70
65
  }
71
66
 
72
- idle(cached = true) {
73
- if (!cached) this._idles = null
74
- this._idles = this._idles || Object.values(this._participants).filter(c => c.state === IdleState)
75
- return this._idles
67
+ idle() {
68
+ return Object.values(this._participants).filter(c => c.state === IdleState)
76
69
  }
77
70
 
78
71
  get count() {
79
72
  return Object.keys(this._participants).length
80
73
  }
81
74
 
82
- numActive(cached = true) {
83
- return this.active(cached).length
75
+ numActive() {
76
+ return this.active().length
84
77
  }
85
78
 
86
- numIdle(cached = true) {
87
- return this.idle(cached).length
79
+ numIdle() {
80
+ return this.idle().length
88
81
  }
89
82
 
90
83
  isIdle(c, currentTimestamp) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anear-js-api",
3
- "version": "0.3.16",
3
+ "version": "0.3.19",
4
4
  "description": "Javascript Developer API for Anear Apps",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {