Skip to content

Commit 3f64535

Browse files
authored
1337 Move getWebSocket to utils.ts (#1877)
1 parent dbb3988 commit 3f64535

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

.changeset/small-vans-glow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@orchestrator-ui/orchestrator-ui-components': patch
3+
---
4+
5+
1337 Move getWebSocket to utils.ts

packages/orchestrator-ui-components/src/rtk/endpoints/streamMessages.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
11
import { debounce } from 'lodash';
2-
import { getSession } from 'next-auth/react';
32

4-
import type { WfoSession } from '@/hooks';
3+
import { getWebSocket, orchestratorApi } from '@/rtk';
54
import type { RootState } from '@/rtk/store';
65
import { CacheTag, CacheTagType } from '@/types';
76

8-
import { orchestratorApi } from '../api';
9-
10-
const getWebSocket = async (url: string) => {
11-
const session = (await getSession()) as WfoSession;
12-
13-
if (session?.accessToken) {
14-
// Implemented authentication taking this into account: https://stackoverflow.com/questions/4361173/http-headers-in-websockets-client-api/77060459#77060459
15-
return new WebSocket(url, [
16-
'base64.bearer.token',
17-
session?.accessToken,
18-
]);
19-
} else {
20-
return new WebSocket(url);
21-
}
22-
};
23-
247
const PING_INTERVAL_MS = 30000;
258
const NO_PONG_RECEIVED_TIMEOUT_MS = 35000;
269
const INITIAL_CONNECTION_CHECK_INTERVAL_MS = 2000;

packages/orchestrator-ui-components/src/rtk/utils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { GraphQLError } from 'graphql/error/GraphQLError';
22
import { isPlainObject } from 'lodash';
3+
import { getSession } from 'next-auth/react';
34

45
import { SerializedError } from '@reduxjs/toolkit';
56
import { FetchBaseQueryError } from '@reduxjs/toolkit/query';
67

8+
import type { WfoSession } from '@/hooks';
79
import { WfoGraphqlError } from '@/rtk/api';
810

911
export function stripUndefined(obj: object): Record<string, unknown> {
@@ -77,3 +79,17 @@ export const mapRtkErrorToWfoError = (
7779
}
7880
return error;
7981
};
82+
83+
export const getWebSocket = async (url: string) => {
84+
const session = (await getSession()) as WfoSession;
85+
86+
if (session?.accessToken) {
87+
// Implemented authentication taking this into account: https://stackoverflow.com/questions/4361173/http-headers-in-websockets-client-api/77060459#77060459
88+
return new WebSocket(url, [
89+
'base64.bearer.token',
90+
session?.accessToken,
91+
]);
92+
} else {
93+
return new WebSocket(url);
94+
}
95+
};

0 commit comments

Comments
 (0)