File tree 3 files changed +8
-6
lines changed
3 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export class RealtimeAPI extends RealtimeEventHandler {
14
14
this . apiKey = apiKey || null ;
15
15
this . debug = ! ! debug ;
16
16
this . ws = null ;
17
- if ( globalThis . WebSocket && this . apiKey ) {
17
+ if ( globalThis . document && this . apiKey ) {
18
18
if ( ! dangerouslyAllowAPIKeyInBrowser ) {
19
19
throw new Error (
20
20
`Can not provide API key in the browser without "dangerouslyAllowAPIKeyInBrowser" set to true` ,
@@ -63,7 +63,7 @@ export class RealtimeAPI extends RealtimeEventHandler {
63
63
if ( this . isConnected ( ) ) {
64
64
throw new Error ( `Already connected` ) ;
65
65
}
66
- if ( globalThis . WebSocket ) {
66
+ if ( globalThis . document ) {
67
67
/**
68
68
* Web browser
69
69
*/
Original file line number Diff line number Diff line change @@ -11,6 +11,12 @@ export async function run({ debug = false } = {}) {
11
11
before ( async ( ) => {
12
12
const WebSocket = ( await import ( 'websocket' ) ) . default . w3cwebsocket ;
13
13
globalThis . WebSocket = WebSocket ;
14
+ globalThis . document = { } ;
15
+ } ) ;
16
+
17
+ after ( async ( ) => {
18
+ globalThis . WebSocket = void 0 ;
19
+ globalThis . document = void 0 ;
14
20
} ) ;
15
21
16
22
it ( 'Should fail to instantiate the RealtimeClient when "dangerouslyAllowAPIKeyInBrowser" is not set' , ( ) => {
Original file line number Diff line number Diff line change @@ -8,10 +8,6 @@ export async function run({ debug = false } = {}) {
8
8
let client ;
9
9
let realtimeEvents = [ ] ;
10
10
11
- before ( async ( ) => {
12
- globalThis . WebSocket = void 0 ;
13
- } ) ;
14
-
15
11
it ( 'Should instantiate the RealtimeClient' , ( ) => {
16
12
client = new RealtimeClient ( {
17
13
apiKey : process . env . OPENAI_API_KEY ,
You can’t perform that action at this time.
0 commit comments