Skip to content

Commit 44f907e

Browse files
committed
Add user_agent to websocket setup data.
1 parent 0f78814 commit 44f907e

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

packages/service-core/src/routes/configure-rsocket.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function configureRSocket(router: ReactiveSocketRouter<Context>, options:
2323

2424
router.applyWebSocketEndpoints(server, {
2525
contextProvider: async (data: Buffer) => {
26-
const { token } = RSocketContextMeta.decode(deserialize(data) as any);
26+
const { token, user_agent } = RSocketContextMeta.decode(deserialize(data) as any);
2727

2828
if (!token) {
2929
throw new errors.AuthorizationError('No token provided');
@@ -38,6 +38,7 @@ export function configureRSocket(router: ReactiveSocketRouter<Context>, options:
3838
}
3939
return {
4040
token,
41+
user_agent,
4142
...context,
4243
token_errors: token_errors,
4344
system

packages/service-core/src/routes/endpoints/socket-route.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export const syncStreamReactive: SocketRouteGenerator = (router) =>
124124
disposer();
125125
logger.info(`Sync stream complete`, {
126126
user_id: syncParams.user_id,
127+
user_agent: context.user_agent,
127128
operations_synced: tracker.operationsSynced,
128129
data_synced_bytes: tracker.dataSyncedBytes
129130
});

packages/service-core/src/routes/router-socket.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ import { Context } from './router.js';
99
export type SocketRouteGenerator = (router: ReactiveSocketRouter<Context>) => IReactiveStream;
1010

1111
export const RSocketContextMeta = t.object({
12-
token: t.string
12+
token: t.string,
13+
user_agent: t.string.optional()
1314
});

packages/service-core/src/routes/router.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export type Context = {
1111

1212
token_payload?: auth.JwtPayload;
1313
token_errors?: string[];
14+
/**
15+
* Only on websocket endpoints.
16+
*/
17+
user_agent?: string;
1418
};
1519

1620
export type BasicRouterRequest = {

0 commit comments

Comments
 (0)