enso/app/gui2/ydoc-server/indexPolyglot.ts
Dmitry Bushev 858e646328
Start Ydoc with the language server (#9862)
- related #7954

Changelog:
- update: Ydoc starts with the language server on the `localhost:1234` by default. The hostname and ports can be configured by setting environment variables `LANGUAGE_SERVER_YDOC_HOSTNAME` and `LANGUAGE_SERVER_YDOC_PORT`
- update: by default `npm dev run` uses the node Ydoc server. You can control it with `POLYGLOT_YDOC_SERVER` env variable. For example,
```
env POLYGLOT_YDOC_SERVER='true' npm --workspace=enso-gui2 run dev
```
To connect to the Ydoc server running on the 1234 port (the one started with the language server)
⠀
```
env POLYGLOT_YDOC_SERVER='ws://127.0.0.1:1235' npm --workspace=enso-gui2 run dev
```
To connect to the provided URL. Can be useful for debugging when you start a separate Ydoc process.
- update: run `npm install` before the engine build. It is required to create the Ydoc JS bundle.
2024-05-28 13:51:42 +00:00

36 lines
811 B
TypeScript

/**
* @file An entry point for polyglot Yjs gateway server.
*/
import { docName } from './auth'
import { setupGatewayClient } from './ydoc'
declare global {
class WebSocketServer {
constructor(config: any)
onconnect: ((socket: any, url: any) => any) | null
start(): void
}
const YDOC_HOST: string | undefined
const YDOC_PORT: number | undefined
}
const host = YDOC_HOST ?? 'localhost'
const port = YDOC_PORT ?? 1234
const wss = new WebSocketServer({ host, port })
wss.onconnect = (socket, url) => {
const doc = docName(url.pathname)
const ls = url.searchParams.get('ls')
if (doc != null && ls != null) {
console.log('setupGatewayClient', ls, doc)
setupGatewayClient(socket, ls, doc)
} else {
console.log('Failed to authenticate user', ls, doc)
}
}
wss.start()