anear-js-api 0.3.21 → 0.3.24

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.
@@ -128,6 +128,11 @@ class AnearMessaging {
128
128
  }
129
129
  }
130
130
 
131
+ resetAllParticipantTimers() {
132
+ // turns off all participant timers
133
+ Object.values(this.participantTimers).forEach(timer => timer.reset())
134
+ }
135
+
131
136
  interruptParticipantTimer(participantId) {
132
137
  const timer = this.participantTimers[participantId]
133
138
 
@@ -13,6 +13,10 @@ class AnearMessaging {
13
13
  async publishEventTransitionMessage(eventId, newState, callback) {
14
14
  return
15
15
  }
16
+
17
+ resetAllParticipantTimers() {
18
+ return
19
+ }
16
20
  }
17
21
 
18
22
  module.exports = AnearMessaging
@@ -233,6 +233,10 @@ class AnearEvent extends JsonApiResource {
233
233
  this.anearStateMachine.sendTimeoutEvent({ participant })
234
234
  }
235
235
 
236
+ cancelParticipantTimers() {
237
+ this.messaging.resetAllParticipantTimers()
238
+ }
239
+
236
240
  async eventBroadcast(message) {
237
241
  await this.eventBroadcastEventCallback(message)
238
242
  }
@@ -277,10 +281,12 @@ class AnearEvent extends JsonApiResource {
277
281
  }
278
282
 
279
283
  async transitionClosed() {
284
+ this.cancelParticipantTimers()
280
285
  await this.transitionNextNext()
281
286
  }
282
287
 
283
288
  async transitionCanceled() {
289
+ this.cancelParticipantTimers()
284
290
  await this.transitionEvent('cancel')
285
291
  }
286
292
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anear-js-api",
3
- "version": "0.3.21",
3
+ "version": "0.3.24",
4
4
  "description": "Javascript Developer API for Anear Apps",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -358,3 +358,23 @@ test('can update state machine context via Action events', async () => {
358
358
  await t.participantClose(p2)
359
359
  await t.remove()
360
360
  })
361
+
362
+ test('can reset All ParticipantTimers', async () => {
363
+ const t = newTestEvent(false)
364
+ const p1 = new TestPlayer(chatParticipant1)
365
+ const p2 = new TestPlayer(chatParticipant2)
366
+
367
+ const resetMock = jest.spyOn(MessagingStub, "resetAllParticipantTimers");
368
+
369
+ await t.participantEnter(p1)
370
+ await t.participantEnter(p2)
371
+ await t.persist()
372
+
373
+ t.cancelParticipantTimers()
374
+
375
+ expect(resetMock).toHaveBeenCalledTimes(1)
376
+
377
+ await t.participantClose(p1)
378
+ await t.participantClose(p2)
379
+ await t.remove()
380
+ })