diff --git a/client/stillbox/src/app/calls.ts b/client/stillbox/src/app/calls.ts index ccd51ee..dddf93f 100644 --- a/client/stillbox/src/app/calls.ts +++ b/client/stillbox/src/app/calls.ts @@ -1,6 +1,7 @@ export interface CallRecord { id: string; call_date: Date; + audioURL: string | null; duration: number; system_id: number; tgid: number; diff --git a/client/stillbox/src/app/incidents/incident/incident.component.ts b/client/stillbox/src/app/incidents/incident/incident.component.ts index 1542e81..e934bf4 100644 --- a/client/stillbox/src/app/incidents/incident/incident.component.ts +++ b/client/stillbox/src/app/incidents/incident/incident.component.ts @@ -39,7 +39,7 @@ import { import { CallPlayerComponent } from '../../calls/player/call-player/call-player.component'; import { FmtDatePipe } from '../incidents.component'; import { MatMenuModule } from '@angular/material/menu'; -import { Share } from '../../share/share.service'; +import { Share } from '../../shares'; export interface EditDialogData { incID: string; @@ -190,8 +190,8 @@ export class IncidentComponent { if (!this.incident) { return; } - this.incID = (this.incident.share as IncidentRecord).id; - incOb = new BehaviorSubject(this.incident.share as IncidentRecord); + this.incID = (this.incident.sharedItem as IncidentRecord).id; + incOb = new BehaviorSubject(this.incident.sharedItem as IncidentRecord); } this.inc$ = merge(incOb, this.incPrime).pipe( tap((inc) => { diff --git a/client/stillbox/src/app/share/share.component.html b/client/stillbox/src/app/share/share.component.html index 6faac2b..7704aca 100644 --- a/client/stillbox/src/app/share/share.component.html +++ b/client/stillbox/src/app/share/share.component.html @@ -1,9 +1,9 @@ @let sh = share | async; @if (sh == null) { -

Share invalid!

-} @else if (sh.shareType == "incident") { +

Share invalid!

+} @else if (sh.type == "incident") { -} @else if (sh.shareType == "call") { +} @else if (sh.type == "call") { } @else { -

Share type {{sh.shareType}} unknown

+

Share type {{ sh.type }} unknown

} diff --git a/client/stillbox/src/app/share/share.component.ts b/client/stillbox/src/app/share/share.component.ts index e1557c9..90766d5 100644 --- a/client/stillbox/src/app/share/share.component.ts +++ b/client/stillbox/src/app/share/share.component.ts @@ -1,5 +1,6 @@ import { Component } from '@angular/core'; -import { Share, ShareService } from './share.service'; +import { ShareService } from './share.service'; +import { Share } from '../shares'; import { ActivatedRoute } from '@angular/router'; import { Observable, Subscription, switchMap } from 'rxjs'; import { IncidentComponent } from '../incidents/incident/incident.component'; diff --git a/client/stillbox/src/app/share/share.service.ts b/client/stillbox/src/app/share/share.service.ts index f880ab8..d13d118 100644 --- a/client/stillbox/src/app/share/share.service.ts +++ b/client/stillbox/src/app/share/share.service.ts @@ -2,35 +2,39 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { map, Observable, switchMap } from 'rxjs'; import { IncidentRecord } from '../incidents'; +import { CallRecord } from '../calls'; +import { Share, ShareType } from '../shares'; -type ShareType = IncidentRecord | ArrayBuffer; -export interface Share { - shareType: string; - share: ShareType; -} @Injectable({ providedIn: 'root', }) export class ShareService { constructor(private http: HttpClient) {} - getShare(id: string): Observable { - return this.http - .get(`/share/${id}`, { observe: 'response' }) - .pipe( - map((res) => { - let typ = res.headers.get('X-Share-Type'); - switch (typ) { - case 'call': - return { shareType: typ, share: res.body as ArrayBuffer }; - case 'incident': - return { - shareType: typ, - share: res.body as IncidentRecord, - }; - } - return null; - }), - ); + getShare(id: string): Observable { + return this.http.get(`/share/${id}`); + } + + getSharedItem(s: Observable): Observable { + return s.pipe( + map((res) => { + switch (res.type) { + case 'call': + return res.sharedItem; + case 'incident': + return res.sharedItem; + } + + return null; + }), + ); + } + + getCallAudio(s: Observable): Observable { + return s.pipe( + switchMap((res) => { + return this.http.get(res.audioURL!); + }), + ); } } diff --git a/client/stillbox/src/app/shares.ts b/client/stillbox/src/app/shares.ts new file mode 100644 index 0000000..8902f74 --- /dev/null +++ b/client/stillbox/src/app/shares.ts @@ -0,0 +1,8 @@ +import { IncidentRecord } from './incidents'; +import { CallRecord } from './calls'; +export type ShareType = IncidentRecord | CallRecord | null; +export interface Share { + id: string; + type: string; + sharedItem: ShareType; +} diff --git a/client/stillbox/src/app/talkgroups/talkgroups.service.ts b/client/stillbox/src/app/talkgroups/talkgroups.service.ts index 0896b64..9025ec9 100644 --- a/client/stillbox/src/app/talkgroups/talkgroups.service.ts +++ b/client/stillbox/src/app/talkgroups/talkgroups.service.ts @@ -2,7 +2,6 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpResponse } from '@angular/common/http'; import { BehaviorSubject, - concatMap, Observable, ReplaySubject, shareReplay, @@ -32,7 +31,10 @@ export class TalkgroupService { private fetchAll = new BehaviorSubject<'fetch'>('fetch'); private subscriptions = new Subscription(); constructor(private http: HttpClient) { - this.tgs$ = this.fetchAll.pipe(switchMap(() => this.getTalkgroups())); + this.tgs$ = this.fetchAll.pipe( + switchMap(() => this.getTalkgroups()), + shareReplay(), + ); this.tags$ = this.fetchAll.pipe( switchMap(() => this.getAllTags()), shareReplay(), @@ -45,11 +47,11 @@ export class TalkgroupService { } getAllTags(): Observable { - return this.http.get('/api/talkgroup/tags').pipe(shareReplay()); + return this.http.get('/api/talkgroup/tags'); } getTalkgroups(): Observable { - return this.http.get('/api/talkgroup/').pipe(shareReplay()); + return this.http.get('/api/talkgroup/'); } getTalkgroup(sys: number, tg: number): Observable {