anear-js-api 0.6.4 → 0.6.5

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.
@@ -47,6 +47,10 @@ class AnearEvent extends JsonApiResource {
47
47
  this.send("CLOSE")
48
48
  }
49
49
 
50
+ restartEvent() {
51
+ this.send("RESTART")
52
+ }
53
+
50
54
  pauseEvent(context, resumeEvent = { type: 'RESUME' }) {
51
55
  // Persist via AEM and acknowledge with PAUSED
52
56
  this.send('PAUSE', { appmContext: { context, resumeEvent } })
@@ -133,6 +133,7 @@ const DeferredStates = [
133
133
  'ACTION',
134
134
  'CANCEL',
135
135
  'CLOSE',
136
+ 'RESTART',
136
137
  'SAVE',
137
138
  'PAUSE'
138
139
  ]
@@ -144,6 +145,10 @@ const ActiveEventGlobalEvents = {
144
145
  // the AnearParticipantMachine has hit its final state
145
146
  actions: ['cleanupExitingParticipant']
146
147
  },
148
+ RESTART: {
149
+ // Hosted apps can request a rewind back to ANNOUNCE without terminating the event.
150
+ target: '#activeEvent.restartEvent'
151
+ },
147
152
  CLOSE: {
148
153
  // AppM has reached a final state or explicitly called closeEvent()
149
154
  // initiate orderly shutdown
@@ -702,6 +707,18 @@ const ActiveEventStatesConfig = {
702
707
  }
703
708
  }
704
709
  },
710
+ restartEvent: {
711
+ id: 'restartEvent',
712
+ deferred: DeferredStatesPlus('RENDER_DISPLAY'),
713
+ invoke: {
714
+ src: 'restartAndGetAttachedSpectators',
715
+ onDone: {
716
+ actions: ['sendSpectatorEnterToAppEventMachine', 'sendRestartedAckToAppMachine'],
717
+ target: '#waitingToStart'
718
+ },
719
+ onError: '#activeEvent.failure'
720
+ }
721
+ },
705
722
  closeEvent: {
706
723
  id: 'closeEvent',
707
724
  initial: 'notifyingParticipants',
@@ -1154,6 +1171,11 @@ const AnearEventMachineStatesConfig = eventId => ({
1154
1171
 
1155
1172
  const AnearEventMachineFunctions = ({
1156
1173
  actions: {
1174
+ sendRestartedAckToAppMachine: (context, _event) => {
1175
+ if (context.appEventMachine) {
1176
+ context.appEventMachine.send('RESTARTED')
1177
+ }
1178
+ },
1157
1179
  sendPausedAckToAppMachine: (context, _event) => {
1158
1180
  if (context.appEventMachine) {
1159
1181
  context.appEventMachine.send('PAUSED')
@@ -1701,6 +1723,28 @@ const AnearEventMachineFunctions = ({
1701
1723
  const [_, members] = await Promise.all([transitionPromise, membersPromise])
1702
1724
  return members
1703
1725
  },
1726
+ restartAndGetAttachedSpectators: async (context, _event) => {
1727
+ // Restart is a developer-only transition that rewinds the event back to ANNOUNCE
1728
+ // without terminating the event or detaching channels.
1729
+ await AnearApi.transitionEvent(context.anearEvent.id, 'restart')
1730
+
1731
+ const publishPromise = RealtimeMessaging.publish(
1732
+ context.eventChannel,
1733
+ 'EVENT_TRANSITION',
1734
+ { content: { state: 'announce' } }
1735
+ )
1736
+
1737
+ // If there is no spectators channel (event/app does not support spectators),
1738
+ // just publish the transition and return an empty spectator list.
1739
+ if (!context.spectatorsDisplayChannel) {
1740
+ await publishPromise
1741
+ return []
1742
+ }
1743
+
1744
+ const members = await RealtimeMessaging.getPresenceOnChannel(context.spectatorsDisplayChannel)
1745
+ await publishPromise
1746
+ return members
1747
+ },
1704
1748
  transitionToLive: (context, event) => {
1705
1749
  return AnearApi.transitionEvent(context.anearEvent.id, 'live')
1706
1750
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anear-js-api",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "description": "Javascript Developer API for Anear Apps",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {