MCPcopy Index your code
hub / github.com/tinyplex/tinybase / getMessageHandler

Function getMessageHandler

src/synchronizers/synchronizer-ws-server/index.ts:173–189  ·  view source on GitHub ↗
(clientId: Id, clients: IdMap<WebSocket>, serverClient: ServerClient)

Source from the content-addressed store, hash-verified

171
172 const getMessageHandler =
173 (clientId: Id, clients: IdMap<WebSocket>, serverClient: ServerClient) =>
174 (payload: string) =>
175 ifPayloadValid(payload, (toClientId, remainder) => {
176 const forwardedPayload = createRawPayload(clientId, remainder);
177 if (toClientId === EMPTY_STRING) {
178 if (clientId !== SERVER_CLIENT_ID) {
179 serverClient[Sc.Send]?.(forwardedPayload);
180 }
181 mapForEach(clients, (otherClientId, otherClient) =>
182 otherClientId !== clientId ? otherClient.send(forwardedPayload) : 0,
183 );
184 } else if (toClientId === SERVER_CLIENT_ID) {
185 serverClient[Sc.Send]?.(forwardedPayload);
186 } else {
187 mapGet(clients, toClientId)?.send(forwardedPayload);
188 }
189 });
190
191 webSocketServer.on('connection', (client, request) =>
192 ifNotUndefined(strMatch(request.url, PATH_REGEX), ([, pathId]) =>

Callers 2

configureServerClientFunction · 0.85
index.tsFile · 0.85

Calls 5

ifPayloadValidFunction · 0.90
createRawPayloadFunction · 0.90
mapForEachFunction · 0.90
mapGetFunction · 0.90
sendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…