1- import { SessionWrapper } from '@deephaven/dashboard-core-plugins' ;
1+ import {
2+ SessionDetails ,
3+ SessionWrapper ,
4+ } from '@deephaven/dashboard-core-plugins' ;
25import dh , {
36 CoreClient ,
47 IdeConnection ,
58 LoginOptions ,
69} from '@deephaven/jsapi-shim' ;
10+ import {
11+ LOGIN_OPTIONS_REQUEST ,
12+ requestParentResponse ,
13+ SESSION_DETAILS_REQUEST ,
14+ } from '@deephaven/jsapi-utils' ;
715import Log from '@deephaven/log' ;
816import shortid from 'shortid' ;
917import NoConsolesError from './NoConsolesError' ;
@@ -50,7 +58,8 @@ export function createConnection(): IdeConnection {
5058 * @returns A session and config that is ready to use
5159 */
5260export async function createSessionWrapper (
53- connection : IdeConnection
61+ connection : IdeConnection ,
62+ details : SessionDetails
5463) : Promise < SessionWrapper > {
5564 log . info ( 'Getting console types...' ) ;
5665
@@ -72,7 +81,12 @@ export async function createSessionWrapper(
7281
7382 log . info ( 'Console session established' , config ) ;
7483
75- return { session, config, connection } ;
84+ return {
85+ session,
86+ config,
87+ connection,
88+ details,
89+ } ;
7690}
7791
7892export function createCoreClient ( ) : CoreClient {
@@ -83,29 +97,12 @@ export function createCoreClient(): CoreClient {
8397 return new dh . CoreClient ( websocketUrl ) ;
8498}
8599
86- export async function requestParentLoginOptions ( ) : Promise < LoginOptions > {
87- if ( window . opener == null ) {
88- throw new Error ( 'window.opener is null, unable to send auth request.' ) ;
89- }
90- return new Promise ( resolve => {
91- const listener = (
92- event : MessageEvent < {
93- message : string ;
94- payload : LoginOptions ;
95- } >
96- ) => {
97- const { data } = event ;
98- log . debug ( 'Received message' , data ) ;
99- if ( data ?. message !== 'loginOptions' ) {
100- log . debug ( 'Ignore received message' , data ) ;
101- return ;
102- }
103- window . removeEventListener ( 'message' , listener ) ;
104- resolve ( data . payload ) ;
105- } ;
106- window . addEventListener ( 'message' , listener ) ;
107- window . opener . postMessage ( 'requestLoginOptionsFromParent' , '*' ) ;
108- } ) ;
100+ async function requestParentLoginOptions ( ) : Promise < LoginOptions > {
101+ return requestParentResponse < LoginOptions > ( LOGIN_OPTIONS_REQUEST ) ;
102+ }
103+
104+ async function requestParentSessionDetails ( ) : Promise < SessionDetails > {
105+ return requestParentResponse < SessionDetails > ( SESSION_DETAILS_REQUEST ) ;
109106}
110107
111108export async function getLoginOptions (
@@ -121,4 +118,17 @@ export async function getLoginOptions(
121118 }
122119}
123120
121+ export async function getSessionDetails (
122+ authType : AUTH_TYPE
123+ ) : Promise < SessionDetails > {
124+ switch ( authType ) {
125+ case AUTH_TYPE . PARENT :
126+ return requestParentSessionDetails ( ) ;
127+ case AUTH_TYPE . ANONYMOUS :
128+ return { } ;
129+ default :
130+ throw new Error ( `Unknown auth type: ${ authType } ` ) ;
131+ }
132+ }
133+
124134export default { createSessionWrapper } ;
0 commit comments