Skip to content

Commit 709efed

Browse files
committed
fixed service-process-test and added readme
Signed-off-by: Jonah Iden <jonah.iden@typefox.io>
1 parent 697b6f9 commit 709efed

File tree

3 files changed

+76
-3
lines changed

3 files changed

+76
-3
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
## Usage
11+
12+
### Starting the Service Process
13+
14+
Start the process by either using [Node.js](https://nodejs.org) to call `process.js` or use a prebuilt executable:
15+
16+
```sh
17+
node ./lib/process.js --server-address http://localhost:8100 --auth-token <your-auth-token>
18+
```
19+
20+
- `--server-address` (**required**): The address of the collaboration server to connect to (e.g., `https://api.open-collab.tools`).
21+
- `--auth-token` (**optional**): The authentication token to use for the session, if saved by the application from a previous login
22+
23+
### Communication Protocol
24+
25+
All communication happens via JSON-RPC 2.0 messages over stdin/stdout.
26+
See [messages.ts](src/messages.ts) for service process specific awarness or lifecycle messages. Other messages follow the open-collaboration-protocol.
27+
28+
For specific examples see `service.process.test.ts` or the [IntellIj integration](https://github.com/eclipse-oct/oct-intellij)
29+
30+
### Sending and Receiving Binary Data
31+
32+
- For efficient document and file transfer, binary data is supported.
33+
- Use the `BinaryData` type for parameters or results that contain binary content.
34+
- Binary data is encoded as base64-encoded [MessagePack](https://msgpack.org/) in the `data` field of a `BinaryData` object.
35+
36+
#### Example: Sending Binary Data
37+
38+
```json
39+
{
40+
"jsonrpc": "2.0",
41+
"id": 1,
42+
"method": "awareness/getDocumentContent",
43+
"params": ["path/to/file"]
44+
}
45+
```
46+
47+
The response will be:
48+
49+
```json
50+
{
51+
"jsonrpc": "2.0",
52+
"id": 1,
53+
"result": {
54+
"type": "binaryData",
55+
"data": "<base64-encoded-messagepack>"
56+
}
57+
}
58+
```
59+
60+
Or sending Binary Data as a Parameter:
61+
62+
```json
63+
{
64+
"jsonrpc": "2.0",
65+
"id": 2,
66+
"method": "fileSystem/writeFile",
67+
"params": [
68+
{
69+
"type": "binaryData",
70+
"data": "<base64-encoded-messagepack>"
71+
}
72+
]
73+
}
74+
```

packages/open-collaboration-service-process/src/message-handler.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export class MessageHandler {
3333
clientCommunication.onError(([error]) => clientCommunication.sendNotification(InternalError, {message: error.message, stack: error.stack}));
3434

3535
clientCommunication.onRequest(async (method, params) => {
36-
console.log(params);
3736
if(!types.isArray(params) || params.length === 0 || typeof params[params.length - 1] !== 'string') {
3837
throw new Error(`Invalid parameters for non service process specific request with method: ${method}, missing target`);
3938
}

packages/open-collaboration-service-process/test/service.process.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('Service Process', () => {
143143

144144
expect(hostId).toBeTruthy();
145145

146-
const folderStat = await guest.communicationHandler.sendRequest('fileSystem/stat', 'testFolder', hostId );
146+
const folderStat = await guest.communicationHandler.sendRequest('fileSystem/stat', 'testFolder', hostId);
147147
expect(folderStat).toBeDefined();
148148

149149
// sending the file path as binary only for testing the conversion
@@ -161,7 +161,7 @@ describe('Service Process', () => {
161161

162162
await updateArived.promise;
163163

164-
}, 2000000);
164+
}, 60000);
165165
});
166166

167167
async function makeSimpleLoginRequest(token: string, username: string) {

0 commit comments

Comments
 (0)