anear-js-api 0.4.26 → 0.4.28
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.
|
@@ -103,22 +103,61 @@ const ActiveEventStatesConfig = {
|
|
|
103
103
|
initial: 'registerCreator',
|
|
104
104
|
states: {
|
|
105
105
|
registerCreator: {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
106
|
+
// First, while continuing to defer any PARTICIPANT_ENTERs, see if the creator presence
|
|
107
|
+
// is available via channel.get() and if not, we will get the PARTICIPANT_ENTER at the
|
|
108
|
+
// right time in waiting where the deferred is not active.
|
|
109
|
+
initial: 'loading',
|
|
110
|
+
states: {
|
|
111
|
+
loading: {
|
|
112
|
+
deferred: DeferredStates,
|
|
113
|
+
invoke: {
|
|
114
|
+
src: 'getAttachedCreatorOrHost',
|
|
115
|
+
onDone: {
|
|
116
|
+
// event.data.anearParticipant will be null if no presence enter
|
|
117
|
+
// was available on actions channel via get(). We must wait for
|
|
118
|
+
// the undeferred PARTICIPANT_ENTER instead. But if get() DID
|
|
119
|
+
// return the creator presence, then an APM will be created
|
|
120
|
+
// and we goto waiting for the PARTICIPANT_MACHINE_READY
|
|
121
|
+
actions: ['startNewParticipantMachine'],
|
|
122
|
+
target: 'waiting'
|
|
123
|
+
},
|
|
124
|
+
onError: {
|
|
125
|
+
target: '#failure'
|
|
126
|
+
}
|
|
127
|
+
}
|
|
113
128
|
},
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
129
|
+
waiting: {
|
|
130
|
+
id: 'waiting',
|
|
131
|
+
initial: 'creatorStatus',
|
|
132
|
+
states: {
|
|
133
|
+
creatorStatus: {
|
|
134
|
+
id: 'creatorStatus',
|
|
135
|
+
on: {
|
|
136
|
+
PARTICIPANT_ENTER: {
|
|
137
|
+
actions: (c, e) => logger.debug("got creator PARTICIPANT_ENTER"),
|
|
138
|
+
target: '#waiting.fetching'
|
|
139
|
+
},
|
|
140
|
+
PARTICIPANT_MACHINE_READY: {
|
|
141
|
+
actions: (c, e) => logger.debug("Got PARTICIPANT_MACHINE_READY for ", e.data.anearParticipant.id),
|
|
142
|
+
target: '#eventCreated'
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
fetching: {
|
|
147
|
+
id: 'fetching',
|
|
148
|
+
deferred: DeferredStates,
|
|
149
|
+
invoke: {
|
|
150
|
+
src: 'fetchParticipantData',
|
|
151
|
+
onDone: {
|
|
152
|
+
actions: ['startNewParticipantMachine'],
|
|
153
|
+
target: '#waiting.creatorStatus'
|
|
154
|
+
},
|
|
155
|
+
onError: {
|
|
156
|
+
target: '#activeEvent.failure'
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
122
161
|
}
|
|
123
162
|
}
|
|
124
163
|
},
|
|
@@ -137,7 +176,6 @@ const ActiveEventStatesConfig = {
|
|
|
137
176
|
initial: 'waitingAnnounce',
|
|
138
177
|
entry: [
|
|
139
178
|
'sendParticipantEnterToAppEventMachine',
|
|
140
|
-
'enableParticipantPresenceEvents',
|
|
141
179
|
'enableSpectatorPresenceEvents'
|
|
142
180
|
],
|
|
143
181
|
on: {
|
|
@@ -440,12 +478,12 @@ const CreateEventChannelsAndAppMachineConfig = {
|
|
|
440
478
|
// 6. Transition to activeEvent
|
|
441
479
|
id: 'createChannels',
|
|
442
480
|
initial: 'setupEventChannel',
|
|
481
|
+
deferred: DeferredStates, // don't allow PARTICIPANT_ENTER until we are registering creator/host
|
|
443
482
|
|
|
444
483
|
states: {
|
|
445
484
|
setupEventChannel: {
|
|
446
485
|
// get(eventChannelName) and setup state-change callbacks
|
|
447
486
|
entry: [(c,e) => logger.debug(`=== NEW EVENT ${c.anearEvent.id} ===`), 'createEventChannel'],
|
|
448
|
-
deferred: DeferredStates,
|
|
449
487
|
invoke: {
|
|
450
488
|
src: 'attachToEventChannel',
|
|
451
489
|
onDone: {
|
|
@@ -465,7 +503,6 @@ const CreateEventChannelsAndAppMachineConfig = {
|
|
|
465
503
|
},
|
|
466
504
|
setupParticipantsDisplayChannel: {
|
|
467
505
|
entry: 'createParticipantsDisplayChannel',
|
|
468
|
-
deferred: DeferredStates,
|
|
469
506
|
invoke: {
|
|
470
507
|
src: 'attachToParticipantsDisplayChannel',
|
|
471
508
|
onDone: {
|
|
@@ -477,12 +514,13 @@ const CreateEventChannelsAndAppMachineConfig = {
|
|
|
477
514
|
}
|
|
478
515
|
},
|
|
479
516
|
on: {
|
|
480
|
-
ATTACHED:
|
|
517
|
+
ATTACHED: {
|
|
518
|
+
target: 'setupActionsChannel'
|
|
519
|
+
}
|
|
481
520
|
}
|
|
482
521
|
},
|
|
483
522
|
setupActionsChannel: {
|
|
484
523
|
entry: 'createActionsChannel',
|
|
485
|
-
deferred: DeferredStates,
|
|
486
524
|
invoke: {
|
|
487
525
|
src: 'attachToActionsChannel',
|
|
488
526
|
onDone: {
|
|
@@ -495,14 +533,13 @@ const CreateEventChannelsAndAppMachineConfig = {
|
|
|
495
533
|
},
|
|
496
534
|
on: {
|
|
497
535
|
ATTACHED: {
|
|
498
|
-
actions: ['subscribeToActionMessages'],
|
|
536
|
+
actions: ['enableParticipantPresenceEvents', 'subscribeToActionMessages'],
|
|
499
537
|
target: 'setupSpectatorsChannel'
|
|
500
538
|
}
|
|
501
539
|
}
|
|
502
540
|
},
|
|
503
541
|
setupSpectatorsChannel: {
|
|
504
542
|
entry: 'createSpectatorsChannel',
|
|
505
|
-
deferred: DeferredStates,
|
|
506
543
|
invoke: {
|
|
507
544
|
src: 'attachToSpectatorsChannel',
|
|
508
545
|
onDone: {
|
|
@@ -614,6 +651,8 @@ const AnearEventMachineFunctions = ({
|
|
|
614
651
|
startNewParticipantMachine: assign((context, event) => {
|
|
615
652
|
const { anearParticipant } = event.data
|
|
616
653
|
|
|
654
|
+
if (!anearParticipant) return {}
|
|
655
|
+
|
|
617
656
|
if (context.participants[anearParticipant.id]) {
|
|
618
657
|
logger.debug(`participant entry for ${anearParticipant.id} already exists`)
|
|
619
658
|
return {}
|
|
@@ -840,7 +879,7 @@ const AnearEventMachineFunctions = ({
|
|
|
840
879
|
|
|
841
880
|
const members = await RealtimeMessaging.getPresenceOnChannel(context.actionsChannel)
|
|
842
881
|
|
|
843
|
-
if (members.length === 0)
|
|
882
|
+
if (members.length === 0) return { anearParticipant: null }
|
|
844
883
|
|
|
845
884
|
// event.data in onDone actions is
|
|
846
885
|
// {
|
|
@@ -871,8 +910,8 @@ const AnearEventMachineFunctions = ({
|
|
|
871
910
|
},
|
|
872
911
|
fetchParticipantData: async (context, event) => {
|
|
873
912
|
// event.data => {id: <participantId>, geoLocation: {}}
|
|
874
|
-
const participantJSON = await AnearApi.getEventParticipantJson(event.id)
|
|
875
|
-
const anearParticipant = new AnearParticipant(participantJSON, event.geoLocation)
|
|
913
|
+
const participantJSON = await AnearApi.getEventParticipantJson(event.data.id)
|
|
914
|
+
const anearParticipant = new AnearParticipant(participantJSON, event.data.geoLocation)
|
|
876
915
|
|
|
877
916
|
return {
|
|
878
917
|
anearParticipant
|
|
@@ -199,7 +199,10 @@ const AnearParticipantMachineFunctions = {
|
|
|
199
199
|
return { privateChannel }
|
|
200
200
|
}),
|
|
201
201
|
sendParticipantReady: (context, event) => {
|
|
202
|
-
context.anearEvent.send(
|
|
202
|
+
context.anearEvent.send(
|
|
203
|
+
'PARTICIPANT_MACHINE_READY',
|
|
204
|
+
{ data: { anearParticipant: context.anearParticipant } }
|
|
205
|
+
)
|
|
203
206
|
},
|
|
204
207
|
createAnyAppParticipantMachine: assign({
|
|
205
208
|
appParticipantMachine: context => {
|
|
@@ -55,8 +55,9 @@ class RealtimeMessaging {
|
|
|
55
55
|
channel.presence.subscribe(
|
|
56
56
|
action,
|
|
57
57
|
member => {
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
const { data } = member
|
|
59
|
+
logger.debug(`sending machine event: rcvd presence ${eventName} from ${data.id} on ${channel.name}`)
|
|
60
|
+
actor.send(eventName, { data })
|
|
60
61
|
}
|
|
61
62
|
)
|
|
62
63
|
}
|