Skip to content

Commit 77df349

Browse files
authored
Service process improvements (#137)
Signed-off-by: Jonah Iden <jonah.iden@typefox.io>
1 parent 6b772dc commit 77df349

9 files changed

Lines changed: 433 additions & 167 deletions

File tree

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ charset = utf-8
88
insert_final_newline = true
99
trim_trailing_whitespace = true
1010

11+
[*.xml]
12+
indent_size = 2
13+
1114
[*.yml]
1215
indent_size = 2
1316

.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "attach",
10+
"name": "Attach to Service Process",
11+
"port": "${input:attachPort}",
12+
13+
},
714
{
815
"type": "node",
916
"request": "launch",
@@ -85,5 +92,13 @@
8592
"sourceMaps": true,
8693
"outFiles": []
8794
}
95+
],
96+
"inputs": [
97+
{
98+
"id": "attachPort",
99+
"type": "promptString",
100+
"description": "What port should the application use for debugging?",
101+
"default": "23698"
102+
}
88103
]
89104
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Open Collaboration Service Process
2+
3+
Open Collaboration Tools is a collection of open source tools, libraries and extensions for live-sharing of IDE contents, designed to boost remote teamwork with open technologies. For more information about this project, please [read the announcement](https://www.typefox.io/blog/open-collaboration-tools-announcement/).
4+
5+
This package is a standalone Node.js application, which helps to simplify integration of OCT with non-TypeScript environments, by providing a stdin/stdout based [JSON-RPC](https://www.jsonrpc.org/) API.
6+
7+
It takes over encryption, session lifecycle management, and includes Yjs integration for collision-free real-time editing of documents,
8+
so client applications do not need to implement these complex features themselves.
9+
10+
The artifact needs to be cjs to be able to be bundled and made into an SEA because of socket.io's dynamic requires.
11+
12+
## Usage
13+
14+
### Starting the Service Process
15+
16+
Start the process by either using [Node.js](https://nodejs.org) to call `process.js` or use a prebuilt executable:
17+
18+
```sh
19+
node ./lib/process.js --server-address http://localhost:8100 --auth-token <your-auth-token>
20+
```
21+
22+
- `--server-address` (**required**): The address of the collaboration server to connect to (e.g., `https://api.open-collab.tools`).
23+
- `--auth-token` (**optional**): The authentication token to use for the session, if saved by the application from a previous login
24+
25+
### Communication Protocol
26+
27+
All communication happens via JSON-RPC 2.0 messages over stdin/stdout.
28+
See [messages.ts](src/messages.ts) for service process specific awareness or lifecycle messages. Other messages follow the open-collaboration-protocol.
29+
30+
For specific examples see `service.process.test.ts` or the [IntellIJ integration](https://github.com/eclipse-oct/oct-intellij)
31+
32+
### Sending and Receiving Binary Data
33+
34+
- For efficient document and file transfer, binary data is supported.
35+
- Use the `BinaryData` type for parameters or results that contain binary content.
36+
- Binary data is encoded as base64-encoded [MessagePack](https://msgpack.org/) in the `data` field of a `BinaryData` object.
37+
38+
#### Example: Sending Binary Data
39+
40+
```json
41+
{
42+
"jsonrpc": "2.0",
43+
"id": 1,
44+
"method": "awareness/getDocumentContent",
45+
"params": ["path/to/file"]
46+
}
47+
```
48+
49+
The response will be:
50+
51+
```json
52+
{
53+
"jsonrpc": "2.0",
54+
"id": 1,
55+
"result": {
56+
"type": "binaryData",
57+
"data": "<base64-encoded-messagepack>"
58+
}
59+
}
60+
```
61+
62+
Or sending Binary Data as a Parameter:
63+
64+
```json
65+
{
66+
"jsonrpc": "2.0",
67+
"id": 2,
68+
"method": "fileSystem/writeFile",
69+
"params": [
70+
{
71+
"type": "binaryData",
72+
"data": "<base64-encoded-messagepack>"
73+
}
74+
]
75+
}
76+
```

packages/open-collaboration-service-process/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"scripts": {
3131
"start": "node lib/process.js",
3232
"start:direct": "tsx src/process.ts",
33-
"build": "esbuild ./lib/process.js --bundle --platform=node --format=esm --outfile=lib/bundle.js",
33+
"build": "esbuild ./src/process.ts --bundle --platform=node --format=cjs --outfile=lib/bundle.cjs",
3434
"create:executable": "npm run build && shx mkdir -p bin && node --experimental-sea-config sea-config.json && node scripts/sea-build.mjs"
3535
},
3636
"dependencies": {

packages/open-collaboration-service-process/scripts/sea-build.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { inject } from 'postject'
88
* The resulting executable can be run as a standalone application without the need of nodejs being installed
99
*/
1010

11-
var EXECUTABLE_NAME = 'oct-servcice-process'
11+
var EXECUTABLE_NAME = 'oct-service-process'
1212

1313
if (process.platform === 'win32') {
1414
EXECUTABLE_NAME = EXECUTABLE_NAME + '.exe'

0 commit comments

Comments
 (0)