websocket.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. YjsHasYdocsNewerThanLatestRevisionUpdated:
  46. 'yjs:has-ydocs-newer-than-latest-revision-update',
  47. } as const;
  48. export type SocketEventName =
  49. (typeof SocketEventName)[keyof typeof SocketEventName];
  50. type PageId = string;
  51. type DescendantCount = number;
  52. /**
  53. * Data of updateDescCount when used through socket.io. Convert to UpdateDescCountData type when use with swr cache.
  54. */
  55. export type UpdateDescCountRawData = Record<PageId, DescendantCount>;
  56. export type UpdateDescCountData = Map<PageId, DescendantCount>;
  57. export type PMStartedData = { total: number };
  58. export type PMMigratingData = { count: number };
  59. export type PMErrorCountData = { skip: number };
  60. export type PMEndedData = { isSucceeded: boolean };
  61. export type PageMigrationErrorData = { paths: string[] };