forked from QwikDev/devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
18 lines (15 loc) · 653 Bytes
/
Copy pathserver.ts
File metadata and controls
18 lines (15 loc) · 653 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { ClientFunctions, ServerFunctions } from './types';
import { DEVTOOLS_VITE_MESSAGING_EVENT } from './constants';
import { setViteServerRpc, getViteServerContext } from './context';
import { createSerializedRpc } from './rpc-core';
export function createServerRpc(functions: ServerFunctions) {
const server = getViteServerContext();
const rpc = createSerializedRpc<ClientFunctions, ServerFunctions>(functions, {
post: (data) => server.ws.send(DEVTOOLS_VITE_MESSAGING_EVENT, data),
on: (handler) =>
server.ws.on(DEVTOOLS_VITE_MESSAGING_EVENT, (data: any) => {
handler(data);
}),
});
setViteServerRpc(rpc);
}