websocket.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { ExternalGroupProviderType } from '~/features/external-user-group/interfaces/external-user-group';
  2. const generateGroupSyncEvents = () => {
  3. const events = {};
  4. Object.values(ExternalGroupProviderType).forEach((provider) => {
  5. events[provider] = {
  6. GroupSyncProgress: `${provider}:groupSyncProgress`,
  7. GroupSyncCompleted: `${provider}:groupSyncCompleted`,
  8. GroupSyncFailed: `${provider}:groupSyncFailed`,
  9. };
  10. });
  11. return events as {
  12. [key in ExternalGroupProviderType]: {
  13. GroupSyncProgress: string,
  14. GroupSyncCompleted: string,
  15. GroupSyncFailed: string,
  16. }
  17. };
  18. };
  19. export const SocketEventName = {
  20. // Update descendantCount
  21. UpdateDescCount: 'UpdateDescCount',
  22. // Public migration
  23. PMStarted: 'PublicMigrationStarted',
  24. PMMigrating: 'PublicMigrationMigrating',
  25. PMErrorCount: 'PublicMigrationErrorCount',
  26. PMEnded: 'PublicMigrationEnded',
  27. // Page migration
  28. PageMigrationSuccess: 'PageMigrationSuccess',
  29. PageMigrationError: 'PageMigrationError',
  30. // Elasticsearch
  31. AddPageProgress: 'addPageProgress',
  32. FinishAddPage: 'finishAddPage',
  33. RebuildingFailed: 'rebuildingFailed',
  34. // External user group sync
  35. externalUserGroup: generateGroupSyncEvents(),
  36. // room per pageId
  37. JoinPage: 'join:page',
  38. LeavePage: 'leave:page',
  39. // Page Operation
  40. PageCreated: 'page:create',
  41. PageUpdated: 'page:update',
  42. PageDeleted: 'page:delete',
  43. // Yjs
  44. YjsAwarenessStateSizeUpdated: 'yjs:awareness-state-size-update',
  45. YjsHasRevisionBodyDiffUpdated: 'yjs:has-revision-body-diff-update',
  46. } as const;
  47. export type SocketEventName = typeof SocketEventName[keyof typeof SocketEventName];
  48. type PageId = string;
  49. type DescendantCount = number;
  50. /**
  51. * Data of updateDescCount when used through socket.io. Convert to UpdateDescCountData type when use with swr cache.
  52. */
  53. export type UpdateDescCountRawData = Record<PageId, DescendantCount>;
  54. export type UpdateDescCountData = Map<PageId, DescendantCount>;
  55. export type PMStartedData = { total: number };
  56. export type PMMigratingData = { count: number };
  57. export type PMErrorCountData = { skip: number };
  58. export type PMEndedData = { isSucceeded: boolean };
  59. export type PageMigrationErrorData = { paths: string[] }