|
1 | 1 | import { |
2 | | - LiveMessageEvent, |
3 | 2 | LiveMessage, |
4 | 3 | Module, |
5 | 4 | Directory, |
6 | 5 | Selection, |
| 6 | + LiveDisconnectReason, |
7 | 7 | } from '@codesandbox/common/lib/types'; |
8 | 8 | import { mutate, json } from 'overmind'; |
9 | 9 | import { Operator } from 'app/overmind'; |
10 | 10 | import { camelizeKeys } from 'humps'; |
11 | 11 | import { NotificationStatus } from '@codesandbox/notifications/lib/state'; |
12 | 12 |
|
13 | | -export const onJoin: Operator<LiveMessage<LiveMessageEvent.JOIN>> = mutate( |
14 | | - ({ effects, state }) => { |
15 | | - effects.notificationToast.success( |
16 | | - state.live.isTeam ? 'Connected to Live Team!' : 'Connected to Live!' |
17 | | - ); |
| 13 | +export const onJoin: Operator< |
| 14 | + LiveMessage<{ status: 'connected'; live_user_id: string }> |
| 15 | +> = mutate(({ effects, state }, { data }) => { |
| 16 | + state.live.liveUserId = data.live_user_id; |
18 | 17 |
|
19 | | - if (state.live.reconnecting) { |
20 | | - effects.live.getAllClients().forEach(client => { |
21 | | - client.serverReconnect(); |
22 | | - }); |
23 | | - } |
| 18 | + effects.notificationToast.success( |
| 19 | + state.live.isTeam ? 'Connected to Live Team!' : 'Connected to Live!' |
| 20 | + ); |
24 | 21 |
|
25 | | - state.live.reconnecting = false; |
| 22 | + if (state.live.reconnecting) { |
| 23 | + effects.live.getAllClients().forEach(client => { |
| 24 | + client.serverReconnect(); |
| 25 | + }); |
26 | 26 | } |
27 | | -); |
| 27 | + |
| 28 | + state.live.reconnecting = false; |
| 29 | +}); |
28 | 30 |
|
29 | 31 | export const onModuleState: Operator< |
30 | 32 | LiveMessage<{ |
@@ -84,12 +86,14 @@ export const onUserLeft: Operator< |
84 | 86 | const { users } = state.live.roomInfo; |
85 | 87 | const user = users ? users.find(u => u.id === data.left_user_id) : null; |
86 | 88 |
|
87 | | - effects.notificationToast.add({ |
88 | | - message: user |
89 | | - ? `${user.username} left the live session.` |
90 | | - : 'Someone left the live session', |
91 | | - status: NotificationStatus.NOTICE, |
92 | | - }); |
| 89 | + if (user.id !== state.live.liveUserId) { |
| 90 | + effects.notificationToast.add({ |
| 91 | + message: user |
| 92 | + ? `${user.username} left the live session.` |
| 93 | + : 'Someone left the live session', |
| 94 | + status: NotificationStatus.NOTICE, |
| 95 | + }); |
| 96 | + } |
93 | 97 | } |
94 | 98 |
|
95 | 99 | actions.live.internal.clearUserSelections(data.left_user_id); |
@@ -397,12 +401,9 @@ export const onConnectionLoss: Operator<LiveMessage> = mutate( |
397 | 401 | ); |
398 | 402 |
|
399 | 403 | export const onDisconnect: Operator< |
400 | | - LiveMessage<{ |
401 | | - reason: string; |
402 | | - }> |
| 404 | + LiveMessage<{ reason: LiveDisconnectReason }> |
403 | 405 | > = mutate(({ state, actions }, { data }) => { |
404 | 406 | actions.live.internal.disconnect(); |
405 | | - |
406 | 407 | state.editor.currentSandbox.owned = state.live.isOwner; |
407 | 408 |
|
408 | 409 | actions.modalOpened({ |
|
0 commit comments