29 lines
648 B
TypeScript
29 lines
648 B
TypeScript
/**
|
|
* Push notification helpers for "ping friends" in map rooms.
|
|
*/
|
|
|
|
export class MapPushManager {
|
|
private apiBase: string;
|
|
|
|
constructor(apiBase: string) {
|
|
this.apiBase = apiBase;
|
|
}
|
|
|
|
get isSupported(): boolean {
|
|
return "Notification" in window && "serviceWorker" in navigator;
|
|
}
|
|
|
|
async requestLocation(roomSlug: string, participantId: string): Promise<boolean> {
|
|
try {
|
|
const res = await fetch(`${this.apiBase}/api/push/request-location`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ roomSlug, participantId }),
|
|
});
|
|
return res.ok;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
}
|