--- /dev/null
+/**
+ * Create and consume BroadcastChannel broadcasts
+ */
+import {Injectable, EventEmitter} from '@angular/core';
+import {empty} from 'rxjs';
+
+interface BroadcastSub {
+ channel: any; // BroadcastChannel
+ emitter: EventEmitter<any>;
+}
+
+@Injectable()
+export class BroadcastService {
+
+ subscriptions: {[key: string]: BroadcastSub} = {};
+
+ noOpEmitter = new EventEmitter<any>();
+
+ listen(key: string): EventEmitter<any> {
+ if (typeof BroadcastChannel === 'undefined') {
+ return this.noOpEmitter;
+ }
+
+ if (this.subscriptions[key]) {
+ return this.subscriptions[key].emitter;
+ }
+
+ const emitter = new EventEmitter<any>();
+ const channel = new BroadcastChannel(key);
+
+ channel.onmessage = (e) => {
+ console.debug('Broadcast received', e.data);
+ emitter.emit(e.data);
+ };
+
+ this.subscriptions[key] = {
+ channel: channel,
+ emitter: emitter
+ };
+
+ return emitter;
+ }
+
+ broadcast(key: string, value: any) {
+ if (typeof BroadcastChannel === 'undefined') { return; }
+
+ if (this.subscriptions[key]) {
+ this.subscriptions[key].channel.postMessage(value);
+
+ } else {
+
+ // One time use channel
+ const channel = new BroadcastChannel(key);
+ channel.postMessage(value);
+ channel.close();
+ }
+ }
+
+ close(key: string) {
+ if (typeof BroadcastChannel === 'undefined') { return; }
+
+ if (this.subscriptions[key]) {
+ this.subscriptions[key].channel.close();
+ this.subscriptions[key].emitter.complete();
+ delete this.subscriptions[key];
+ }
+ }
+}
+
import {TransferHoldingsComponent
} from '@eg/staff/share/holdings/transfer-holdings.component';
import {AlertDialogComponent} from '@eg/share/dialog/alert.component';
+import {BroadcastService} from '@eg/share/util/broadcast.service';
// The holdings grid models a single HoldingsTree, composed of HoldingsTreeNodes
private store: ServerStoreService,
private localStore: StoreService,
private holdings: HoldingsService,
+ private broadcaster: BroadcastService,
private anonCache: AnonCacheService
) {
// Set some sane defaults before settings are loaded.
ngOnInit() {
this.initDone = true;
+ this.broadcaster.listen('eg.holdings.update').subscribe(data => {
+ if (data && data.records && data.records.includes(this.recordId)) {
+ this.refreshHoldings = true;
+ this.holdingsGrid.reload();
+ }
+ });
+
// These are pre-cached via the catalog resolver.
const settings = this.store.getItemBatchCached([
'cat.holdings_show_empty_org',
import {MultiSelectComponent} from '@eg/share/multi-select/multi-select.component';
import {NotBeforeMomentValidatorDirective} from '@eg/share/validators/not_before_moment_validator.directive';
import {PatronBarcodeValidatorDirective} from '@eg/share/validators/patron_barcode_validator.directive';
+import {BroadcastService} from '@eg/share/util/broadcast.service';
/**
* Imports the EG common modules and adds modules common to all staff UI's.
ngModule: StaffCommonModule,
providers: [ // Export staff-wide services
AccessKeyService,
- AudioService
+ AudioService,
+ BroadcastService
]
};
}