11// debug friend: document.writeln(JSON.stringify(value));
2+ //@ts -check
3+ /** @type {import('./webxdc').Webxdc<any> } */
24window . webxdc = ( ( ) => {
3- var updateListener = ( ) => { } ;
5+ var updateListener = ( _ ) => { } ;
46 var updatesKey = "__xdcUpdatesKey__" ;
57 window . addEventListener ( 'storage' , ( event ) => {
68 if ( event . key == null ) {
@@ -13,19 +15,14 @@ window.webxdc = (() => {
1315 }
1416 } ) ;
1517
18+ var params = new URLSearchParams ( window . location . hash . substr ( 1 ) ) ;
1619 return {
17- selfAddr : ( ) => {
18- var params = new URLSearchParams ( window . location . hash . substr ( 1 ) ) ;
19- return params . get ( "addr" ) || "device0@local.host" ;
20- } ,
21- selfName : ( ) => {
22- var params = new URLSearchParams ( window . location . hash . substr ( 1 ) ) ;
23- return params . get ( "name" ) || "device0" ;
24- } ,
20+ selfAddr : params . get ( "addr" ) || "device0@local.host" ,
21+ selfName : params . get ( "name" ) || "device0" ,
2522 setUpdateListener : ( cb ) => ( updateListener = cb ) ,
2623 getAllUpdates : ( ) => {
2724 var updatesJSON = window . localStorage . getItem ( updatesKey ) ;
28- return updatesJSON ? JSON . parse ( updatesJSON ) : [ ] ;
25+ return Promise . resolve ( updatesJSON ? JSON . parse ( updatesJSON ) : [ ] ) ;
2926 } ,
3027 sendUpdate : ( update , description ) => {
3128 // alert(description+"\n\n"+JSON.stringify(payload));
@@ -52,7 +49,7 @@ window.addXdcPeer = () => {
5249 window . open ( url ) ;
5350
5451 // update next peer ID
55- params . set ( "next_peer" , peerId + 1 ) ;
52+ params . set ( "next_peer" , String ( peerId + 1 ) ) ;
5653 window . location . hash = "#" + params . toString ( ) ;
5754}
5855
@@ -70,9 +67,9 @@ window.alterXdcApp = () => {
7067 title = document . createElement ( 'title' ) ;
7168 document . getElementsByTagName ( 'head' ) [ 0 ] . append ( title ) ;
7269 }
73- title . innerText = window . webxdc . selfAddr ( ) ;
70+ title . innerText = window . webxdc . selfAddr ;
7471
75- if ( window . webxdc . selfName ( ) === "device0" ) {
72+ if ( window . webxdc . selfName === "device0" ) {
7673 var div = document . createElement ( 'div' ) ;
7774 div . innerHTML =
7875 '<div style="' + styleControlPanel + '">' +
0 commit comments