@@ -11,16 +11,16 @@ import {
11
11
import { Edge , Node } from "@xyflow/react"
12
12
import { Assessment } from "@/typings"
13
13
14
- enum MessageType {
14
+ export enum MessageType {
15
15
YjsSYNC = 0 ,
16
16
YjsUpdate = 1 ,
17
17
}
18
18
19
- type SendFunction = ( data : string ) => void
19
+ export type SendBroadcastMessage = ( base64data : string ) => void
20
20
21
21
export class YjsSyncClass {
22
22
private readonly stopYjsObserver : ( ) => void
23
- private sendFunction : SendFunction | null = null
23
+ private sendBroadcastMessage : SendBroadcastMessage | null = null
24
24
private readonly ydoc : Y . Doc
25
25
private readonly diagramStore : StoreApi < DiagramStore >
26
26
private readonly metadataStore : StoreApi < MetadataStore >
@@ -40,8 +40,8 @@ export class YjsSyncClass {
40
40
this . stopYjsObserver ( )
41
41
}
42
42
43
- public setSendFunction = ( sendFn : SendFunction ) => {
44
- this . sendFunction = sendFn
43
+ public setSendBroadcastMessage = ( sendFn : SendBroadcastMessage ) => {
44
+ this . sendBroadcastMessage = sendFn
45
45
}
46
46
47
47
private applyUpdate = ( update : Uint8Array , transactionOrigin : string ) => {
@@ -57,14 +57,14 @@ export class YjsSyncClass {
57
57
const update = decodedData . slice ( 1 )
58
58
this . applyUpdate ( update , "remote" )
59
59
} else if ( messageType === MessageType . YjsSYNC ) {
60
- if ( this . sendFunction ) {
60
+ if ( this . sendBroadcastMessage ) {
61
61
const syncMessage = Y . encodeStateAsUpdate ( this . ydoc )
62
62
const fullMessage = new Uint8Array ( 1 + syncMessage . length )
63
63
fullMessage [ 0 ] = MessageType . YjsUpdate
64
64
fullMessage . set ( syncMessage , 1 )
65
65
66
66
const base64Message = YjsSyncClass . uint8ToBase64 ( fullMessage )
67
- this . sendFunction ( base64Message )
67
+ this . sendBroadcastMessage ( base64Message )
68
68
}
69
69
}
70
70
}
@@ -112,13 +112,13 @@ export class YjsSyncClass {
112
112
_arg2 : Y . Doc ,
113
113
transaction : Y . Transaction
114
114
) => {
115
- if ( this . sendFunction && transaction . origin === "store" ) {
115
+ if ( this . sendBroadcastMessage && transaction . origin === "store" ) {
116
116
const syncMessage = Y . encodeStateAsUpdate ( this . ydoc )
117
117
const fullMessage = new Uint8Array ( 1 + syncMessage . length )
118
118
fullMessage [ 0 ] = MessageType . YjsUpdate
119
119
fullMessage . set ( syncMessage , 1 )
120
120
const base64Message = YjsSyncClass . uint8ToBase64 ( fullMessage )
121
- this . sendFunction ( base64Message )
121
+ this . sendBroadcastMessage ( base64Message )
122
122
}
123
123
}
124
124
0 commit comments