@@ -7,15 +7,10 @@ import { addDisposer, types } from 'mobx-state-tree'
77import { readSessionFromDynamo } from './sessionSharing'
88import { addRelativeUris , checkPlugins , fromUrlSafeB64 , readConf } from './util'
99
10+ import type { SessionTriagedInfo } from './types'
1011import type { PluginDefinition , PluginRecord } from '@jbrowse/core/PluginLoader'
1112import type { Instance } from 'mobx-state-tree'
1213
13- export interface SessionTriagedInfo {
14- snap : unknown
15- origin : string
16- reason : PluginDefinition [ ]
17- }
18-
1914const SessionLoader = types
2015 . model ( {
2116 /**
@@ -66,6 +61,11 @@ const SessionLoader = types
6661 * #property
6762 */
6863 initialTimestamp : types . number ,
64+
65+ /**
66+ * #property
67+ */
68+ hubURL : types . maybe ( types . array ( types . string ) ) ,
6969 } )
7070 . volatile ( ( ) => ( {
7171 /**
@@ -84,6 +84,10 @@ const SessionLoader = types
8484 * #volatile
8585 */
8686 sessionSpec : undefined as Record < string , unknown > | undefined ,
87+ /**
88+ * #volatile
89+ */
90+ hubSpec : undefined as Record < string , unknown > | undefined ,
8791 /**
8892 * #volatile
8993 */
@@ -134,6 +138,12 @@ const SessionLoader = types
134138 get isSpecSession ( ) {
135139 return ! ! self . sessionQuery ?. startsWith ( 'spec-' )
136140 } ,
141+ /**
142+ * #getter
143+ */
144+ get isHubSession ( ) {
145+ return ! ! self . hubURL
146+ } ,
137147 /**
138148 * #getter
139149 */
@@ -275,8 +285,7 @@ const SessionLoader = types
275285 try {
276286 const pluginLoader = new PluginLoader ( snap . sessionPlugins || [ ] , {
277287 fetchESM : url => import ( /* webpackIgnore:true */ url ) ,
278- } )
279- pluginLoader . installGlobalReExports ( window )
288+ } ) . installGlobalReExports ( window )
280289 const plugins = await pluginLoader . load ( window . location . href )
281290 self . setSessionPlugins ( [ ...plugins ] )
282291 } catch ( e ) {
@@ -315,38 +324,38 @@ const SessionLoader = types
315324 */
316325 async fetchConfig ( ) {
317326 // @ts -expect-error
327+ const path = window . __jbrowseConfigPath
328+ const { hubURL, configPath = path || 'config.json' } = self
329+ if ( ! hubURL ) {
330+ const text = await openLocation ( {
331+ uri :
332+ configPath +
333+ // @ts -expect-error
334+ ( window . __jbrowseCacheBuster ? `?rand=${ Math . random ( ) } ` : '' ) ,
335+ locationType : 'UriLocation' ,
336+ } ) . readFile ( 'utf8' )
337+ const config = JSON . parse ( text )
338+ const configUri = new URL ( configPath , window . location . href )
339+ addRelativeUris ( config , configUri )
318340
319- let { configPath = window . __jbrowseConfigPath || 'config.json' } = self
320-
321- // @ts -expect-error
322-
323- if ( window . __jbrowseCacheBuster ) {
324- configPath += `?rand=${ Math . random ( ) } `
325- }
326-
327- const text = await openLocation ( {
328- uri : configPath ,
329- locationType : 'UriLocation' ,
330- } ) . readFile ( 'utf8' )
331- const config = JSON . parse ( text )
332- const configUri = new URL ( configPath , window . location . href )
333- addRelativeUris ( config , configUri )
334-
335- // cross origin config check
336- if ( configUri . hostname !== window . location . hostname ) {
337- const configPlugins = config . plugins || [ ]
338- const configPluginsAllowed = await checkPlugins ( configPlugins )
339- if ( ! configPluginsAllowed ) {
340- self . setSessionTriaged ( {
341- snap : config ,
342- origin : 'config' ,
343- reason : configPlugins ,
344- } )
345- return
341+ // cross origin config check
342+ if ( configUri . hostname !== window . location . hostname ) {
343+ const configPlugins = config . plugins || [ ]
344+ const configPluginsAllowed = await checkPlugins ( configPlugins )
345+ if ( ! configPluginsAllowed ) {
346+ self . setSessionTriaged ( {
347+ snap : config ,
348+ origin : 'config' ,
349+ reason : configPlugins ,
350+ } )
351+ return
352+ }
346353 }
354+ await this . fetchPlugins ( config )
355+ self . setConfigSnapshot ( config )
356+ } else {
357+ self . setConfigSnapshot ( { } )
347358 }
348- await this . fetchPlugins ( config )
349- self . setConfigSnapshot ( config )
350359 } ,
351360 /**
352361 * #action
@@ -399,7 +408,10 @@ const SessionLoader = types
399408 )
400409
401410 const session = JSON . parse ( await fromUrlSafeB64 ( decryptedSession ) )
402- await this . setSessionSnapshot ( { ...session , id : nanoid ( ) } )
411+ await this . setSessionSnapshot ( {
412+ ...session ,
413+ id : nanoid ( ) ,
414+ } )
403415 } ,
404416 /**
405417 * #action
@@ -409,7 +421,10 @@ const SessionLoader = types
409421 // @ts -expect-error
410422 await fromUrlSafeB64 ( self . sessionQuery . replace ( 'encoded-' , '' ) ) ,
411423 )
412- await this . setSessionSnapshot ( { ...session , id : nanoid ( ) } )
424+ await this . setSessionSnapshot ( {
425+ ...session ,
426+ id : nanoid ( ) ,
427+ } )
413428 } ,
414429 /**
415430 * #action
@@ -451,13 +466,28 @@ const SessionLoader = types
451466 }
452467 }
453468 } ,
469+
470+ /**
471+ * #action
472+ */
473+ decodeHubSpec ( ) {
474+ const { hubURL, sessionTracksParsed : sessionTracks } = self
475+
476+ self . hubSpec = {
477+ sessionTracks,
478+ hubURL,
479+ }
480+ } ,
454481 /**
455482 * #action
456483 */
457484 async decodeJsonUrlSession ( ) {
458485 // @ts -expect-error
459- const session = JSON . parse ( self . sessionQuery . replace ( 'json-' , '' ) )
460- await this . setSessionSnapshot ( { ...session . session , id : nanoid ( ) } )
486+ const { session } = JSON . parse ( self . sessionQuery . replace ( / ^ j s o n - / , '' ) )
487+ await this . setSessionSnapshot ( {
488+ ...session ,
489+ id : nanoid ( ) ,
490+ } )
461491 } ,
462492 /**
463493 * #aftercreate
@@ -479,6 +509,7 @@ const SessionLoader = types
479509 isSharedSession,
480510 isJsonSession,
481511 isJb1StyleSession,
512+ isHubSession,
482513 sessionQuery,
483514 configSnapshot,
484515 } = self
@@ -505,6 +536,9 @@ const SessionLoader = types
505536 this . decodeJb1StyleSession ( )
506537 } else if ( isEncodedSession ) {
507538 await this . decodeEncodedUrlSession ( )
539+ } else if ( isHubSession ) {
540+ this . decodeHubSpec ( )
541+ self . setBlankSession ( true )
508542 } else if ( isJsonSession ) {
509543 await this . decodeJsonUrlSession ( )
510544 } else if ( isLocalSession ) {
@@ -525,7 +559,6 @@ const SessionLoader = types
525559 } catch ( e ) {
526560 console . error ( e )
527561 self . setConfigError ( e )
528- return
529562 }
530563 } ) ( )
531564 } ,
0 commit comments