File tree Expand file tree Collapse file tree 3 files changed +8
-6
lines changed Expand file tree Collapse file tree 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 {
1414 this . apiKey = apiKey || null ;
1515 this . debug = ! ! debug ;
1616 this . ws = null ;
17- if ( globalThis . WebSocket && this . apiKey ) {
17+ if ( globalThis . document && this . apiKey ) {
1818 if ( ! dangerouslyAllowAPIKeyInBrowser ) {
1919 throw new Error (
2020 `Can not provide API key in the browser without "dangerouslyAllowAPIKeyInBrowser" set to true` ,
@@ -63,7 +63,7 @@ export class RealtimeAPI extends RealtimeEventHandler {
6363 if ( this . isConnected ( ) ) {
6464 throw new Error ( `Already connected` ) ;
6565 }
66- if ( globalThis . WebSocket ) {
66+ if ( globalThis . document ) {
6767 /**
6868 * Web browser
6969 */
Original file line number Diff line number Diff line change @@ -11,6 +11,12 @@ export async function run({ debug = false } = {}) {
1111 before ( async ( ) => {
1212 const WebSocket = ( await import ( 'websocket' ) ) . default . w3cwebsocket ;
1313 globalThis . WebSocket = WebSocket ;
14+ globalThis . document = { } ;
15+ } ) ;
16+
17+ after ( async ( ) => {
18+ globalThis . WebSocket = void 0 ;
19+ globalThis . document = void 0 ;
1420 } ) ;
1521
1622 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 } = {}) {
88 let client ;
99 let realtimeEvents = [ ] ;
1010
11- before ( async ( ) => {
12- globalThis . WebSocket = void 0 ;
13- } ) ;
14-
1511 it ( 'Should instantiate the RealtimeClient' , ( ) => {
1612 client = new RealtimeClient ( {
1713 apiKey : process . env . OPENAI_API_KEY ,
You can’t perform that action at this time.
0 commit comments