@dxos/websocket-rpc 0.8.4-main.84f28bd → 0.8.4-main.937b3ca
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/dist/lib/browser/index.mjs +13 -8
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +13 -8
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/client.d.ts +2 -2
- package/dist/types/src/client.d.ts.map +1 -1
- package/dist/types/src/server.d.ts +3 -3
- package/dist/types/src/server.d.ts.map +1 -1
- package/dist/types/src/token-auth.d.ts +1 -1
- package/dist/types/src/token-auth.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -7
- package/src/client.ts +3 -3
- package/src/e2e.node.test.ts +3 -3
- package/src/server.ts +7 -6
- package/src/token-auth.ts +2 -1
package/package.json
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/websocket-rpc",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.937b3ca",
|
|
4
4
|
"description": "websocket-rpc",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
7
11
|
"license": "MIT",
|
|
8
12
|
"author": "DXOS.org",
|
|
9
|
-
"sideEffects":
|
|
13
|
+
"sideEffects": false,
|
|
10
14
|
"type": "module",
|
|
11
15
|
"exports": {
|
|
12
16
|
".": {
|
|
17
|
+
"source": "./src/index.ts",
|
|
13
18
|
"types": "./dist/types/src/index.d.ts",
|
|
14
19
|
"browser": "./dist/lib/browser/index.mjs",
|
|
15
20
|
"node": "./dist/lib/node-esm/index.mjs"
|
|
@@ -27,11 +32,11 @@
|
|
|
27
32
|
"dependencies": {
|
|
28
33
|
"isomorphic-ws": "^5.0.0",
|
|
29
34
|
"ws": "^8.14.2",
|
|
30
|
-
"@dxos/async": "0.8.4-main.
|
|
31
|
-
"@dxos/
|
|
32
|
-
"@dxos/
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
35
|
+
"@dxos/async": "0.8.4-main.937b3ca",
|
|
36
|
+
"@dxos/rpc": "0.8.4-main.937b3ca",
|
|
37
|
+
"@dxos/node-std": "0.8.4-main.937b3ca",
|
|
38
|
+
"@dxos/protocols": "0.8.4-main.937b3ca",
|
|
39
|
+
"@dxos/log": "0.8.4-main.937b3ca"
|
|
35
40
|
},
|
|
36
41
|
"devDependencies": {},
|
|
37
42
|
"publishConfig": {
|
package/src/client.ts
CHANGED
|
@@ -6,11 +6,11 @@ import WebSocket from 'isomorphic-ws';
|
|
|
6
6
|
|
|
7
7
|
import { Event, Trigger } from '@dxos/async';
|
|
8
8
|
import { log, logInfo } from '@dxos/log';
|
|
9
|
-
import {
|
|
9
|
+
import { type ProtoRpcPeer, type ProtoRpcPeerOptions, createProtoRpcPeer } from '@dxos/rpc';
|
|
10
10
|
|
|
11
11
|
import { WebSocketWithTokenAuth } from './token-auth';
|
|
12
12
|
|
|
13
|
-
export type
|
|
13
|
+
export type WebsocketRpcClientProps<C, S> = {
|
|
14
14
|
url: string;
|
|
15
15
|
authenticationToken?: string;
|
|
16
16
|
} & Pick<ProtoRpcPeerOptions<C, S>, 'requested' | 'exposed' | 'handlers' | 'noHandshake'>;
|
|
@@ -24,7 +24,7 @@ export class WebsocketRpcClient<C, S> {
|
|
|
24
24
|
readonly disconnected = new Event();
|
|
25
25
|
readonly error = new Event<Error>();
|
|
26
26
|
|
|
27
|
-
constructor(private readonly _params:
|
|
27
|
+
constructor(private readonly _params: WebsocketRpcClientProps<C, S>) {
|
|
28
28
|
this._rpc = createProtoRpcPeer({
|
|
29
29
|
requested: this._params.requested,
|
|
30
30
|
exposed: this._params.exposed,
|
package/src/e2e.node.test.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { describe, expect, onTestFinished, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { schema } from '@dxos/protocols/proto';
|
|
8
|
-
import {
|
|
8
|
+
import { type ServiceTypesOf, createServiceBundle } from '@dxos/rpc';
|
|
9
9
|
|
|
10
10
|
import { WebsocketRpcClient } from './client';
|
|
11
11
|
import { WebsocketRpcServer } from './server';
|
|
@@ -24,7 +24,7 @@ describe('e2e', () => {
|
|
|
24
24
|
requested: {},
|
|
25
25
|
handlers: {
|
|
26
26
|
TestService: {
|
|
27
|
-
testCall: async (request) => {
|
|
27
|
+
testCall: async (request: any) => {
|
|
28
28
|
return {
|
|
29
29
|
data: request.data,
|
|
30
30
|
};
|
package/src/server.ts
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type IncomingMessage } from 'http';
|
|
6
|
-
import WebSocket from 'isomorphic-ws';
|
|
7
6
|
import { type Socket } from 'node:net';
|
|
8
7
|
|
|
8
|
+
import WebSocket from 'isomorphic-ws';
|
|
9
|
+
|
|
9
10
|
import { log } from '@dxos/log';
|
|
10
|
-
import {
|
|
11
|
+
import { type ProtoRpcPeer, type ProtoRpcPeerOptions, createProtoRpcPeer } from '@dxos/rpc';
|
|
11
12
|
|
|
12
13
|
export type ConnectionInfo = {
|
|
13
14
|
request: IncomingMessage;
|
|
@@ -18,16 +19,16 @@ export type ConnectionHandler<C, S> = {
|
|
|
18
19
|
onClose?: (rpc: ProtoRpcPeer<C>) => Promise<void>;
|
|
19
20
|
} & Pick<ProtoRpcPeerOptions<C, S>, 'requested' | 'exposed' | 'handlers'>;
|
|
20
21
|
|
|
21
|
-
export type
|
|
22
|
+
export type WebsocketRpcServerProps<C, S> = {
|
|
22
23
|
onConnection: (info: ConnectionInfo) => Promise<ConnectionHandler<C, S>>;
|
|
23
24
|
} & WebSocket.ServerOptions;
|
|
24
25
|
|
|
25
26
|
export class WebsocketRpcServer<C, S> {
|
|
26
27
|
private _server?: WebSocket.Server;
|
|
27
28
|
|
|
28
|
-
constructor(private readonly _params:
|
|
29
|
+
constructor(private readonly _params: WebsocketRpcServerProps<C, S>) {}
|
|
29
30
|
handleUpgrade(request: IncomingMessage, socket: Socket, head: Buffer): void {
|
|
30
|
-
this._server?.handleUpgrade(request, socket, head, (ws) => {
|
|
31
|
+
this._server?.handleUpgrade(request, socket, head, (ws: WebSocket) => {
|
|
31
32
|
this._server?.emit('connection', ws, request);
|
|
32
33
|
});
|
|
33
34
|
}
|
|
@@ -36,7 +37,7 @@ export class WebsocketRpcServer<C, S> {
|
|
|
36
37
|
this._server = new WebSocket.Server({
|
|
37
38
|
...this._params,
|
|
38
39
|
});
|
|
39
|
-
this._server.on('connection', async (socket, request) => {
|
|
40
|
+
this._server.on('connection', async (socket: WebSocket, request: IncomingMessage) => {
|
|
40
41
|
log('connection', { url: request.url, headers: request.headers });
|
|
41
42
|
const info: ConnectionInfo = {
|
|
42
43
|
request,
|
package/src/token-auth.ts
CHANGED
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
// https://stackoverflow.com/questions/4361173/http-headers-in-websockets-client-api/77060459#77060459
|
|
7
7
|
|
|
8
8
|
import { type IncomingMessage } from 'http';
|
|
9
|
-
import WebSocket from 'isomorphic-ws';
|
|
10
9
|
import { type Socket } from 'node:net';
|
|
11
10
|
|
|
11
|
+
import WebSocket from 'isomorphic-ws';
|
|
12
|
+
|
|
12
13
|
import { log } from '@dxos/log';
|
|
13
14
|
|
|
14
15
|
const PROTOCOL_TOKEN_PREFIX = 'base64url.bearer.authorization.dxos.org';
|