@abraca/nuxt 0.1.0
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.
- package/README.md +84 -0
- package/dist/module.d.mts +201 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +170 -0
- package/dist/runtime/components/ACollaborationUsers.d.vue.ts +11 -0
- package/dist/runtime/components/ACollaborationUsers.vue +48 -0
- package/dist/runtime/components/ACollaborationUsers.vue.d.ts +11 -0
- package/dist/runtime/components/AColorPicker.d.vue.ts +13 -0
- package/dist/runtime/components/AColorPicker.vue +71 -0
- package/dist/runtime/components/AColorPicker.vue.d.ts +13 -0
- package/dist/runtime/components/ACommandPalette.d.vue.ts +13 -0
- package/dist/runtime/components/ACommandPalette.vue +31 -0
- package/dist/runtime/components/ACommandPalette.vue.d.ts +13 -0
- package/dist/runtime/components/AConnectionStatus.d.vue.ts +13 -0
- package/dist/runtime/components/AConnectionStatus.vue +50 -0
- package/dist/runtime/components/AConnectionStatus.vue.d.ts +13 -0
- package/dist/runtime/components/ADocTypeSelect.d.vue.ts +10 -0
- package/dist/runtime/components/ADocTypeSelect.vue +34 -0
- package/dist/runtime/components/ADocTypeSelect.vue.d.ts +10 -0
- package/dist/runtime/components/ADocumentTree.d.vue.ts +53 -0
- package/dist/runtime/components/ADocumentTree.vue +350 -0
- package/dist/runtime/components/ADocumentTree.vue.d.ts +53 -0
- package/dist/runtime/components/AEditor.d.vue.ts +60 -0
- package/dist/runtime/components/AEditor.vue +174 -0
- package/dist/runtime/components/AEditor.vue.d.ts +60 -0
- package/dist/runtime/components/AFloatingWindow.d.vue.ts +24 -0
- package/dist/runtime/components/AFloatingWindow.vue +232 -0
- package/dist/runtime/components/AFloatingWindow.vue.d.ts +24 -0
- package/dist/runtime/components/AIconPicker.d.vue.ts +13 -0
- package/dist/runtime/components/AIconPicker.vue +257 -0
- package/dist/runtime/components/AIconPicker.vue.d.ts +13 -0
- package/dist/runtime/components/ANodePanel.d.vue.ts +15 -0
- package/dist/runtime/components/ANodePanel.vue +541 -0
- package/dist/runtime/components/ANodePanel.vue.d.ts +15 -0
- package/dist/runtime/components/ANotifications.d.vue.ts +7 -0
- package/dist/runtime/components/ANotifications.vue +75 -0
- package/dist/runtime/components/ANotifications.vue.d.ts +7 -0
- package/dist/runtime/components/APermissionGuard.d.vue.ts +21 -0
- package/dist/runtime/components/APermissionGuard.vue +22 -0
- package/dist/runtime/components/APermissionGuard.vue.d.ts +21 -0
- package/dist/runtime/components/APresence.d.vue.ts +43 -0
- package/dist/runtime/components/APresence.vue +36 -0
- package/dist/runtime/components/APresence.vue.d.ts +43 -0
- package/dist/runtime/components/AProvider.d.vue.ts +27 -0
- package/dist/runtime/components/AProvider.vue +42 -0
- package/dist/runtime/components/AProvider.vue.d.ts +27 -0
- package/dist/runtime/components/ARoleBadge.d.vue.ts +11 -0
- package/dist/runtime/components/ARoleBadge.vue +29 -0
- package/dist/runtime/components/ARoleBadge.vue.d.ts +11 -0
- package/dist/runtime/components/AVoiceBar.d.vue.ts +13 -0
- package/dist/runtime/components/AVoiceBar.vue +379 -0
- package/dist/runtime/components/AVoiceBar.vue.d.ts +13 -0
- package/dist/runtime/components/AVoiceTile.d.vue.ts +10 -0
- package/dist/runtime/components/AVoiceTile.vue +48 -0
- package/dist/runtime/components/AVoiceTile.vue.d.ts +10 -0
- package/dist/runtime/components/AWindowLayer.d.vue.ts +3 -0
- package/dist/runtime/components/AWindowLayer.vue +17 -0
- package/dist/runtime/components/AWindowLayer.vue.d.ts +3 -0
- package/dist/runtime/components/aware/AArea.d.vue.ts +42 -0
- package/dist/runtime/components/aware/AArea.vue +45 -0
- package/dist/runtime/components/aware/AArea.vue.d.ts +42 -0
- package/dist/runtime/components/aware/AAvatar.d.vue.ts +25 -0
- package/dist/runtime/components/aware/AAvatar.vue +86 -0
- package/dist/runtime/components/aware/AAvatar.vue.d.ts +25 -0
- package/dist/runtime/components/aware/AButton.d.vue.ts +7 -0
- package/dist/runtime/components/aware/AButton.vue +39 -0
- package/dist/runtime/components/aware/AButton.vue.d.ts +7 -0
- package/dist/runtime/components/aware/ACursorLabel.d.vue.ts +12 -0
- package/dist/runtime/components/aware/ACursorLabel.vue +44 -0
- package/dist/runtime/components/aware/ACursorLabel.vue.d.ts +12 -0
- package/dist/runtime/components/aware/ADocBadge.d.vue.ts +11 -0
- package/dist/runtime/components/aware/ADocBadge.vue +27 -0
- package/dist/runtime/components/aware/ADocBadge.vue.d.ts +11 -0
- package/dist/runtime/components/aware/AFacepile.d.vue.ts +20 -0
- package/dist/runtime/components/aware/AFacepile.vue +92 -0
- package/dist/runtime/components/aware/AFacepile.vue.d.ts +20 -0
- package/dist/runtime/components/aware/AInput.d.vue.ts +7 -0
- package/dist/runtime/components/aware/AInput.vue +44 -0
- package/dist/runtime/components/aware/AInput.vue.d.ts +7 -0
- package/dist/runtime/components/aware/ASelect.d.vue.ts +7 -0
- package/dist/runtime/components/aware/ASelect.vue +51 -0
- package/dist/runtime/components/aware/ASelect.vue.d.ts +7 -0
- package/dist/runtime/components/aware/ATextarea.d.vue.ts +7 -0
- package/dist/runtime/components/aware/ATextarea.vue +44 -0
- package/dist/runtime/components/aware/ATextarea.vue.d.ts +7 -0
- package/dist/runtime/components/aware/AUserList.d.vue.ts +17 -0
- package/dist/runtime/components/aware/AUserList.vue +72 -0
- package/dist/runtime/components/aware/AUserList.vue.d.ts +17 -0
- package/dist/runtime/components/renderers/ACalendarRenderer.d.vue.ts +8 -0
- package/dist/runtime/components/renderers/ACalendarRenderer.vue +154 -0
- package/dist/runtime/components/renderers/ACalendarRenderer.vue.d.ts +8 -0
- package/dist/runtime/components/renderers/AGalleryRenderer.d.vue.ts +8 -0
- package/dist/runtime/components/renderers/AGalleryRenderer.vue +88 -0
- package/dist/runtime/components/renderers/AGalleryRenderer.vue.d.ts +8 -0
- package/dist/runtime/components/renderers/AKanbanRenderer.d.vue.ts +8 -0
- package/dist/runtime/components/renderers/AKanbanRenderer.vue +179 -0
- package/dist/runtime/components/renderers/AKanbanRenderer.vue.d.ts +8 -0
- package/dist/runtime/components/renderers/AOutlineRenderer.d.vue.ts +8 -0
- package/dist/runtime/components/renderers/AOutlineRenderer.vue +180 -0
- package/dist/runtime/components/renderers/AOutlineRenderer.vue.d.ts +8 -0
- package/dist/runtime/components/renderers/ATableRenderer.d.vue.ts +8 -0
- package/dist/runtime/components/renderers/ATableRenderer.vue +191 -0
- package/dist/runtime/components/renderers/ATableRenderer.vue.d.ts +8 -0
- package/dist/runtime/composables/useAAField.d.ts +42 -0
- package/dist/runtime/composables/useAAField.js +62 -0
- package/dist/runtime/composables/useAbraLocale.d.ts +14 -0
- package/dist/runtime/composables/useAbraLocale.js +11 -0
- package/dist/runtime/composables/useAbracadabra.d.ts +11 -0
- package/dist/runtime/composables/useAbracadabra.js +3 -0
- package/dist/runtime/composables/useAbracadabraAuth.d.ts +23 -0
- package/dist/runtime/composables/useAbracadabraAuth.js +22 -0
- package/dist/runtime/composables/useAwareness.d.ts +22 -0
- package/dist/runtime/composables/useAwareness.js +48 -0
- package/dist/runtime/composables/useAwarenessPeers.d.ts +34 -0
- package/dist/runtime/composables/useAwarenessPeers.js +33 -0
- package/dist/runtime/composables/useBackgroundSync.d.ts +37 -0
- package/dist/runtime/composables/useBackgroundSync.js +73 -0
- package/dist/runtime/composables/useChat.d.ts +65 -0
- package/dist/runtime/composables/useChat.js +210 -0
- package/dist/runtime/composables/useChatUsers.d.ts +21 -0
- package/dist/runtime/composables/useChatUsers.js +39 -0
- package/dist/runtime/composables/useChildTree.d.ts +119 -0
- package/dist/runtime/composables/useChildTree.js +100 -0
- package/dist/runtime/composables/useCommandPalette.d.ts +58 -0
- package/dist/runtime/composables/useCommandPalette.js +94 -0
- package/dist/runtime/composables/useConnectionStatus.d.ts +17 -0
- package/dist/runtime/composables/useConnectionStatus.js +37 -0
- package/dist/runtime/composables/useDashboard.d.ts +3 -0
- package/dist/runtime/composables/useDashboard.js +23 -0
- package/dist/runtime/composables/useDocExport.d.ts +5 -0
- package/dist/runtime/composables/useDocExport.js +256 -0
- package/dist/runtime/composables/useDocImport.d.ts +10 -0
- package/dist/runtime/composables/useDocImport.js +227 -0
- package/dist/runtime/composables/useDocJump.d.ts +29 -0
- package/dist/runtime/composables/useDocJump.js +17 -0
- package/dist/runtime/composables/useDocumentPermissions.d.ts +20 -0
- package/dist/runtime/composables/useDocumentPermissions.js +33 -0
- package/dist/runtime/composables/useEditor.d.ts +45 -0
- package/dist/runtime/composables/useEditor.js +121 -0
- package/dist/runtime/composables/useEditorDragHandle.d.ts +26 -0
- package/dist/runtime/composables/useEditorDragHandle.js +219 -0
- package/dist/runtime/composables/useEditorMentions.d.ts +28 -0
- package/dist/runtime/composables/useEditorMentions.js +40 -0
- package/dist/runtime/composables/useEditorSuggestions.d.ts +18 -0
- package/dist/runtime/composables/useEditorSuggestions.js +45 -0
- package/dist/runtime/composables/useEditorToolbar.d.ts +22 -0
- package/dist/runtime/composables/useEditorToolbar.js +60 -0
- package/dist/runtime/composables/useFileBlobStore.d.ts +15 -0
- package/dist/runtime/composables/useFileBlobStore.js +22 -0
- package/dist/runtime/composables/useFileIndex.d.ts +20 -0
- package/dist/runtime/composables/useFileIndex.js +69 -0
- package/dist/runtime/composables/useFollowUser.d.ts +5 -0
- package/dist/runtime/composables/useFollowUser.js +40 -0
- package/dist/runtime/composables/useNotifications.d.ts +82 -0
- package/dist/runtime/composables/useNotifications.js +171 -0
- package/dist/runtime/composables/useOfflineUploadQueue.d.ts +90 -0
- package/dist/runtime/composables/useOfflineUploadQueue.js +33 -0
- package/dist/runtime/composables/usePasskeyAccounts.d.ts +32 -0
- package/dist/runtime/composables/usePasskeyAccounts.js +46 -0
- package/dist/runtime/composables/usePluginRegistry.d.ts +6 -0
- package/dist/runtime/composables/usePluginRegistry.js +3 -0
- package/dist/runtime/composables/useRendererBase.d.ts +186 -0
- package/dist/runtime/composables/useRendererBase.js +46 -0
- package/dist/runtime/composables/useSearchIndex.d.ts +20 -0
- package/dist/runtime/composables/useSearchIndex.js +104 -0
- package/dist/runtime/composables/useTrash.d.ts +50 -0
- package/dist/runtime/composables/useTrash.js +127 -0
- package/dist/runtime/composables/useVoice.d.ts +51 -0
- package/dist/runtime/composables/useVoice.js +220 -0
- package/dist/runtime/composables/useWindowManager.d.ts +122 -0
- package/dist/runtime/composables/useWindowManager.js +141 -0
- package/dist/runtime/composables/useYDoc.d.ts +142 -0
- package/dist/runtime/composables/useYDoc.js +172 -0
- package/dist/runtime/extensions/accordion.d.ts +3 -0
- package/dist/runtime/extensions/accordion.js +49 -0
- package/dist/runtime/extensions/badge.d.ts +2 -0
- package/dist/runtime/extensions/badge.js +39 -0
- package/dist/runtime/extensions/callout.d.ts +2 -0
- package/dist/runtime/extensions/callout.js +28 -0
- package/dist/runtime/extensions/card.d.ts +3 -0
- package/dist/runtime/extensions/card.js +53 -0
- package/dist/runtime/extensions/code-collapse.d.ts +2 -0
- package/dist/runtime/extensions/code-collapse.js +32 -0
- package/dist/runtime/extensions/code-group.d.ts +2 -0
- package/dist/runtime/extensions/code-group.js +17 -0
- package/dist/runtime/extensions/collapsible.d.ts +2 -0
- package/dist/runtime/extensions/collapsible.js +35 -0
- package/dist/runtime/extensions/document-header.d.ts +11 -0
- package/dist/runtime/extensions/document-header.js +82 -0
- package/dist/runtime/extensions/document-meta.d.ts +20 -0
- package/dist/runtime/extensions/document-meta.js +121 -0
- package/dist/runtime/extensions/document.d.ts +6 -0
- package/dist/runtime/extensions/document.js +6 -0
- package/dist/runtime/extensions/file-block.d.ts +15 -0
- package/dist/runtime/extensions/file-block.js +34 -0
- package/dist/runtime/extensions/file-drop.d.ts +6 -0
- package/dist/runtime/extensions/file-drop.js +65 -0
- package/dist/runtime/extensions/kbd.d.ts +2 -0
- package/dist/runtime/extensions/kbd.js +33 -0
- package/dist/runtime/extensions/prose-icon.d.ts +2 -0
- package/dist/runtime/extensions/prose-icon.js +33 -0
- package/dist/runtime/extensions/search-highlight.d.ts +10 -0
- package/dist/runtime/extensions/search-highlight.js +129 -0
- package/dist/runtime/extensions/steps.d.ts +2 -0
- package/dist/runtime/extensions/steps.js +32 -0
- package/dist/runtime/extensions/tabs.d.ts +3 -0
- package/dist/runtime/extensions/tabs.js +49 -0
- package/dist/runtime/extensions/views/AccordionItemView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/AccordionItemView.vue +41 -0
- package/dist/runtime/extensions/views/AccordionItemView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/AccordionView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/AccordionView.vue +22 -0
- package/dist/runtime/extensions/views/AccordionView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/BadgeView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/BadgeView.vue +23 -0
- package/dist/runtime/extensions/views/BadgeView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/CalloutView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/CalloutView.vue +43 -0
- package/dist/runtime/extensions/views/CalloutView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/CardGroupView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/CardGroupView.vue +22 -0
- package/dist/runtime/extensions/views/CardGroupView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/CardView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/CardView.vue +28 -0
- package/dist/runtime/extensions/views/CardView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/CodeCollapseView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/CodeCollapseView.vue +45 -0
- package/dist/runtime/extensions/views/CodeCollapseView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/CodeGroupView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/CodeGroupView.vue +53 -0
- package/dist/runtime/extensions/views/CodeGroupView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/CollapsibleView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/CollapsibleView.vue +42 -0
- package/dist/runtime/extensions/views/CollapsibleView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/FileNodeView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/FileNodeView.vue +140 -0
- package/dist/runtime/extensions/views/FileNodeView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/KbdView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/KbdView.vue +23 -0
- package/dist/runtime/extensions/views/KbdView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/ProseIconView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/ProseIconView.vue +23 -0
- package/dist/runtime/extensions/views/ProseIconView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/StepsView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/StepsView.vue +32 -0
- package/dist/runtime/extensions/views/StepsView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/TabsItemView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/TabsItemView.vue +22 -0
- package/dist/runtime/extensions/views/TabsItemView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/TabsView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/TabsView.vue +56 -0
- package/dist/runtime/extensions/views/TabsView.vue.d.ts +4 -0
- package/dist/runtime/locale.d.ts +134 -0
- package/dist/runtime/locale.js +119 -0
- package/dist/runtime/middleware/abracadabra-auth.d.ts +11 -0
- package/dist/runtime/middleware/abracadabra-auth.js +9 -0
- package/dist/runtime/plugin-abracadabra.client.d.ts +7 -0
- package/dist/runtime/plugin-abracadabra.client.js +898 -0
- package/dist/runtime/plugin-abracadabra.server.d.ts +2 -0
- package/dist/runtime/plugin-abracadabra.server.js +71 -0
- package/dist/runtime/plugin-registry.d.ts +34 -0
- package/dist/runtime/plugin-registry.js +83 -0
- package/dist/runtime/plugin-shared-globals.client.d.ts +2 -0
- package/dist/runtime/plugin-shared-globals.client.js +20 -0
- package/dist/runtime/plugins/core.plugin.d.ts +12 -0
- package/dist/runtime/plugins/core.plugin.js +179 -0
- package/dist/runtime/server/api/_abracadabra/render/[docId].get.d.ts +18 -0
- package/dist/runtime/server/api/_abracadabra/render/[docId].get.js +51 -0
- package/dist/runtime/server/api/_abracadabra/spaces.get.d.ts +11 -0
- package/dist/runtime/server/api/_abracadabra/spaces.get.js +16 -0
- package/dist/runtime/server/plugins/abracadabra-service.d.ts +2 -0
- package/dist/runtime/server/plugins/abracadabra-service.js +116 -0
- package/dist/runtime/server/runners/doc-tree-cache.d.ts +11 -0
- package/dist/runtime/server/runners/doc-tree-cache.js +65 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/server/utils/docCache.d.ts +25 -0
- package/dist/runtime/server/utils/docCache.js +131 -0
- package/dist/runtime/server/utils/serverRunner.d.ts +28 -0
- package/dist/runtime/server/utils/serverRunner.js +58 -0
- package/dist/runtime/types.d.ts +444 -0
- package/dist/runtime/types.js +93 -0
- package/dist/runtime/utils/VoiceClient.d.ts +94 -0
- package/dist/runtime/utils/VoiceClient.js +599 -0
- package/dist/runtime/utils/avatarStyle.d.ts +15 -0
- package/dist/runtime/utils/avatarStyle.js +20 -0
- package/dist/runtime/utils/colorPalettes.d.ts +13 -0
- package/dist/runtime/utils/colorPalettes.js +49 -0
- package/dist/runtime/utils/docTypes.d.ts +129 -0
- package/dist/runtime/utils/docTypes.js +116 -0
- package/dist/runtime/utils/markdownToYjs.d.ts +23 -0
- package/dist/runtime/utils/markdownToYjs.js +440 -0
- package/dist/runtime/utils/metaFieldDefinitions.d.ts +7 -0
- package/dist/runtime/utils/metaFieldDefinitions.js +182 -0
- package/dist/runtime/utils/voiceErrors.d.ts +33 -0
- package/dist/runtime/utils/voiceErrors.js +54 -0
- package/dist/runtime/utils/yjsConvert.d.ts +14 -0
- package/dist/runtime/utils/yjsConvert.js +331 -0
- package/dist/types.d.mts +13 -0
- package/package.json +100 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { shallowRef, computed, watch, watchEffect } from "vue";
|
|
2
|
+
import { useSmoothedCursors } from "./useYDoc.js";
|
|
3
|
+
import { useChildTree } from "./useChildTree.js";
|
|
4
|
+
export function useRendererBase(props) {
|
|
5
|
+
const { doc: rootDoc, userName, userColor, publicKeyB64 } = useAbracadabra();
|
|
6
|
+
const childProviderRef = shallowRef(null);
|
|
7
|
+
const childDoc = shallowRef(null);
|
|
8
|
+
watch(
|
|
9
|
+
() => props.childProvider,
|
|
10
|
+
(p) => {
|
|
11
|
+
childProviderRef.value = p;
|
|
12
|
+
childDoc.value = p?.document ?? null;
|
|
13
|
+
},
|
|
14
|
+
{ immediate: true }
|
|
15
|
+
);
|
|
16
|
+
const { cursors, states, setLocalState } = useSmoothedCursors(childProviderRef, "pos");
|
|
17
|
+
watchEffect(() => {
|
|
18
|
+
if (!childProviderRef.value) return;
|
|
19
|
+
const name = userName.value;
|
|
20
|
+
const color = userColor.value;
|
|
21
|
+
const publicKey = publicKeyB64.value;
|
|
22
|
+
if (name && publicKey) {
|
|
23
|
+
setLocalState({ user: { name, color, publicKey } });
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
const tree = useChildTree(rootDoc, props.docId);
|
|
27
|
+
const connectedUsers = computed(
|
|
28
|
+
() => states.value.map((s) => ({
|
|
29
|
+
clientId: s.clientId,
|
|
30
|
+
name: s.user?.name ?? "",
|
|
31
|
+
color: s.user?.color ?? "#888",
|
|
32
|
+
avatar: s.user?.avatar,
|
|
33
|
+
publicKey: s.user?.publicKey
|
|
34
|
+
}))
|
|
35
|
+
);
|
|
36
|
+
return {
|
|
37
|
+
childProviderRef,
|
|
38
|
+
childDoc,
|
|
39
|
+
rootDoc,
|
|
40
|
+
cursors,
|
|
41
|
+
states,
|
|
42
|
+
setLocalState,
|
|
43
|
+
tree,
|
|
44
|
+
connectedUsers
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useSearchIndex
|
|
3
|
+
*
|
|
4
|
+
* Full-text search over all synced documents. Wraps SearchIndex from @abraca/dabra.
|
|
5
|
+
* Watches BackgroundSync sync states and re-indexes docs when they sync.
|
|
6
|
+
* Initialized by the main plugin; destroyed on server switch.
|
|
7
|
+
*/
|
|
8
|
+
interface SearchResult {
|
|
9
|
+
docId: string;
|
|
10
|
+
score: number;
|
|
11
|
+
excerpt?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function _initSearchIndex(serverOrigin: string): void;
|
|
14
|
+
export declare function _destroySearchIndex(): void;
|
|
15
|
+
export declare function useSearchIndex(): {
|
|
16
|
+
search: (query: string, limit?: number) => Promise<SearchResult[]>;
|
|
17
|
+
isReady: import("vue").ComputedRef<boolean>;
|
|
18
|
+
indexedCount: import("vue").ComputedRef<number>;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { ref, computed, watch } from "vue";
|
|
2
|
+
import * as Y from "yjs";
|
|
3
|
+
let _searchIndex = null;
|
|
4
|
+
const _indexedVersions = /* @__PURE__ */ new Map();
|
|
5
|
+
const _isReady = ref(false);
|
|
6
|
+
const _indexedCount = ref(0);
|
|
7
|
+
let _stopWatcher = null;
|
|
8
|
+
function walkXmlForText(node, texts) {
|
|
9
|
+
for (const child of node.toArray()) {
|
|
10
|
+
if (child instanceof Y.XmlText) {
|
|
11
|
+
const t = child.toString().trim();
|
|
12
|
+
if (t) texts.push(t);
|
|
13
|
+
} else if (child instanceof Y.XmlElement) {
|
|
14
|
+
if (child.nodeName === "fileBlock") {
|
|
15
|
+
const filename = child.getAttribute("filename");
|
|
16
|
+
const mimeType = child.getAttribute("mimeType");
|
|
17
|
+
if (filename) texts.push(filename);
|
|
18
|
+
if (mimeType) texts.push(mimeType);
|
|
19
|
+
}
|
|
20
|
+
walkXmlForText(child, texts);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function extractDocTexts(ydoc, label, meta) {
|
|
25
|
+
const texts = [];
|
|
26
|
+
if (label) texts.push(label);
|
|
27
|
+
if (meta) {
|
|
28
|
+
const searchableFields = ["subtitle", "note", "url", "status", "geoDescription"];
|
|
29
|
+
for (const field of searchableFields) {
|
|
30
|
+
const val = meta[field];
|
|
31
|
+
if (typeof val === "string" && val.trim()) texts.push(val.trim());
|
|
32
|
+
}
|
|
33
|
+
if (Array.isArray(meta.tags)) {
|
|
34
|
+
const joined = meta.tags.filter((t) => typeof t === "string").join(" ");
|
|
35
|
+
if (joined) texts.push(joined);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const fragment = ydoc.getXmlFragment("default");
|
|
40
|
+
walkXmlForText(fragment, texts);
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
43
|
+
return texts;
|
|
44
|
+
}
|
|
45
|
+
export function _initSearchIndex(serverOrigin) {
|
|
46
|
+
import("@abraca/dabra").then(({ SearchIndex }) => {
|
|
47
|
+
_searchIndex = new SearchIndex(serverOrigin);
|
|
48
|
+
_isReady.value = true;
|
|
49
|
+
_indexedVersions.clear();
|
|
50
|
+
_indexedCount.value = 0;
|
|
51
|
+
_startWatcher();
|
|
52
|
+
}).catch(() => {
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
export function _destroySearchIndex() {
|
|
56
|
+
_stopWatcher?.();
|
|
57
|
+
_stopWatcher = null;
|
|
58
|
+
_searchIndex?.destroy();
|
|
59
|
+
_searchIndex = null;
|
|
60
|
+
_isReady.value = false;
|
|
61
|
+
_indexedVersions.clear();
|
|
62
|
+
_indexedCount.value = 0;
|
|
63
|
+
}
|
|
64
|
+
function _startWatcher() {
|
|
65
|
+
const { syncStates } = useBackgroundSync();
|
|
66
|
+
const { provider } = useAbracadabra();
|
|
67
|
+
const stop = watch(syncStates, async (states) => {
|
|
68
|
+
if (!_searchIndex) return;
|
|
69
|
+
const p = provider.value;
|
|
70
|
+
if (!p) return;
|
|
71
|
+
for (const [docId, state] of states.entries()) {
|
|
72
|
+
if (state.status !== "synced") continue;
|
|
73
|
+
const lastSynced = state.lastSynced ?? 0;
|
|
74
|
+
if (_indexedVersions.get(docId) === lastSynced) continue;
|
|
75
|
+
try {
|
|
76
|
+
const childProvider = await p.loadChild(docId);
|
|
77
|
+
await childProvider.ready;
|
|
78
|
+
const rootDoc = p.document;
|
|
79
|
+
const treeMap = rootDoc.getMap("doc-tree");
|
|
80
|
+
const entry = treeMap.get(docId);
|
|
81
|
+
const texts = extractDocTexts(childProvider.document, entry?.label ?? "", entry?.meta);
|
|
82
|
+
await _searchIndex.index(docId, texts);
|
|
83
|
+
_indexedVersions.set(docId, lastSynced);
|
|
84
|
+
_indexedCount.value = _indexedVersions.size;
|
|
85
|
+
} catch {
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}, { deep: false });
|
|
89
|
+
_stopWatcher = stop;
|
|
90
|
+
}
|
|
91
|
+
export function useSearchIndex() {
|
|
92
|
+
return {
|
|
93
|
+
search: async (query, limit = 15) => {
|
|
94
|
+
if (!_searchIndex) return [];
|
|
95
|
+
try {
|
|
96
|
+
return await _searchIndex.search(query, limit);
|
|
97
|
+
} catch {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
isReady: computed(() => _isReady.value),
|
|
102
|
+
indexedCount: computed(() => _indexedCount.value)
|
|
103
|
+
};
|
|
104
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useTrash
|
|
3
|
+
*
|
|
4
|
+
* Document trash management over the 'doc-trash' Y.Map.
|
|
5
|
+
* Supports moving docs (and descendants) to trash, restoring, permanent delete,
|
|
6
|
+
* and auto-purge of expired entries.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* const { trashedItems, moveToTrash, restoreFromTrash, emptyTrash } = useTrash()
|
|
10
|
+
*/
|
|
11
|
+
import type { ShallowRef } from 'vue';
|
|
12
|
+
import * as Y from 'yjs';
|
|
13
|
+
export interface TrashEntry {
|
|
14
|
+
label: string;
|
|
15
|
+
parentId: string | null;
|
|
16
|
+
order: number;
|
|
17
|
+
type?: string;
|
|
18
|
+
meta?: Record<string, any>;
|
|
19
|
+
deletedAt: number;
|
|
20
|
+
deletedBy?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function useTrash(rootDoc?: ShallowRef<Y.Doc | null>): {
|
|
23
|
+
trashMap: {
|
|
24
|
+
data: Record<string, TrashEntry>;
|
|
25
|
+
lastUpdateLocal: ShallowRef<boolean, boolean>;
|
|
26
|
+
set: (key: string, value: TrashEntry) => TrashEntry | undefined;
|
|
27
|
+
remove: (key: string) => void | undefined;
|
|
28
|
+
clear: () => void | undefined;
|
|
29
|
+
get: (key: string) => TrashEntry | undefined;
|
|
30
|
+
yMap: import("vue").ComputedRef<Y.Map<TrashEntry> | null>;
|
|
31
|
+
};
|
|
32
|
+
trashedItems: import("vue").ComputedRef<{
|
|
33
|
+
label: string;
|
|
34
|
+
parentId: string | null;
|
|
35
|
+
order: number;
|
|
36
|
+
type?: string;
|
|
37
|
+
meta?: Record<string, any>;
|
|
38
|
+
deletedAt: number;
|
|
39
|
+
deletedBy?: string;
|
|
40
|
+
id: string;
|
|
41
|
+
}[]>;
|
|
42
|
+
trashedCount: import("vue").ComputedRef<number>;
|
|
43
|
+
autoPurgeDays: import("vue").Ref<number, number>;
|
|
44
|
+
setAutoPurgeDays: (days: number) => void;
|
|
45
|
+
moveToTrash: (docId: string, deletedBy?: string) => void;
|
|
46
|
+
restoreFromTrash: (docId: string) => void;
|
|
47
|
+
permanentlyDelete: (docId: string) => void;
|
|
48
|
+
emptyTrash: () => void;
|
|
49
|
+
purgeExpired: () => void;
|
|
50
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { computed, ref } from "vue";
|
|
2
|
+
import { useSyncedMap } from "./useYDoc.js";
|
|
3
|
+
const TRASH_SETTINGS_KEY = "abracadabra_trash_settings";
|
|
4
|
+
function loadTrashSettings() {
|
|
5
|
+
try {
|
|
6
|
+
const raw = localStorage.getItem(TRASH_SETTINGS_KEY);
|
|
7
|
+
if (raw) return JSON.parse(raw);
|
|
8
|
+
} catch {
|
|
9
|
+
}
|
|
10
|
+
return { autoPurgeDays: 30 };
|
|
11
|
+
}
|
|
12
|
+
function saveTrashSettings(settings) {
|
|
13
|
+
try {
|
|
14
|
+
localStorage.setItem(TRASH_SETTINGS_KEY, JSON.stringify(settings));
|
|
15
|
+
} catch {
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function useTrash(rootDoc) {
|
|
19
|
+
const { doc: globalDoc, userName } = useAbracadabra();
|
|
20
|
+
const _doc = rootDoc ?? globalDoc;
|
|
21
|
+
const trashMap = useSyncedMap(_doc, "doc-trash");
|
|
22
|
+
const treeMap = useSyncedMap(_doc, "doc-tree");
|
|
23
|
+
const autoPurgeDays = ref(loadTrashSettings().autoPurgeDays);
|
|
24
|
+
function setAutoPurgeDays(days) {
|
|
25
|
+
autoPurgeDays.value = days;
|
|
26
|
+
saveTrashSettings({ autoPurgeDays: days });
|
|
27
|
+
}
|
|
28
|
+
const trashedItems = computed(
|
|
29
|
+
() => Object.entries(trashMap.data).map(([id, entry]) => ({ id, ...entry })).sort((a, b) => b.deletedAt - a.deletedAt)
|
|
30
|
+
);
|
|
31
|
+
const trashedCount = computed(() => Object.keys(trashMap.data).length);
|
|
32
|
+
function collectDescendants(id) {
|
|
33
|
+
const result = [id];
|
|
34
|
+
for (const [cid, entry] of Object.entries(treeMap.data)) {
|
|
35
|
+
if (entry.parentId === id) result.push(...collectDescendants(cid));
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
function moveToTrash(docId, deletedBy) {
|
|
40
|
+
const doc = _doc.value;
|
|
41
|
+
if (!doc) return;
|
|
42
|
+
const now = Date.now();
|
|
43
|
+
doc.transact(() => {
|
|
44
|
+
for (const id of collectDescendants(docId)) {
|
|
45
|
+
const entry = treeMap.get(id);
|
|
46
|
+
if (!entry) continue;
|
|
47
|
+
trashMap.set(id, {
|
|
48
|
+
label: entry.label || "Untitled",
|
|
49
|
+
parentId: entry.parentId,
|
|
50
|
+
order: entry.order ?? 0,
|
|
51
|
+
type: entry.type,
|
|
52
|
+
meta: entry.meta,
|
|
53
|
+
deletedAt: now,
|
|
54
|
+
deletedBy: deletedBy ?? userName.value
|
|
55
|
+
});
|
|
56
|
+
treeMap.remove(id);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function restoreFromTrash(docId) {
|
|
61
|
+
const doc = _doc.value;
|
|
62
|
+
if (!doc) return;
|
|
63
|
+
const entry = trashMap.get(docId);
|
|
64
|
+
if (!entry) return;
|
|
65
|
+
const { deletedAt } = entry;
|
|
66
|
+
doc.transact(() => {
|
|
67
|
+
const toRestore = Object.entries(trashMap.data).filter(([, e]) => Math.abs(e.deletedAt - deletedAt) < 1e3);
|
|
68
|
+
for (const [id, trashEntry] of toRestore) {
|
|
69
|
+
const parentExists = trashEntry.parentId === null || treeMap.get(trashEntry.parentId) !== void 0 || toRestore.some(([rid]) => rid === trashEntry.parentId);
|
|
70
|
+
treeMap.set(id, {
|
|
71
|
+
label: trashEntry.label,
|
|
72
|
+
parentId: parentExists ? trashEntry.parentId : null,
|
|
73
|
+
order: trashEntry.order,
|
|
74
|
+
type: trashEntry.type,
|
|
75
|
+
meta: trashEntry.meta
|
|
76
|
+
});
|
|
77
|
+
trashMap.remove(id);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function permanentlyDelete(docId) {
|
|
82
|
+
trashMap.remove(docId);
|
|
83
|
+
cleanupIDB(docId);
|
|
84
|
+
}
|
|
85
|
+
function emptyTrash() {
|
|
86
|
+
const doc = _doc.value;
|
|
87
|
+
if (!doc) return;
|
|
88
|
+
const ids = Object.keys(trashMap.data);
|
|
89
|
+
doc.transact(() => {
|
|
90
|
+
for (const id of ids) trashMap.remove(id);
|
|
91
|
+
});
|
|
92
|
+
for (const id of ids) cleanupIDB(id);
|
|
93
|
+
}
|
|
94
|
+
function purgeExpired() {
|
|
95
|
+
if (autoPurgeDays.value <= 0) return;
|
|
96
|
+
const cutoff = Date.now() - autoPurgeDays.value * 24 * 60 * 60 * 1e3;
|
|
97
|
+
const expired = Object.entries(trashMap.data).filter(([, e]) => e.deletedAt < cutoff).map(([id]) => id);
|
|
98
|
+
if (!expired.length) return;
|
|
99
|
+
const doc = _doc.value;
|
|
100
|
+
if (!doc) return;
|
|
101
|
+
doc.transact(() => {
|
|
102
|
+
for (const id of expired) trashMap.remove(id);
|
|
103
|
+
});
|
|
104
|
+
for (const id of expired) cleanupIDB(id);
|
|
105
|
+
}
|
|
106
|
+
async function cleanupIDB(docId) {
|
|
107
|
+
try {
|
|
108
|
+
const dbs = await indexedDB.databases();
|
|
109
|
+
for (const db of dbs) {
|
|
110
|
+
if (db.name?.includes(docId)) indexedDB.deleteDatabase(db.name);
|
|
111
|
+
}
|
|
112
|
+
} catch {
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
trashMap,
|
|
117
|
+
trashedItems,
|
|
118
|
+
trashedCount,
|
|
119
|
+
autoPurgeDays,
|
|
120
|
+
setAutoPurgeDays,
|
|
121
|
+
moveToTrash,
|
|
122
|
+
restoreFromTrash,
|
|
123
|
+
permanentlyDelete,
|
|
124
|
+
emptyTrash,
|
|
125
|
+
purgeExpired
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { VoiceConnectionStatus, VoicePeer } from '../utils/VoiceClient.js';
|
|
2
|
+
import type { VoiceError } from '../utils/voiceErrors.js';
|
|
3
|
+
declare function joinRoom(docId: string): Promise<void>;
|
|
4
|
+
declare function leaveRoom(): void;
|
|
5
|
+
declare function toggleMute(): Promise<void>;
|
|
6
|
+
declare function toggleVideo(): Promise<void>;
|
|
7
|
+
declare function toggleScreen(): Promise<void>;
|
|
8
|
+
declare function togglePeerMute(peerId: string): void;
|
|
9
|
+
declare function setMasterVolume(volume: number): void;
|
|
10
|
+
declare function setPeerVolume(peerId: string, volume: number): void;
|
|
11
|
+
export declare function useVoice(): {
|
|
12
|
+
voiceStatus: import("vue").Ref<VoiceConnectionStatus, VoiceConnectionStatus>;
|
|
13
|
+
voiceRoomId: import("vue").Ref<string | null, string | null>;
|
|
14
|
+
isMuted: import("vue").Ref<boolean, boolean>;
|
|
15
|
+
isVideoEnabled: import("vue").Ref<boolean, boolean>;
|
|
16
|
+
isScreenEnabled: import("vue").Ref<boolean, boolean>;
|
|
17
|
+
voiceError: import("vue").Ref<{
|
|
18
|
+
code: import("../utils/voiceErrors.js").VoiceErrorCode;
|
|
19
|
+
message: string;
|
|
20
|
+
} | null, VoiceError | {
|
|
21
|
+
code: import("../utils/voiceErrors.js").VoiceErrorCode;
|
|
22
|
+
message: string;
|
|
23
|
+
} | null>;
|
|
24
|
+
localAudioLevel: import("vue").Ref<number, number>;
|
|
25
|
+
masterVolume: import("vue").Ref<number, number>;
|
|
26
|
+
peers: import("vue").ShallowRef<Map<string, VoicePeer>, Map<string, VoicePeer>>;
|
|
27
|
+
audioLevels: import("vue").ShallowRef<Map<string, number>, Map<string, number>>;
|
|
28
|
+
localVideoStream: import("vue").ShallowRef<MediaStream | null, MediaStream | null>;
|
|
29
|
+
localScreenStream: import("vue").ShallowRef<MediaStream | null, MediaStream | null>;
|
|
30
|
+
peerVideoStreams: import("vue").ShallowRef<Map<string, {
|
|
31
|
+
camera: MediaStream | null;
|
|
32
|
+
screen: MediaStream | null;
|
|
33
|
+
}>, Map<string, {
|
|
34
|
+
camera: MediaStream | null;
|
|
35
|
+
screen: MediaStream | null;
|
|
36
|
+
}>>;
|
|
37
|
+
peerList: import("vue").ComputedRef<VoicePeer[]>;
|
|
38
|
+
peerCount: import("vue").ComputedRef<number>;
|
|
39
|
+
anyPeerSpeaking: import("vue").ComputedRef<boolean>;
|
|
40
|
+
canScreenShare: import("vue").ComputedRef<boolean>;
|
|
41
|
+
hasAnyVideo: import("vue").ComputedRef<boolean>;
|
|
42
|
+
joinRoom: typeof joinRoom;
|
|
43
|
+
leaveRoom: typeof leaveRoom;
|
|
44
|
+
toggleMute: typeof toggleMute;
|
|
45
|
+
toggleVideo: typeof toggleVideo;
|
|
46
|
+
toggleScreen: typeof toggleScreen;
|
|
47
|
+
togglePeerMute: typeof togglePeerMute;
|
|
48
|
+
setMasterVolume: typeof setMasterVolume;
|
|
49
|
+
setPeerVolume: typeof setPeerVolume;
|
|
50
|
+
};
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { ref, shallowRef, computed } from "vue";
|
|
2
|
+
import { VoiceClient } from "../utils/VoiceClient.js";
|
|
3
|
+
import { TRANSIENT_ERROR_CODES } from "../utils/voiceErrors.js";
|
|
4
|
+
const voiceStatus = ref("idle");
|
|
5
|
+
const voiceRoomId = ref(null);
|
|
6
|
+
const isMuted = ref(false);
|
|
7
|
+
const isVideoEnabled = ref(false);
|
|
8
|
+
const isScreenEnabled = ref(false);
|
|
9
|
+
const voiceError = ref(null);
|
|
10
|
+
const localAudioLevel = ref(0);
|
|
11
|
+
const masterVolume = ref(1);
|
|
12
|
+
const peers = shallowRef(/* @__PURE__ */ new Map());
|
|
13
|
+
const audioLevels = shallowRef(/* @__PURE__ */ new Map());
|
|
14
|
+
const localVideoStream = shallowRef(null);
|
|
15
|
+
const localScreenStream = shallowRef(null);
|
|
16
|
+
const peerVideoStreams = shallowRef(/* @__PURE__ */ new Map());
|
|
17
|
+
let _client = null;
|
|
18
|
+
const _unbinds = [];
|
|
19
|
+
function _cleanup() {
|
|
20
|
+
for (const unsub of _unbinds) unsub();
|
|
21
|
+
_unbinds.length = 0;
|
|
22
|
+
if (_client) {
|
|
23
|
+
_client.disconnect();
|
|
24
|
+
_client = null;
|
|
25
|
+
}
|
|
26
|
+
voiceStatus.value = "idle";
|
|
27
|
+
voiceRoomId.value = null;
|
|
28
|
+
isMuted.value = false;
|
|
29
|
+
isVideoEnabled.value = false;
|
|
30
|
+
isScreenEnabled.value = false;
|
|
31
|
+
voiceError.value = null;
|
|
32
|
+
localAudioLevel.value = 0;
|
|
33
|
+
peers.value = /* @__PURE__ */ new Map();
|
|
34
|
+
audioLevels.value = /* @__PURE__ */ new Map();
|
|
35
|
+
localVideoStream.value = null;
|
|
36
|
+
localScreenStream.value = null;
|
|
37
|
+
peerVideoStreams.value = /* @__PURE__ */ new Map();
|
|
38
|
+
}
|
|
39
|
+
function _wireEvents(vc) {
|
|
40
|
+
_unbinds.push(
|
|
41
|
+
vc.on("statusChange", (s) => {
|
|
42
|
+
voiceStatus.value = s;
|
|
43
|
+
if (s === "connected") voiceError.value = null;
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
_unbinds.push(
|
|
47
|
+
vc.on("peerJoined", () => {
|
|
48
|
+
peers.value = new Map(vc.peers);
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
_unbinds.push(
|
|
52
|
+
vc.on("peerLeft", (peerId) => {
|
|
53
|
+
peers.value = new Map(vc.peers);
|
|
54
|
+
const next = new Map(audioLevels.value);
|
|
55
|
+
next.delete(peerId);
|
|
56
|
+
audioLevels.value = next;
|
|
57
|
+
const nextVid = new Map(peerVideoStreams.value);
|
|
58
|
+
nextVid.delete(peerId);
|
|
59
|
+
peerVideoStreams.value = nextVid;
|
|
60
|
+
})
|
|
61
|
+
);
|
|
62
|
+
_unbinds.push(
|
|
63
|
+
vc.on("peerStream", () => {
|
|
64
|
+
peers.value = new Map(vc.peers);
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
_unbinds.push(
|
|
68
|
+
vc.on("audioLevel", (peerId, level) => {
|
|
69
|
+
const next = new Map(audioLevels.value);
|
|
70
|
+
next.set(peerId, level);
|
|
71
|
+
audioLevels.value = next;
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
_unbinds.push(
|
|
75
|
+
vc.on("localAudioLevel", (level) => {
|
|
76
|
+
localAudioLevel.value = level;
|
|
77
|
+
})
|
|
78
|
+
);
|
|
79
|
+
_unbinds.push(
|
|
80
|
+
vc.on("mute", (m) => {
|
|
81
|
+
isMuted.value = m;
|
|
82
|
+
})
|
|
83
|
+
);
|
|
84
|
+
_unbinds.push(
|
|
85
|
+
vc.on("remoteMute", () => {
|
|
86
|
+
peers.value = new Map(vc.peers);
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
_unbinds.push(
|
|
90
|
+
vc.on("videoChange", (enabled) => {
|
|
91
|
+
isVideoEnabled.value = enabled;
|
|
92
|
+
localVideoStream.value = vc.localVideoStream;
|
|
93
|
+
})
|
|
94
|
+
);
|
|
95
|
+
_unbinds.push(
|
|
96
|
+
vc.on("screenChange", (enabled) => {
|
|
97
|
+
isScreenEnabled.value = enabled;
|
|
98
|
+
localScreenStream.value = vc.localScreenStream;
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
_unbinds.push(
|
|
102
|
+
vc.on("peerVideoStream", (peerId, stream, kind) => {
|
|
103
|
+
const next = new Map(peerVideoStreams.value);
|
|
104
|
+
const entry = next.get(peerId) ?? { camera: null, screen: null };
|
|
105
|
+
entry[kind] = stream;
|
|
106
|
+
next.set(peerId, { ...entry });
|
|
107
|
+
peerVideoStreams.value = next;
|
|
108
|
+
})
|
|
109
|
+
);
|
|
110
|
+
_unbinds.push(
|
|
111
|
+
vc.on("peerMediaState", () => {
|
|
112
|
+
peers.value = new Map(vc.peers);
|
|
113
|
+
})
|
|
114
|
+
);
|
|
115
|
+
_unbinds.push(
|
|
116
|
+
vc.on("peerProfile", () => {
|
|
117
|
+
peers.value = new Map(vc.peers);
|
|
118
|
+
})
|
|
119
|
+
);
|
|
120
|
+
_unbinds.push(
|
|
121
|
+
vc.on("error", (err) => {
|
|
122
|
+
if (TRANSIENT_ERROR_CODES.has(err.code)) {
|
|
123
|
+
try {
|
|
124
|
+
const toast = useToast();
|
|
125
|
+
toast.add({ title: err.message, color: "warning", icon: "i-lucide-alert-triangle" });
|
|
126
|
+
} catch {
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
voiceError.value = err;
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
async function joinRoom(docId) {
|
|
135
|
+
if (voiceRoomId.value === docId && (voiceStatus.value === "connected" || voiceStatus.value === "connecting")) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
_cleanup();
|
|
139
|
+
const { client: abClient, currentServerUrl, userName, userColor } = useAbracadabra();
|
|
140
|
+
const jwt = abClient.value?.token ?? "";
|
|
141
|
+
if (!jwt) {
|
|
142
|
+
const { createVoiceError: mkErr, VoiceErrorCode } = await import("../utils/voiceErrors.js");
|
|
143
|
+
voiceError.value = mkErr(VoiceErrorCode.CONNECT_FAILED, "Not authenticated \u2014 please sign in first");
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const wsBase = currentServerUrl.value.replace(/^https:\/\//, "wss://").replace(/^http:\/\//, "ws://");
|
|
147
|
+
const signalingUrl = `${wsBase}/ws/${docId}/signaling?token=${jwt}`;
|
|
148
|
+
voiceRoomId.value = docId;
|
|
149
|
+
_client = new VoiceClient(signalingUrl);
|
|
150
|
+
_wireEvents(_client);
|
|
151
|
+
_client.setProfile(userName.value, userColor.value);
|
|
152
|
+
await _client.connect();
|
|
153
|
+
}
|
|
154
|
+
function leaveRoom() {
|
|
155
|
+
_cleanup();
|
|
156
|
+
}
|
|
157
|
+
async function toggleMute() {
|
|
158
|
+
if (_client) await _client.toggleMute();
|
|
159
|
+
}
|
|
160
|
+
async function toggleVideo() {
|
|
161
|
+
if (_client) await _client.toggleVideo();
|
|
162
|
+
}
|
|
163
|
+
async function toggleScreen() {
|
|
164
|
+
if (_client) await _client.toggleScreen();
|
|
165
|
+
}
|
|
166
|
+
function togglePeerMute(peerId) {
|
|
167
|
+
if (_client) _client.togglePeerMute(peerId);
|
|
168
|
+
}
|
|
169
|
+
function setMasterVolume(volume) {
|
|
170
|
+
masterVolume.value = volume;
|
|
171
|
+
if (_client) _client.setMasterVolume(volume);
|
|
172
|
+
}
|
|
173
|
+
function setPeerVolume(peerId, volume) {
|
|
174
|
+
if (_client) _client.setPeerVolume(peerId, volume);
|
|
175
|
+
}
|
|
176
|
+
const peerList = computed(() => [...peers.value.values()]);
|
|
177
|
+
const peerCount = computed(() => peers.value.size);
|
|
178
|
+
const anyPeerSpeaking = computed(
|
|
179
|
+
() => [...audioLevels.value.values()].some((l) => l > 0.05)
|
|
180
|
+
);
|
|
181
|
+
const canScreenShare = computed(
|
|
182
|
+
() => typeof navigator !== "undefined" && !!navigator.mediaDevices?.getDisplayMedia
|
|
183
|
+
);
|
|
184
|
+
const hasAnyVideo = computed(() => {
|
|
185
|
+
if (isVideoEnabled.value || isScreenEnabled.value) return true;
|
|
186
|
+
for (const peer of peers.value.values()) {
|
|
187
|
+
if (peer.remoteVideo || peer.remoteScreen) return true;
|
|
188
|
+
}
|
|
189
|
+
return false;
|
|
190
|
+
});
|
|
191
|
+
export function useVoice() {
|
|
192
|
+
return {
|
|
193
|
+
voiceStatus,
|
|
194
|
+
voiceRoomId,
|
|
195
|
+
isMuted,
|
|
196
|
+
isVideoEnabled,
|
|
197
|
+
isScreenEnabled,
|
|
198
|
+
voiceError,
|
|
199
|
+
localAudioLevel,
|
|
200
|
+
masterVolume,
|
|
201
|
+
peers,
|
|
202
|
+
audioLevels,
|
|
203
|
+
localVideoStream,
|
|
204
|
+
localScreenStream,
|
|
205
|
+
peerVideoStreams,
|
|
206
|
+
peerList,
|
|
207
|
+
peerCount,
|
|
208
|
+
anyPeerSpeaking,
|
|
209
|
+
canScreenShare,
|
|
210
|
+
hasAnyVideo,
|
|
211
|
+
joinRoom,
|
|
212
|
+
leaveRoom,
|
|
213
|
+
toggleMute,
|
|
214
|
+
toggleVideo,
|
|
215
|
+
toggleScreen,
|
|
216
|
+
togglePeerMute,
|
|
217
|
+
setMasterVolume,
|
|
218
|
+
setPeerVolume
|
|
219
|
+
};
|
|
220
|
+
}
|