Skip to content

Commit 1139c0a

Browse files
committed
♻️(frontend) replace y-webrtc by @hocuspocus
y-webrtc had some issues, users had difficulties to connect with each others. We replace it by @hocuspocus/provider.
1 parent 9e1979f commit 1139c0a

File tree

9 files changed

+25
-29
lines changed

9 files changed

+25
-29
lines changed

src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test.beforeEach(async ({ page }) => {
99
});
1010

1111
test.describe('Doc Editor', () => {
12-
test('checks the Doc is connected to the webrtc server', async ({
12+
test('checks the Doc is connected to the provider server', async ({
1313
page,
1414
browserName,
1515
}) => {
@@ -29,12 +29,7 @@ test.describe('Doc Editor', () => {
2929
await page.locator('.ProseMirror.bn-editor').fill('Hello World');
3030

3131
const framesent = await framesentPromise;
32-
const payload = JSON.parse(framesent.payload as string) as {
33-
type: string;
34-
};
35-
36-
const typeCases = ['publish', 'subscribe', 'unsubscribe', 'ping'];
37-
expect(typeCases.includes(payload.type)).toBeTruthy();
32+
expect(framesent.payload).not.toBeNull();
3833
});
3934

4035
test('markdown button converts from markdown to the editor syntax json', async ({

src/frontend/apps/impress/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
NEXT_PUBLIC_API_ORIGIN=
2+
NEXT_PUBLIC_Y_PROVIDER_URL=
23
NEXT_PUBLIC_MEDIA_URL=
3-
NEXT_PUBLIC_SIGNALING_URL=
44
NEXT_PUBLIC_THEME=dsfr
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
NEXT_PUBLIC_API_ORIGIN=http://localhost:8071
2-
NEXT_PUBLIC_SIGNALING_URL=ws://localhost:4444
2+
NEXT_PUBLIC_Y_PROVIDER_URL=ws://localhost:4444
33
NEXT_PUBLIC_MEDIA_URL=http://localhost:8083
44
NEXT_PUBLIC_SW_DEACTIVATED=true

src/frontend/apps/impress/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@blocknote/mantine": "*",
2020
"@blocknote/react": "*",
2121
"@gouvfr-lasuite/integration": "1.0.2",
22+
"@hocuspocus/provider": "2.13.5",
2223
"@openfun/cunningham-react": "2.9.4",
2324
"@tanstack/react-query": "5.53.2",
2425
"i18next": "23.14.0",
@@ -32,7 +33,6 @@
3233
"react-i18next": "15.0.1",
3334
"react-select": "5.8.0",
3435
"styled-components": "6.1.13",
35-
"y-webrtc": "10.3.0",
3636
"yjs": "*",
3737
"zustand": "4.5.5"
3838
},

src/frontend/apps/impress/src/core/conf.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ export const backendUrl = () =>
99
export const baseApiUrl = (apiVersion: string = '1.0') =>
1010
`${backendUrl()}/api/v${apiVersion}/`;
1111

12-
export const signalingUrl = (docId: string) => {
12+
export const providerUrl = (docId: string) => {
1313
const base =
14-
process.env.NEXT_PUBLIC_SIGNALING_URL ||
14+
process.env.NEXT_PUBLIC_Y_PROVIDER_URL ||
1515
(typeof window !== 'undefined' ? `wss://${window.location.host}/ws` : '');
1616

1717
return `${base}/${docId}`;

src/frontend/apps/impress/src/custom-next.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace NodeJS {
2121
interface ProcessEnv {
2222
NEXT_PUBLIC_API_ORIGIN?: string;
2323
NEXT_PUBLIC_MEDIA_URL?: string;
24-
NEXT_PUBLIC_SIGNALING_URL?: string;
24+
NEXT_PUBLIC_Y_PROVIDER_URL?: string;
2525
NEXT_PUBLIC_SW_DEACTIVATED?: string;
2626
NEXT_PUBLIC_THEME?: string;
2727
}

src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { BlockNoteEditor as BlockNoteEditorCore } from '@blocknote/core';
22
import '@blocknote/core/fonts/inter.css';
33
import { BlockNoteView } from '@blocknote/mantine';
44
import '@blocknote/mantine/style.css';
5+
import { HocuspocusProvider } from '@hocuspocus/provider';
56
import React, { useCallback, useEffect, useMemo } from 'react';
6-
import { WebrtcProvider } from 'y-webrtc';
77

88
import { Box, TextErrors } from '@/components';
99
import { mediaUrl } from '@/core';
@@ -44,7 +44,7 @@ export const BlockNoteEditor = ({ doc, version }: BlockNoteEditorProps) => {
4444
const provider = docsStore?.[storeId]?.provider;
4545

4646
useEffect(() => {
47-
if (!provider || provider.doc.guid !== storeId) {
47+
if (!provider || provider.document.guid !== storeId) {
4848
createProvider(storeId, initialContent);
4949
}
5050
}, [createProvider, initialContent, provider, storeId]);
@@ -58,7 +58,7 @@ export const BlockNoteEditor = ({ doc, version }: BlockNoteEditorProps) => {
5858

5959
interface BlockNoteContentProps {
6060
doc: Doc;
61-
provider: WebrtcProvider;
61+
provider: HocuspocusProvider;
6262
storeId: string;
6363
}
6464

@@ -71,7 +71,7 @@ export const BlockNoteContent = ({
7171
const { userData } = useAuthStore();
7272
const { setStore, docsStore } = useDocStore();
7373
const canSave = doc.abilities.partial_update && !isVersion;
74-
useSaveDoc(doc.id, provider.doc, canSave);
74+
useSaveDoc(doc.id, provider.document, canSave);
7575
const storedEditor = docsStore?.[storeId]?.editor;
7676
const {
7777
mutateAsync: createDocAttachment,
@@ -102,7 +102,7 @@ export const BlockNoteContent = ({
102102
return BlockNoteEditorCore.create({
103103
collaboration: {
104104
provider,
105-
fragment: provider.doc.getXmlFragment('document-store'),
105+
fragment: provider.document.getXmlFragment('document-store'),
106106
user: {
107107
name: userData?.email || 'Anonymous',
108108
color: randomColor(),

src/frontend/apps/impress/src/features/docs/doc-editor/stores/useDocStore.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { BlockNoteEditor } from '@blocknote/core';
2-
import { WebrtcProvider } from 'y-webrtc';
2+
import { HocuspocusProvider } from '@hocuspocus/provider';
33
import * as Y from 'yjs';
44
import { create } from 'zustand';
55

6-
import { signalingUrl } from '@/core';
6+
import { providerUrl } from '@/core';
77
import { Base64 } from '@/features/docs/doc-management';
88

99
interface DocStore {
10-
provider: WebrtcProvider;
10+
provider: HocuspocusProvider;
1111
editor?: BlockNoteEditor;
1212
}
1313

1414
export interface UseDocStore {
1515
docsStore: {
1616
[storeId: string]: DocStore;
1717
};
18-
createProvider: (storeId: string, initialDoc: Base64) => WebrtcProvider;
18+
createProvider: (storeId: string, initialDoc: Base64) => HocuspocusProvider;
1919
setStore: (storeId: string, props: Partial<DocStore>) => void;
2020
}
2121

@@ -30,9 +30,10 @@ export const useDocStore = create<UseDocStore>((set, get) => ({
3030
Y.applyUpdate(doc, Buffer.from(initialDoc, 'base64'));
3131
}
3232

33-
const provider = new WebrtcProvider(storeId, doc, {
34-
signaling: [signalingUrl(storeId)],
35-
maxConns: 5,
33+
const provider = new HocuspocusProvider({
34+
url: providerUrl(storeId),
35+
name: storeId,
36+
document: doc,
3637
});
3738

3839
get().setStore(storeId, { provider });

src/frontend/apps/impress/src/features/docs/doc-versioning/components/ModalVersion.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ export const ModalVersion = ({
5151
});
5252

5353
revertUpdate(
54-
docsStore[docId].provider.doc,
55-
docsStore[docId].provider.doc,
56-
docsStore[versionId].provider.doc,
54+
docsStore[docId].provider.document,
55+
docsStore[docId].provider.document,
56+
docsStore[versionId].provider.document,
5757
);
5858

5959
onDisplaySuccess();
@@ -83,7 +83,7 @@ export const ModalVersion = ({
8383
fullWidth
8484
onClick={() => {
8585
const newDoc = toBase64(
86-
Y.encodeStateAsUpdate(docsStore?.[versionId]?.provider.doc),
86+
Y.encodeStateAsUpdate(docsStore?.[versionId]?.provider.document),
8787
);
8888

8989
updateDoc({

0 commit comments

Comments
 (0)