Skip to content

Commit

Permalink
It's aware !
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoos committed Oct 22, 2024
1 parent d19d90f commit 9fa6ec2
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 8 deletions.
8 changes: 6 additions & 2 deletions vendor/brr_lwd_ui/bindings/y-quill/y_quill.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ type t = Jv.t

let quill_binding = Global.quill_binding

let make text editor =
Jv.new' quill_binding [| Yjs.Text.to_jv text; Quill.to_jv editor |]
let make ?awareness text editor =
let awareness = Option.map Yjs.Awareness.to_jv awareness in
let params =
Yjs.Text.to_jv text :: Quill.to_jv editor :: Option.to_list awareness
in
Jv.new' quill_binding @@ Array.of_list params
2 changes: 1 addition & 1 deletion vendor/brr_lwd_ui/bindings/y-quill/y_quill.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
type t

val make : Yjs.Text.t -> Quill.t -> t
val make : ?awareness:Yjs.Awareness.t -> Yjs.Text.t -> Quill.t -> t
6 changes: 6 additions & 0 deletions vendor/brr_lwd_ui/bindings/yjs/awareness.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type t = Jv.t

external to_jv : t -> Jv.t = "%identity"

let class_awarness = Jv.get Global.awareness_protocol "Awareness"
let make doc = Jv.new' class_awarness [| Doc.Doc.to_jv doc |]
4 changes: 4 additions & 0 deletions vendor/brr_lwd_ui/bindings/yjs/awareness.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type t

val to_jv : t -> Jv.t
val make : Doc.Doc.t -> t
1 change: 1 addition & 0 deletions vendor/brr_lwd_ui/bindings/yjs/global.ml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
let yjs = Jv.get Jv.global "yjs"
let awareness_protocol = Jv.get Jv.global "awarenessProtocol"
1 change: 1 addition & 0 deletions vendor/brr_lwd_ui/bindings/yjs/js/yjs.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
window.yjs = require('yjs')
window.WebrtcProvider = require('y-webrtc').WebrtcProvider
window.IndexeddbPersistence = require('y-indexeddb').IndexeddbPersistence
window.awarenessProtocol = require('y-protocols/awareness.js')
8 changes: 6 additions & 2 deletions vendor/brr_lwd_ui/bindings/yjs/webrtc_provider.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ let _servers =
"relay.webwormhole.io:3478";
]

let make ~room_name ?signaling yjs_doc =
let make ~room_name ?signaling ?awareness yjs_doc =
let signaling =
Option.map (fun v -> ("signaling", Jv.of_list Jv.of_string v)) signaling
in
Expand All @@ -169,8 +169,12 @@ let make ~room_name ?signaling yjs_doc =
|] )
in
let () = Brr.Console.log [ peer_opts ] in
let awareness =
Option.map (fun a -> ("awareness", Awareness.to_jv a)) awareness
in
let options =
[ signaling; peer_opts ] |> List.filter_map Fun.id |> Array.of_list
[ signaling; peer_opts; awareness ]
|> List.filter_map Fun.id |> Array.of_list
in
Jv.new' web_rpc_provider
[| Jv.of_string room_name; Doc.Doc.to_jv yjs_doc; Jv.obj options |]
7 changes: 6 additions & 1 deletion vendor/brr_lwd_ui/bindings/yjs/webrtc_provider.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
type t

val make : room_name:string -> ?signaling:string list -> Doc.Doc.t -> t
val make :
room_name:string ->
?signaling:string list ->
?awareness:Awareness.t ->
Doc.Doc.t ->
t
1 change: 1 addition & 0 deletions vendor/brr_lwd_ui/bindings/yjs/yjs.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module Webrtc_provider = Webrtc_provider
module Indexeddb_persistence = Indexeddb_persistence
module Awareness = Awareness
include Doc
include Y
5 changes: 3 additions & 2 deletions vendor/brr_lwd_ui/examples/yjs/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ open Lwd_infix
let random_state = Random.State.make_self_init ()
let new_uuid_v4 () = Uuidm.v4_gen random_state ()
let yjs_doc = Yjs.Doc.make ()
let awareness = Yjs.Awareness.make yjs_doc
let _ = Quill.register ~path:"modules/cursors" Quill.cursors

let provider =
Yjs.Webrtc_provider.make ~room_name:"testroom5267564"
Yjs.Webrtc_provider.make ~room_name:"testroom5267564" ~awareness
~signaling:[ "wss://p2p.u31.fr" ] yjs_doc

let _provider = Yjs.Indexeddb_persistence.make ~doc_name:"zedoc" yjs_doc
Expand Down Expand Up @@ -606,7 +607,7 @@ let render_richtext_cell ~src:_ (value : Yjs.Text.t) =
let open Quill in
let toolbar = Array [ Bold; Italic; Underline ] in
make ~container @@ config ~theme:Snow ~cursors:true ~toolbar ()
|> (* TODO is there some cleanup to do ? *) Y_quill.make value
|> (* TODO is there some cleanup to do ? *) Y_quill.make ~awareness value
in
elt

Expand Down

0 comments on commit 9fa6ec2

Please sign in to comment.