feat: Android APP V1 - Experimental Alpha
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
|
||||
import type { CallNotificationActionIntent } from '../logic/call-notification.rules';
|
||||
import { buildIncomingCallNotification, buildInCallNotification } from '../logic/call-notification.rules';
|
||||
import type { MobileNotificationAdapter } from '../contracts/mobile.contracts';
|
||||
import { CapacitorMobileNotificationsAdapter } from '../adapters/capacitor/capacitor-mobile-notifications.adapter';
|
||||
import { WebMobileNotificationsAdapter } from '../adapters/web/web-mobile-notifications.adapter';
|
||||
import { MobilePlatformService } from './mobile-platform.service';
|
||||
import { MobilePushRegistrationService } from './mobile-push-registration.service';
|
||||
|
||||
/** Facade for push/local notifications with platform-specific adapters. */
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class MobileNotificationsService {
|
||||
private readonly mobilePlatform = inject(MobilePlatformService);
|
||||
private readonly pushRegistration = inject(MobilePushRegistrationService);
|
||||
private readonly adapter: MobileNotificationAdapter = this.createAdapter();
|
||||
private initialized = false;
|
||||
|
||||
async initialize(): Promise<void> {
|
||||
if (this.initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.adapter.initialize();
|
||||
this.pushRegistration.initialize();
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
async showIncomingCall(displayName: string, callId: string): Promise<void> {
|
||||
await this.initialize();
|
||||
await this.adapter.showCallNotification(buildIncomingCallNotification(displayName, callId));
|
||||
}
|
||||
|
||||
async showActiveCall(input: { callId: string; displayName: string; isMuted: boolean }): Promise<void> {
|
||||
await this.initialize();
|
||||
await this.adapter.showCallNotification(buildInCallNotification(input));
|
||||
}
|
||||
|
||||
async dismissIncomingCall(callId: string): Promise<void> {
|
||||
await this.adapter.dismissCallNotification(callId, 'incoming');
|
||||
}
|
||||
|
||||
async dismissActiveCall(callId: string): Promise<void> {
|
||||
await this.adapter.dismissCallNotification(callId, 'active');
|
||||
}
|
||||
|
||||
onCallAction(handler: (input: { callId: string; intent: CallNotificationActionIntent }) => void): void {
|
||||
this.adapter.onActionSelected(handler);
|
||||
}
|
||||
|
||||
private createAdapter(): MobileNotificationAdapter {
|
||||
return this.mobilePlatform.isCapacitor()
|
||||
? new CapacitorMobileNotificationsAdapter()
|
||||
: new WebMobileNotificationsAdapter();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user