openreplay/frontend/app/services/spotService.ts
Delirium b17c3ab8d7
Spots UI (#2385)
* feat ui: login flow for spot extension

* spot list, store and service created

* some fixing for header

* start work on single spot

* spot player start

* header for player, comments, icons, etc

* split stuff into compoennts, create player state manager

* player controls, activity panel etc etc

* comments, empty page, rename and stuff

* interval buttons etc

* access modal

* pubkey support

* fix tooltip

* limit 10 -> 9

* hls lib instead of videojs

* some warnings

* fix date display for exp

* change public links

* display more client data

* fix cleaning, init comment

* map network to replay player network ev

* stream support, console panel, close panels on X

* fixing streaming, destroy on leave

* fix autoplay

* show notification on spot login

* fix spot login

* backup player added, fix audio issue

* show thumbnail when no video, add spot roles

* add poster thumbnail

* some fixes to video check

* fix events jump

* fix play btn

* try catch over pubkey

* icons

* spot login pinging

* move spot login flow to login comp, use separate spot login path for unique jwt

* invalidate spot jwt on logout

* add visual data on page load event

* typo fix

* issue to copy change

* share spot url f
2024-07-31 09:56:41 +02:00

101 lines
No EOL
2.5 KiB
TypeScript

import BaseService from "./BaseService";
export interface SpotInfo {
name: string;
duration: number;
comments: SpotComment[];
mobURL: string;
videoURL: string;
createdAt: string;
userID: number;
}
export interface SpotComment {
user: string;
text: string;
createdAt: string;
}
interface GetSpotResponse {
spot: SpotInfo;
}
export interface UpdateSpotRequest {
name?: string;
/** timestamp of public key expiration */
keyExpiration?: number;
}
interface AddCommentRequest {
userName: string;
comment: string;
}
interface GetSpotsResponse {
spots: SpotInfo[];
total: number;
}
interface GetSpotsRequest {
query?: string;
filterBy: "own" | "all" | "shared";
/** @default desc, order by created date */
order: "asc" | "desc";
page: number;
limit: number;
}
export default class SpotService extends BaseService {
async fetchSpots(filters: GetSpotsRequest): Promise<GetSpotsResponse> {
return this.client.get('/spot/v1/spots', filters)
.then(r => r.json())
.catch(console.error)
}
async fetchSpot(id: string, accessKey?: string): Promise<GetSpotResponse> {
return this.client.get(`/spot/v1/spots/${id}${accessKey ? `?key=${accessKey}` : ''}`)
.then(r => r.json())
.catch(console.error)
}
async updateSpot(id: string, filter: UpdateSpotRequest) {
return this.client.patch(`/spot/v1/spots/${id}`, filter)
.then(r => r.json())
.catch(console.error)
}
async deleteSpot(spotIDs: string[]) {
return this.client.delete(`/spot/v1/spots`, {
spotIDs
})
.then(r => r.json())
.catch(console.error)
}
async addComment(id: string, data: AddCommentRequest) {
return this.client.post(`/spot/v1/spots/${id}/comment`, data)
.then(r => r.json())
.catch(console.error)
}
async getVideo(id:string) {
return this.client.get(`/spot/v1/spots/${id}/video`)
.then(r => r.json())
.catch(console.error)
}
/**
* @param id - spot id string
* @param expiration - in seconds, 0 if removing
* */
async generateKey(id: string, expiration: number): Promise<{ key: { value: string, expiration: number }}> {
return this.client.patch(`/spot/v1/spots/${id}/public-key`, { expiration })
.then(r => r.json())
.catch(console.error)
}
async getKey(id: string): Promise<{ key: { value: string, expiration: number }}> {
return this.client.get(`/spot/v1/spots/${id}/public-key`)
.then(r => r.json())
.catch(console.error)
}
}