File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,6 +5,23 @@ import { EventHandler } from "./EventHandler.js";
55export class SimpleBus implements EventBus {
66
77 private handlers = new Map < string , EventHandler [ ] > ( ) ;
8+ private channel : BroadcastChannel ;
9+
10+ constructor ( ) {
11+ this . channel = new BroadcastChannel ( 'nextcloud' )
12+
13+ console . debug ( 'SimpleBus 2 created' , this )
14+ // Global broadcast channel
15+ this . channel . onmessage = ( event ) => {
16+ ( this . handlers . get ( event . data . name ) || [ ] ) . forEach ( h => {
17+ try {
18+ h ( event . data . event )
19+ } catch ( e ) {
20+ console . error ( 'could not invoke event listener' , e )
21+ }
22+ } )
23+ }
24+ }
825
926 getVersion ( ) : string {
1027 return globalThis . __pkg_version ;
@@ -19,13 +36,12 @@ export class SimpleBus implements EventBus {
1936 }
2037
2138 emit ( name : string , event : Event ) : void {
22- ( this . handlers . get ( name ) || [ ] ) . forEach ( h => {
23- try {
24- h ( event )
25- } catch ( e ) {
26- console . error ( 'could not invoke event listener' , e )
27- }
28- } )
39+ try {
40+ const data = { name , event }
41+ console . debug ( 'Bus emit' , data ) ;
42+ this . channel . postMessage ( data ) ;
43+ } catch ( e ) {
44+ console . error ( 'could not emit event' , e )
45+ }
2946 }
30-
3147}
You can’t perform that action at this time.
0 commit comments