@seafile/sdoc-editor 0.3.8 → 0.3.9

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.
@@ -4,6 +4,8 @@ import context from '../../../context';
4
4
  import { User } from '../../../model';
5
5
  import toaster from '../../../components/toast';
6
6
  import { getErrorMsg } from '../../../utils';
7
+ import { EventBus } from '../../../basic-sdk';
8
+ import { EXTERNAL_EVENT } from '../../../constants';
7
9
  const ParticipantsContext = React.createContext(null);
8
10
  export const ParticipantsProvider = props => {
9
11
  const isSdocRevision = context.getSetting('isSdocRevision');
@@ -37,6 +39,12 @@ export const ParticipantsProvider = props => {
37
39
  });
38
40
  // eslint-disable-next-line react-hooks/exhaustive-deps
39
41
  }, [updateLocalParticipants, participants]);
42
+ const deleteLocalParticipant = useCallback(email => {
43
+ if (!participants.find(participant => participant.username === email)) return;
44
+ let newParticipants = participants.slice(0);
45
+ newParticipants = newParticipants.filter(participant => participant.username !== email);
46
+ setParticipants(newParticipants);
47
+ }, [participants]);
40
48
  const deleteParticipant = useCallback(email => {
41
49
  if (!participants.find(participant => participant.username === email)) return;
42
50
  context.deleteParticipants(email).then(res => {
@@ -57,6 +65,15 @@ export const ParticipantsProvider = props => {
57
65
  }).catch(error => {});
58
66
  // eslint-disable-next-line react-hooks/exhaustive-deps
59
67
  }, []);
68
+ useEffect(() => {
69
+ const eventBus = EventBus.getInstance();
70
+ const unsubscribeParticipantAdded = eventBus.subscribe(EXTERNAL_EVENT.PARTICIPANT_ADDED, updateLocalParticipants);
71
+ const unsubscribeParticipantRemoved = eventBus.subscribe(EXTERNAL_EVENT.PARTICIPANT_REMOVED, deleteLocalParticipant);
72
+ return () => {
73
+ unsubscribeParticipantAdded();
74
+ unsubscribeParticipantRemoved();
75
+ };
76
+ }, [updateLocalParticipants, deleteLocalParticipant]);
60
77
  return /*#__PURE__*/React.createElement(ParticipantsContext.Provider, {
61
78
  value: {
62
79
  participants,
@@ -150,6 +150,14 @@ class SocketClient {
150
150
  const socketManager = SocketManager.getInstance();
151
151
  socketManager.receiveNewNotification(notification);
152
152
  };
153
+ this.receiveParticipantAdded = uses => {
154
+ const socketManager = SocketManager.getInstance();
155
+ socketManager.receiveParticipantAdded(uses);
156
+ };
157
+ this.receiveParticipantRemoved = email => {
158
+ const socketManager = SocketManager.getInstance();
159
+ socketManager.receiveParticipantRemoved(email);
160
+ };
153
161
  this.config = config;
154
162
  this.isReconnect = false;
155
163
  this.socket = io(config.sdocServer, {
@@ -180,6 +188,10 @@ class SocketClient {
180
188
 
181
189
  // notification
182
190
  this.socket.on('new-notification', this.receiveNewNotification);
191
+
192
+ // participant
193
+ this.socket.on('participant-added', this.receiveParticipantAdded);
194
+ this.socket.on('participant-removed', this.receiveParticipantRemoved);
183
195
  this.socket.io.on('reconnect', this.onReconnect);
184
196
  this.socket.io.on('reconnect_attempt', this.onReconnectAttempt);
185
197
  this.socket.io.on('reconnect_error', this.onReconnectError);
@@ -339,6 +339,12 @@ class SocketManager {
339
339
  this.closeSocketConnect = () => {
340
340
  this.socketClient.disconnectWithServer();
341
341
  };
342
+ this.receiveParticipantAdded = uses => {
343
+ this.eventBus.dispatch(EXTERNAL_EVENT.PARTICIPANT_ADDED, uses);
344
+ };
345
+ this.receiveParticipantRemoved = email => {
346
+ this.eventBus.dispatch(EXTERNAL_EVENT.PARTICIPANT_REMOVED, email);
347
+ };
342
348
  this.editor = editor;
343
349
  this.document = _document;
344
350
  this.socketClient = new SocketClient(config);
@@ -11,7 +11,9 @@ export const EXTERNAL_EVENT = {
11
11
  DOCUMENT_REPLACED_ERROR: 'document_replaced_error',
12
12
  REMOVE_DOCUMENT: 'remove_document',
13
13
  REMOVE_DOCUMENT_ERROR: 'remove_document_error',
14
- NEW_NOTIFICATION: 'new_notification'
14
+ NEW_NOTIFICATION: 'new_notification',
15
+ PARTICIPANT_ADDED: 'participant-added',
16
+ PARTICIPANT_REMOVED: 'participant-removed'
15
17
  };
16
18
  export const TIP_TYPE = {
17
19
  DELETE_NO_CHANGES_REVISION: 'delete_no_changes_revision',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",