|
1 | 1 | import { useApiStore } from 'stores/api'
|
2 | 2 | import { ItemDto } from 'src/interfaces';
|
3 |
| -import { CREATOR_UUID } from './constants'; |
4 | 3 |
|
5 | 4 | export function useVideoApi() {
|
6 | 5 | const { buildUrl, postJson } = useApiStore()
|
7 | 6 |
|
8 |
| - /** |
9 |
| - * Get a media stream url by id |
10 |
| - * Endpoint: Videos/itemId/master.m3u8 is HLS. HLS supports audio: aac, mp3 ac3, eac3. video container: fMP4, mp2ts |
11 |
| - * Doc: https://datatracker.ietf.org/doc/html/draft-pantos-http-live-streaming-20#section-3.1 -3.4 |
12 |
| - * @param itemId itemId of media |
13 |
| - * @param forceVideoReason force transcode of video |
14 |
| - * @param forceAudioReason force transcode of audio |
15 |
| - * @param container ts, mp4, ... |
16 |
| - */ |
17 |
| - function getVideoStream(itemId: ItemDto['Id'], forceVideoReason?:string, forceAudioReason?: string, container?: string) { |
| 7 | + /** |
| 8 | + * Get a media stream url by id |
| 9 | + * Endpoint: Videos/itemId/master.m3u8 is HLS. HLS supports audio: aac, mp3 ac3, eac3. video container: fMP4, mp2ts |
| 10 | + * Doc: https://datatracker.ietf.org/doc/html/draft-pantos-http-live-streaming-20#section-3.1 -3.4 |
| 11 | + * @param itemId itemId of media |
| 12 | + * @param forceVideoReason force transcode of video |
| 13 | + * @param forceAudioReason force transcode of audio |
| 14 | + * @param container ts, mp4, ... |
| 15 | + */ |
| 16 | + function getVideoStream(itemId: ItemDto['Id'], forceVideoReason?: string, forceAudioReason?: string, container?: string) { |
18 | 17 | const query: Map<string, any> = new Map();
|
19 | 18 | const transcodeReasons: string[] = [];
|
20 |
| - query.set('MediaSourceId',itemId) |
| 19 | + query.set('MediaSourceId', itemId) |
21 | 20 |
|
22 | 21 | // if there is no transcode, enable direct stream
|
23 |
| - if (!forceAudioReason && !forceVideoReason){ |
24 |
| - query.set('static',true) |
| 22 | + if (!forceAudioReason && !forceVideoReason) { |
| 23 | + query.set('static', true) |
25 | 24 | }
|
26 |
| - if(forceAudioReason){ |
| 25 | + if (forceAudioReason) { |
27 | 26 | transcodeReasons.push(`Audio not supported (${forceAudioReason})`)
|
28 |
| - query.set('AudioCodec','aac') |
29 |
| - query.set('TranscodingMaxAudioChannels',2) |
| 27 | + query.set('AudioCodec', 'aac') |
| 28 | + query.set('TranscodingMaxAudioChannels', 2) |
30 | 29 | }
|
31 |
| - if(forceVideoReason){ |
| 30 | + if (forceVideoReason) { |
32 | 31 | transcodeReasons.push(`Video not supported (${forceVideoReason}`)
|
33 |
| - query.set('VideoCodec','h264') |
| 32 | + query.set('VideoCodec', 'h264') |
34 | 33 | }
|
35 |
| - if(transcodeReasons.length){ |
36 |
| - query.set('transcodeReasons',transcodeReasons.join(',')) |
| 34 | + if (transcodeReasons.length) { |
| 35 | + query.set('transcodeReasons', transcodeReasons.join(',')) |
37 | 36 | }
|
38 |
| - if (container){ |
39 |
| - query.set('segmentContainer',container) |
| 37 | + if (container) { |
| 38 | + query.set('segmentContainer', container) |
40 | 39 | }
|
41 | 40 | // skip session, we can't stop it without userId...
|
42 | 41 | // query.set('PlaySessionId',CREATOR_UUID)
|
43 | 42 |
|
44 | 43 | const baseUrl = `Videos/${itemId}/master.m3u8`;
|
45 |
| - return buildUrl(baseUrl,query) |
| 44 | + return buildUrl(baseUrl, query) |
46 | 45 | }
|
47 | 46 |
|
48 | 47 | /**
|
49 | 48 | * Report end of playback. Requires userId from httpContext server side...
|
50 | 49 | * @param itemId
|
51 | 50 | */
|
52 |
| - function reportPlayingStop(itemId: ItemDto['Id']){ |
| 51 | + function reportPlayingStop(itemId: ItemDto['Id']) { |
53 | 52 | const payload = {
|
54 | 53 | ItemId: itemId,
|
55 | 54 | MediaSourceId: itemId,
|
56 |
| - PlaySessionId: CREATOR_UUID |
| 55 | + PlaySessionId: 'xxx' |
57 | 56 | }
|
58 |
| - postJson('Sessions/Playing/Stopped',payload) |
| 57 | + postJson('Sessions/Playing/Stopped', payload) |
59 | 58 | }
|
60 | 59 |
|
61 | 60 | return { getVideoStream, reportPlayingStop }
|
|
0 commit comments