File tree Expand file tree Collapse file tree 3 files changed +71
-0
lines changed
Expand file tree Collapse file tree 3 files changed +71
-0
lines changed Original file line number Diff line number Diff line change 188188 _enter2d ( ) ;
189189 break ;
190190 }
191+ case 'loadScene' : {
192+ const { html} = data ;
193+ if ( html ) {
194+ root . setHTML ( html ) ;
195+ }
196+ break ;
197+ }
191198 }
192199} ) ;
193200
36223629 } else {
36233630 console . log ( 'paste fail' ) ;
36243631 }
3632+ } else if ( id === 'action-load-scene' ) {
3633+ window . parentPostMessage ( {
3634+ method : 'loadScene' ,
3635+ } ) ;
3636+ } else if ( id === 'action-save-scene' ) {
3637+ window . parentPostMessage ( {
3638+ method : 'saveScene' ,
3639+ html : root . outerHTML ,
3640+ } ) ;
36253641 } else if ( href ) {
36263642 const xrIframe = document . createElement ( 'xr-iframe' ) ;
36273643 xrIframe . src = href ;
Original file line number Diff line number Diff line change @@ -581,6 +581,41 @@ <h3>This beta requires login.</h3>
581581 if ( navigator . serviceWorker . controller ) { // avoid FOUC during reload
582582 xrScene = document . createElement ( 'xr-scene' ) ;
583583 xrScene . src = 'app.html' ;
584+ xrScene . addEventListener ( 'message' , async e => {
585+ const { data} = e ;
586+ const { method} = data ;
587+ if ( method === 'loadScene' ) {
588+ const res = await fetch ( '/.s/scene' ) ;
589+ if ( res . status >= 200 && res . status < 300 ) {
590+ const html = await res . text ( ) ;
591+ xrScene . postMessage ( {
592+ method : 'loadScene' ,
593+ html,
594+ } ) ;
595+ } else if ( res . status === 404 ) {
596+ xrScene . postMessage ( {
597+ method : 'loadScene' ,
598+ html : null ,
599+ } ) ;
600+ } else {
601+ console . warn ( `invalid status code: ${ res . status } ` ) ;
602+ }
603+ } else if ( method === 'saveScene' ) {
604+ const { html} = data ;
605+ const res = await fetch ( '/.s/scene' , {
606+ method : 'PUT' ,
607+ headers : {
608+ 'Content-Type' : 'text/html' ,
609+ } ,
610+ body : html ,
611+ } ) ;
612+ if ( res . status >= 200 && res . status < 300 ) {
613+ // nothing
614+ } else {
615+ console . warn ( `invalid status code: ${ res . status } ` ) ;
616+ }
617+ }
618+ } ) ;
584619 document . body . appendChild ( xrScene ) ;
585620
586621 const { email, code} = q ;
Original file line number Diff line number Diff line change @@ -279,6 +279,26 @@ <h3>Paste scene</h3>
279279 < p > Paste site from clipboard</ p >
280280 </ div >
281281 </ a >
282+ < a id =action-load-scene class =action >
283+ < div class =border > </ div >
284+ < div class =icon >
285+ < i class ="fal fa-folder-open "> </ i >
286+ </ div >
287+ < div class =wrap >
288+ < h3 > Load scene</ h3 >
289+ < p > Open the locally saved scene</ p >
290+ </ div >
291+ </ a >
292+ < a id =action-save-scene class =action >
293+ < div class =border > </ div >
294+ < div class =icon >
295+ < i class ="fal fa-save "> </ i >
296+ </ div >
297+ < div class =wrap >
298+ < h3 > Save scene</ h3 >
299+ < p > Save this site locally</ p >
300+ </ div >
301+ </ a >
282302 </ div >
283303 {{/tab2}}
284304 {{#tab4}}
You can’t perform that action at this time.
0 commit comments