@xwiki/cristal-realtime 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE +505 -0
- package/dist/index.js +39721 -0
- package/package.json +33 -0
- package/src/index.ts +53 -0
- package/tsconfig.json +8 -0
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xwiki/cristal-realtime",
|
|
3
|
+
"version": "0.11.0",
|
|
4
|
+
"license": "LGPL 2.1",
|
|
5
|
+
"author": "XWiki Org Community <contact@xwiki.org>",
|
|
6
|
+
"homepage": "https://cristal.xwiki.org/",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"directory": "realtime",
|
|
10
|
+
"url": "https://github.com/xwiki-contrib/cristal/"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://jira.xwiki.org/projects/CRISTAL/"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@hocuspocus/server": "2.13.7",
|
|
18
|
+
"express": "4.21.1",
|
|
19
|
+
"express-ws": "5.0.2"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/express": "5.0.0",
|
|
23
|
+
"@types/express-ws": "3.0.5",
|
|
24
|
+
"esbuild": "0.24.0",
|
|
25
|
+
"tsx": "4.19.1"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc --project tsconfig.json && esbuild ./src/index.ts --bundle --outfile=dist/index.js --platform=node",
|
|
29
|
+
"clean": "rimraf dist",
|
|
30
|
+
"dev": "tsx src/index.ts",
|
|
31
|
+
"lint": "eslint \"./src/**/*.{ts,tsx}\" --max-warnings=0"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* See the LICENSE file distributed with this work for additional
|
|
3
|
+
* information regarding copyright ownership.
|
|
4
|
+
*
|
|
5
|
+
* This is free software; you can redistribute it and/or modify it
|
|
6
|
+
* under the terms of the GNU Lesser General Public License as
|
|
7
|
+
* published by the Free Software Foundation; either version 2.1 of
|
|
8
|
+
* the License, or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This software is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13
|
+
* Lesser General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Lesser General Public
|
|
16
|
+
* License along with this software; if not, write to the Free
|
|
17
|
+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
18
|
+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import express from "express";
|
|
22
|
+
import expressWebsockets from "express-ws";
|
|
23
|
+
import { Server as HocuspocusServer } from "@hocuspocus/server";
|
|
24
|
+
|
|
25
|
+
const hocuspocusServer = HocuspocusServer.configure({
|
|
26
|
+
// See https://developer.chrome.com/blog/timer-throttling-in-chrome-88/
|
|
27
|
+
timeout: 60000,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const { app }: expressWebsockets.Instance = expressWebsockets(express());
|
|
31
|
+
|
|
32
|
+
// Add a WebSocket route for Hocuspocus.
|
|
33
|
+
app.ws("/collaboration", (webSocket, request) => {
|
|
34
|
+
// We can pass contextual information to the Hocuspocus server. For instance, we could authenticate the user here.
|
|
35
|
+
const context = {
|
|
36
|
+
//user: {
|
|
37
|
+
// id: 'mflorea',
|
|
38
|
+
// name: "Marius Florea",
|
|
39
|
+
//},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
hocuspocusServer.handleConnection(webSocket, request, context);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
let port = 15681;
|
|
46
|
+
const env_port = parseInt(process.env.REALTIME_HTTP_PORT || "");
|
|
47
|
+
if (!isNaN(env_port) && env_port > 0) {
|
|
48
|
+
port = env_port;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
app.listen(port, () => {
|
|
52
|
+
console.log(`Application is running on http://localhost:${port}`);
|
|
53
|
+
});
|