@@ -4,6 +4,11 @@ import type { AsyncResponseManagerOpts } from "../shared/async";
44import { adapters } from "@rails/actioncable" ;
55import * as WS from "ws" ;
66
7+ declare global {
8+ function addEventListener ( type : string , listener : ( ) => void ) : void ;
9+ function removeEventListener ( type : string , listener : ( ) => void ) : void ;
10+ }
11+
712export type ServerAsyncResponseManagerOpts = {
813 apiHost : string ;
914 getOauthToken : ( ) => Promise < AccessToken > | AccessToken ;
@@ -16,12 +21,20 @@ export class ServerAsyncResponseManager extends AsyncResponseManager {
1621 constructor ( opts : ServerAsyncResponseManagerOpts ) {
1722 super ( ) ;
1823 this . serverOpts = opts ;
24+ // eslint-disable-next-line @typescript-eslint/no-empty-function
25+ global . addEventListener = ( ) => { } ;
26+ // eslint-disable-next-line @typescript-eslint/no-empty-function
27+ global . removeEventListener = ( ) => { } ;
1928 if ( typeof adapters . WebSocket === "undefined" )
20- adapters . WebSocket == WS ;
29+ adapters . WebSocket = WS as unknown as WebSocket ;
2130 }
2231
2332 protected override async getOpts ( ) : Promise < AsyncResponseManagerOpts > {
24- const token = await this . serverOpts . getOauthToken ( ) ;
33+ const oauthToken = await this . serverOpts . getOauthToken ( ) ;
34+ if ( ! oauthToken ?. token ?. access_token ) {
35+ throw new Error ( "Invalid OAuth token structure" ) ;
36+ }
37+ const token = oauthToken . token . access_token ;
2538 const projectId = await this . serverOpts . getProjectId ( ) ;
2639 return {
2740 url : `wss://${ this . serverOpts . apiHost } /websocket?oauth_token=${ token } ` ,
0 commit comments