diff --git a/app/action/option.go b/app/action/option.go index 7034790..b67f7a3 100644 --- a/app/action/option.go +++ b/app/action/option.go @@ -8,8 +8,8 @@ var StorageOption struct { var StartOption struct { Frontend fs.FS + YJSServer []byte Doc fs.FS - YSweetBin []byte Port int Readonly bool diff --git a/app/action/start.go b/app/action/start.go index bdd5d3e..43c34cc 100644 --- a/app/action/start.go +++ b/app/action/start.go @@ -10,7 +10,6 @@ import ( "os" "os/exec" "path/filepath" - "strconv" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" @@ -55,12 +54,10 @@ func Start(ctx context.Context) error { } e.Use(middlewares...) - // proxy y-sweet ws - ysweetPort := mustStartYSweetServer() + // proxy yjs-server ws + yjsPort := mustStartYJSServer() e.Any("/ws/*", func(c echo.Context) error { - // y-sweet server hard-coded the listening host as `127.0.0.1`, which prevents remote machines to access. - // https://github.com/drifting-in-space/y-sweet/blob/0f5bcfd05dfc744c01bb06f202ce6c97a1aebb49/crates/y-sweet/src/main.rs#L158 - target := fmt.Sprintf("http://127.0.0.1:%d", ysweetPort) + target := fmt.Sprintf("http://127.0.0.1:%d", yjsPort) targetUrl, err := url.Parse(target) if err != nil { return err @@ -220,13 +217,13 @@ func databaseDir() string { return filepath.Join(StorageOption.Workspace, "database") } -func mustStartYSweetServer() int { +func mustStartYJSServer() int { // create a temporary file - bin, err := os.CreateTemp("", "y-sweet-*") + bin, err := os.CreateTemp("", "nutsh-yjs-*") mustOk(err) // write the embedded binary to the temporary file - _, err = bin.Write(StartOption.YSweetBin) + _, err = bin.Write(StartOption.YJSServer) mustOk(err) mustOk(bin.Close()) @@ -238,8 +235,12 @@ func mustStartYSweetServer() int { dir := filepath.Join(StorageOption.Workspace, "yjs") // execute the binary in a new process - cmd := exec.Command(bin.Name(), "serve", "--port", strconv.Itoa(internalPort), dir) - zap.L().Info("start y-sweet server", zap.Int("port", internalPort), zap.String("dir", dir)) + cmd := exec.Command(bin.Name()) + cmd.Env = []string{ + fmt.Sprintf("PORT=%d", internalPort), + fmt.Sprintf("DATA_DIR=%s", dir), + } + zap.L().Info("start yjs-server server", zap.Int("port", internalPort), zap.String("dir", dir)) cmd.Stderr = os.Stderr cmd.Stdout = os.Stdout diff --git a/app/frontend/package-lock.json b/app/frontend/package-lock.json index 68f5035..b28b517 100644 --- a/app/frontend/package-lock.json +++ b/app/frontend/package-lock.json @@ -15,7 +15,6 @@ "@fortawesome/react-fontawesome": "^0.2.0", "@react-hook/window-size": "^3.1.1", "@tanstack/react-query": "^4.14.1", - "@y-sweet/client": "^0.1.0", "antd": "^5.7.3", "crypto-js": "^4.1.1", "deep-equal": "^2.1.0", @@ -40,6 +39,7 @@ "ts-key-enum": "^2.0.12", "typescript": "^5.1.6", "uuid": "^9.0.0", + "y-websocket": "^1.5.4", "yjs": "^13.6.12", "zundo": "^2.0.0-beta.5", "zustand": "^4.1.4" @@ -5305,39 +5305,27 @@ "resolved": "https://registry.npmjs.org/@xtuc/long/-/long-4.2.2.tgz", "integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==" }, - "node_modules/@y-sweet/client": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/@y-sweet/client/-/client-0.1.0.tgz", - "integrity": "sha512-X9+IZ/7t7So39TxYxmmjKKZ8SCKcFJrBmnEHHEJ9l6Jj6hPfoK8uHzQiYN+R0J5CpEoGsxuPevwAQZzENYX0dQ==", - "dependencies": { - "@y-sweet/sdk": "0.1.0", - "y-protocols": "^1.0.5" - }, - "peerDependencies": { - "yjs": "^13.0.0" - } - }, - "node_modules/@y-sweet/sdk": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/@y-sweet/sdk/-/sdk-0.1.0.tgz", - "integrity": "sha512-rQDF3p3KhRVPBRpT9e8fNq0qyQlHe/LF3IfrkP3m/PjUmtTkMY/a3x1/vdRn1KXLz3tB5h7iP7KRPDP7bEs2qw==", - "dependencies": { - "@types/node": "^20.5.9" - } - }, - "node_modules/@y-sweet/sdk/node_modules/@types/node": { - "version": "20.11.19", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.19.tgz", - "integrity": "sha512-7xMnVEcZFu0DikYjWOlRq7NTPETrm7teqUT2WkQjrTIkEgUyyGdWsj/Zg8bEJt5TNklzbPD1X3fqfsHw3SpapQ==", - "dependencies": { - "undici-types": "~5.26.4" - } - }, "node_modules/abab": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.6.tgz", "integrity": "sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==" }, + "node_modules/abstract-leveldown": { + "version": "6.2.3", + "resolved": "https://registry.npmjs.org/abstract-leveldown/-/abstract-leveldown-6.2.3.tgz", + "integrity": "sha512-BsLm5vFMRUrrLeCcRc+G0t2qOaTzpoJQLOubq2XM72eNpjF5UdU5o/5NvlNhx95XHcAvcl8OMXr4mlg/fRgUXQ==", + "optional": true, + "dependencies": { + "buffer": "^5.5.0", + "immediate": "^3.2.3", + "level-concat-iterator": "~2.0.0", + "level-supports": "~1.0.0", + "xtend": "~4.0.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -5807,6 +5795,12 @@ "resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz", "integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==" }, + "node_modules/async-limiter": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", + "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==", + "optional": true + }, "node_modules/async-validator": { "version": "4.2.5", "resolved": "https://registry.npmjs.org/async-validator/-/async-validator-4.2.5.tgz", @@ -6158,6 +6152,26 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "optional": true + }, "node_modules/batch": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz", @@ -6329,6 +6343,30 @@ "node-int64": "^0.4.0" } }, + "node_modules/buffer": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", + "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "optional": true, + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.1.13" + } + }, "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -7609,6 +7647,19 @@ "node": ">= 10" } }, + "node_modules/deferred-leveldown": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/deferred-leveldown/-/deferred-leveldown-5.3.0.tgz", + "integrity": "sha512-a59VOT+oDy7vtAbLRCZwWgxu2BaCfd5Hk7wxJd48ei7I+nsg8Orlb9CLG0PMZienk9BSUKgeAqkO2+Lw+1+Ukw==", + "optional": true, + "dependencies": { + "abstract-leveldown": "~6.2.1", + "inherits": "^2.0.3" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/define-lazy-prop": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-2.0.0.tgz", @@ -7954,6 +8005,21 @@ "node": ">= 0.8" } }, + "node_modules/encoding-down": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/encoding-down/-/encoding-down-6.3.0.tgz", + "integrity": "sha512-QKrV0iKR6MZVJV08QY0wp1e7vF6QbhnbQhb07bwpEyuz4uZiZgPlEGdkCROuFkUwdxlFaiPIhjyarH1ee/3vhw==", + "optional": true, + "dependencies": { + "abstract-leveldown": "^6.2.1", + "inherits": "^2.0.3", + "level-codec": "^9.0.0", + "level-errors": "^2.0.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/enhanced-resolve": { "version": "5.10.0", "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.10.0.tgz", @@ -7986,6 +8052,18 @@ "url": "https://github.com/fb55/entities?sponsor=1" } }, + "node_modules/errno": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.8.tgz", + "integrity": "sha512-dJ6oBr5SQ1VSd9qkk7ByRgb/1SH4JZjCHSW/mr63/QcXO9zLVxvJ6Oy13nio03rxpSnVDDjFor75SjVeZWPW/A==", + "optional": true, + "dependencies": { + "prr": "~1.0.1" + }, + "bin": { + "errno": "cli.js" + } + }, "node_modules/error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -10867,6 +10945,26 @@ "node": ">=4" } }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "optional": true + }, "node_modules/ignore": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", @@ -10875,6 +10973,12 @@ "node": ">= 4" } }, + "node_modules/immediate": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.3.0.tgz", + "integrity": "sha512-HR7EVodfFUdQCTIeySw+WDRFJlPcLOJbXfwwZ7Oom6tjsvZ3bOkCDJHehQC3nxJrv7+f9XecwazynjU8e4Vw3Q==", + "optional": true + }, "node_modules/immer": { "version": "9.0.19", "resolved": "https://registry.npmjs.org/immer/-/immer-9.0.19.tgz", @@ -13793,6 +13897,139 @@ "language-subtag-registry": "~0.3.2" } }, + "node_modules/level": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/level/-/level-6.0.1.tgz", + "integrity": "sha512-psRSqJZCsC/irNhfHzrVZbmPYXDcEYhA5TVNwr+V92jF44rbf86hqGp8fiT702FyiArScYIlPSBTDUASCVNSpw==", + "optional": true, + "dependencies": { + "level-js": "^5.0.0", + "level-packager": "^5.1.0", + "leveldown": "^5.4.0" + }, + "engines": { + "node": ">=8.6.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/level" + } + }, + "node_modules/level-codec": { + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/level-codec/-/level-codec-9.0.2.tgz", + "integrity": "sha512-UyIwNb1lJBChJnGfjmO0OR+ezh2iVu1Kas3nvBS/BzGnx79dv6g7unpKIDNPMhfdTEGoc7mC8uAu51XEtX+FHQ==", + "optional": true, + "dependencies": { + "buffer": "^5.6.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/level-concat-iterator": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/level-concat-iterator/-/level-concat-iterator-2.0.1.tgz", + "integrity": "sha512-OTKKOqeav2QWcERMJR7IS9CUo1sHnke2C0gkSmcR7QuEtFNLLzHQAvnMw8ykvEcv0Qtkg0p7FOwP1v9e5Smdcw==", + "optional": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/level-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/level-errors/-/level-errors-2.0.1.tgz", + "integrity": "sha512-UVprBJXite4gPS+3VznfgDSU8PTRuVX0NXwoWW50KLxd2yw4Y1t2JUR5In1itQnudZqRMT9DlAM3Q//9NCjCFw==", + "optional": true, + "dependencies": { + "errno": "~0.1.1" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/level-iterator-stream": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/level-iterator-stream/-/level-iterator-stream-4.0.2.tgz", + "integrity": "sha512-ZSthfEqzGSOMWoUGhTXdX9jv26d32XJuHz/5YnuHZzH6wldfWMOVwI9TBtKcya4BKTyTt3XVA0A3cF3q5CY30Q==", + "optional": true, + "dependencies": { + "inherits": "^2.0.4", + "readable-stream": "^3.4.0", + "xtend": "^4.0.2" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/level-js": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/level-js/-/level-js-5.0.2.tgz", + "integrity": "sha512-SnBIDo2pdO5VXh02ZmtAyPP6/+6YTJg2ibLtl9C34pWvmtMEmRTWpra+qO/hifkUtBTOtfx6S9vLDjBsBK4gRg==", + "optional": true, + "dependencies": { + "abstract-leveldown": "~6.2.3", + "buffer": "^5.5.0", + "inherits": "^2.0.3", + "ltgt": "^2.1.2" + } + }, + "node_modules/level-packager": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/level-packager/-/level-packager-5.1.1.tgz", + "integrity": "sha512-HMwMaQPlTC1IlcwT3+swhqf/NUO+ZhXVz6TY1zZIIZlIR0YSn8GtAAWmIvKjNY16ZkEg/JcpAuQskxsXqC0yOQ==", + "optional": true, + "dependencies": { + "encoding-down": "^6.3.0", + "levelup": "^4.3.2" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/level-supports": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/level-supports/-/level-supports-1.0.1.tgz", + "integrity": "sha512-rXM7GYnW8gsl1vedTJIbzOrRv85c/2uCMpiiCzO2fndd06U/kUXEEU9evYn4zFggBOg36IsBW8LzqIpETwwQzg==", + "optional": true, + "dependencies": { + "xtend": "^4.0.2" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/leveldown": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/leveldown/-/leveldown-5.6.0.tgz", + "integrity": "sha512-iB8O/7Db9lPaITU1aA2txU/cBEXAt4vWwKQRrrWuS6XDgbP4QZGj9BL2aNbwb002atoQ/lIotJkfyzz+ygQnUQ==", + "hasInstallScript": true, + "optional": true, + "dependencies": { + "abstract-leveldown": "~6.2.1", + "napi-macros": "~2.0.0", + "node-gyp-build": "~4.1.0" + }, + "engines": { + "node": ">=8.6.0" + } + }, + "node_modules/levelup": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/levelup/-/levelup-4.4.0.tgz", + "integrity": "sha512-94++VFO3qN95cM/d6eBXvd894oJE0w3cInq9USsyQzzoJxmiYzPAocNcuGCPGGjoXqDVJcr3C1jzt1TSjyaiLQ==", + "optional": true, + "dependencies": { + "deferred-leveldown": "~5.3.0", + "level-errors": "~2.0.0", + "level-iterator-stream": "~4.0.0", + "level-supports": "~1.0.0", + "xtend": "~4.0.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/leven": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", @@ -13951,6 +14188,12 @@ "node": ">=10" } }, + "node_modules/ltgt": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ltgt/-/ltgt-2.2.1.tgz", + "integrity": "sha512-AI2r85+4MquTw9ZYqabu4nMwy9Oftlfa/e/52t9IjtfG+mGBbTNdAoZ3RQKLHR6r0wQnwZnPIEh/Ya6XTWAKNA==", + "optional": true + }, "node_modules/magic-string": { "version": "0.25.9", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.9.tgz", @@ -14318,6 +14561,12 @@ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" } }, + "node_modules/napi-macros": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/napi-macros/-/napi-macros-2.0.0.tgz", + "integrity": "sha512-A0xLykHtARfueITVDernsAWdtIMbOJgKgcluwENp3AlsKN/PloyO10HtmoqnFAQAcxPkgZN7wdfPfEd0zNGxbg==", + "optional": true + }, "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", @@ -14405,6 +14654,17 @@ "node": ">= 6.13.0" } }, + "node_modules/node-gyp-build": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.1.1.tgz", + "integrity": "sha512-dSq1xmcPDKPZ2EED2S6zw/b9NKsqzXRE6dVr8TVQnI3FJOTteUMuqF3Qqs6LZg+mLGYJWqQzMbIjMtJqTv87nQ==", + "optional": true, + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -16453,6 +16713,12 @@ "node": ">= 0.10" } }, + "node_modules/prr": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz", + "integrity": "sha512-yPw4Sng1gWghHQWj0B3ZggWUm4qVbPwPFcRG8KyxiU7J2OHFSoEHKS+EZ3fv5l1t9CyCiop6l/ZYeWbrgoQejw==", + "optional": true + }, "node_modules/psl": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", @@ -19643,11 +19909,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" - }, "node_modules/unicode-canonical-property-names-ecmascript": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz", @@ -20762,6 +21023,23 @@ "node": ">=0.4" } }, + "node_modules/y-leveldb": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/y-leveldb/-/y-leveldb-0.1.2.tgz", + "integrity": "sha512-6ulEn5AXfXJYi89rXPEg2mMHAyyw8+ZfeMMdOtBbV8FJpQ1NOrcgi6DTAcXof0dap84NjHPT2+9d0rb6cFsjEg==", + "optional": true, + "dependencies": { + "level": "^6.0.1", + "lib0": "^0.2.31" + }, + "funding": { + "type": "GitHub Sponsors ❤", + "url": "https://github.com/sponsors/dmonad" + }, + "peerDependencies": { + "yjs": "^13.0.0" + } + }, "node_modules/y-protocols": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/y-protocols/-/y-protocols-1.0.6.tgz", @@ -20781,6 +21059,44 @@ "yjs": "^13.0.0" } }, + "node_modules/y-websocket": { + "version": "1.5.4", + "resolved": "https://registry.npmjs.org/y-websocket/-/y-websocket-1.5.4.tgz", + "integrity": "sha512-Y3021uy0anOIHqAPyAZbNDoR05JuMEGjRNI8c+K9MHzVS8dWoImdJUjccljAznc8H2L7WkIXhRHZ1igWNRSgPw==", + "dependencies": { + "lib0": "^0.2.52", + "lodash.debounce": "^4.0.8", + "y-protocols": "^1.0.5" + }, + "bin": { + "y-websocket": "bin/server.js", + "y-websocket-server": "bin/server.js" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=8.0.0" + }, + "funding": { + "type": "GitHub Sponsors ❤", + "url": "https://github.com/sponsors/dmonad" + }, + "optionalDependencies": { + "ws": "^6.2.1", + "y-leveldb": "^0.1.0" + }, + "peerDependencies": { + "yjs": "^13.5.6" + } + }, + "node_modules/y-websocket/node_modules/ws": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.2.tgz", + "integrity": "sha512-zmhltoSR8u1cnDsD43TX59mzoMZsLKqUweyYBAIvTngR3shc0W6aOZylZmq/7hqyVxPdi+5Ud2QInblgyE72fw==", + "optional": true, + "dependencies": { + "async-limiter": "~1.0.0" + } + }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/app/frontend/package.json b/app/frontend/package.json index d0ba655..c9e98ff 100644 --- a/app/frontend/package.json +++ b/app/frontend/package.json @@ -17,7 +17,6 @@ "@fortawesome/react-fontawesome": "^0.2.0", "@react-hook/window-size": "^3.1.1", "@tanstack/react-query": "^4.14.1", - "@y-sweet/client": "^0.1.0", "antd": "^5.7.3", "crypto-js": "^4.1.1", "deep-equal": "^2.1.0", @@ -42,6 +41,7 @@ "ts-key-enum": "^2.0.12", "typescript": "^5.1.6", "uuid": "^9.0.0", + "y-websocket": "^1.5.4", "yjs": "^13.6.12", "zundo": "^2.0.0-beta.5", "zustand": "^4.1.4" diff --git a/app/frontend/src/state/server/annotation.ts b/app/frontend/src/state/server/annotation.ts index 08d01e4..3931052 100644 --- a/app/frontend/src/state/server/annotation.ts +++ b/app/frontend/src/state/server/annotation.ts @@ -1,11 +1,11 @@ import {useQuery, useMutation} from '@tanstack/react-query'; -import {createYjsProvider} from '@y-sweet/client'; import {NutshClientContext} from 'common/context'; import {useYjsContext} from 'common/yjs/context'; import {writeAnnotationToYjs, readAnnotationFromYjs} from 'common/yjs/convert'; import type {NutshClient, DefaultService, Video} from 'openapi/nutsh'; import {mustDecodeJsonStr as mustDecodeAnnotationJsonStr} from 'type/annotation'; import {useContext} from 'react'; +import {WebsocketProvider} from 'y-websocket'; /** * @deprecated Use `useGetVideoAnnotationYjs`. @@ -32,17 +32,9 @@ export const useGetVideoAnnotationYjs = (id: Video['id']) => { return useQuery({ queryKey: ['getVideoAnnotationV2', id], queryFn: async () => { + // connect to the yjs server const origin = wsOrigin(); - const clientToken = { - url: `${origin}/ws/doc/ws`, - docId: `${id}`, - }; - - // connect the yjs doc to the Y-Sweet server - const provider = createYjsProvider(doc, clientToken, { - // disable cross-tab BroadcastChannel communication - disableBc: true, - }); + const provider = new WebsocketProvider(origin, `ws/video/${id}`, doc); // reconstruct the initial annotation const annoJson = await new Promise(resolve => { diff --git a/main.go b/main.go index 79d9a10..a856f47 100644 --- a/main.go +++ b/main.go @@ -17,12 +17,12 @@ import ( //go:embed app/frontend/build/* var frontend embed.FS +//go:embed app/yjs-server/bin/yjs-server +var yjsServer []byte + //go:embed docs/build/* var docs embed.FS -//go:embed bin/y-sweet -var ysweet []byte - func main() { mustSetupLogger() @@ -108,7 +108,7 @@ func main() { func runStart(ctx *cli.Context) error { action.StartOption.Frontend = echo.MustSubFS(frontend, "app/frontend/build") action.StartOption.Doc = echo.MustSubFS(docs, "docs/build") - action.StartOption.YSweetBin = ysweet + action.StartOption.YJSServer = yjsServer return action.Start(ctx.Context) } diff --git a/script/download_y_sweet.sh b/script/download_y_sweet.sh deleted file mode 100644 index f1f03aa..0000000 --- a/script/download_y_sweet.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -version="0.1.1" -default_os=$(uname -s) -default_arch=$(uname -m) - -os=${GOOS:-$default_os} -arch=${GOARCH:-$default_arch} - -if [[ "$os" == "linux" || "$os" == "Linux" ]]; then - os="linux" -elif [[ "$os" == "darwin" || "$os" == "Darwin" ]]; then - os="macos" -else - echo "Unsupported OS" - exit 1 -fi - -if [[ "$arch" == "amd64" || "$arch" == "x86_64" ]]; then - arch="x64" -elif [[ "$arch" == "arm64" ]]; then - arch="arm64" -else - echo "Unsupported architecture" - exit 1 -fi - -filename="y-sweet-${os}-${arch}.gz" -url="https://github.com/drifting-in-space/y-sweet/releases/download/v${version}/y-sweet-${os}-${arch}.gz" - -# Download the file -mkdir -p bin -echo "downloading ${filename} from ${url} ..." -curl -sL $url | gzip -d > bin/y-sweet - -echo "download completed" \ No newline at end of file