kasunk99-livestream-core 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { setLivestreamConfig, getLivestreamConfig, getBaseUrl, getApiKey, getSignalingUrl, getSignalingWsUrl, getDisplayName, } from './config';
|
|
6
6
|
export type { LivestreamConfig } from './config';
|
|
7
|
-
export { fetchActiveStreams } from './services/livestream.service';
|
|
8
|
-
export type { FetchStreamsResult } from './services/livestream.service';
|
|
7
|
+
export { fetchActiveStreams, createStream, mintViewerToken } from './services/livestream.service';
|
|
8
|
+
export type { FetchStreamsResult, CreateStreamResult, MintViewerTokenResult } from './services/livestream.service';
|
|
9
9
|
export { ensureMediasoupGlobals } from './services/mediasoup-init';
|
|
10
10
|
export { useViewerSocket } from './hooks/useViewerSocket';
|
|
11
11
|
export { useLiveStreams } from './hooks/useLiveStreams';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,UAAU,EACV,SAAS,EACT,eAAe,EACf,iBAAiB,EACjB,cAAc,GACf,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,UAAU,EACV,SAAS,EACT,eAAe,EACf,iBAAiB,EACjB,cAAc,GACf,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAClG,YAAY,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACnH,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEzE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Configure with setLivestreamConfig() before using components/hooks.
|
|
4
4
|
*/
|
|
5
5
|
export { setLivestreamConfig, getLivestreamConfig, getBaseUrl, getApiKey, getSignalingUrl, getSignalingWsUrl, getDisplayName, } from './config';
|
|
6
|
-
export { fetchActiveStreams } from './services/livestream.service';
|
|
6
|
+
export { fetchActiveStreams, createStream, mintViewerToken } from './services/livestream.service';
|
|
7
7
|
export { ensureMediasoupGlobals } from './services/mediasoup-init';
|
|
8
8
|
export { useViewerSocket } from './hooks/useViewerSocket';
|
|
9
9
|
export { useLiveStreams } from './hooks/useLiveStreams';
|
|
@@ -16,7 +16,23 @@ export type MintViewerTokenResult = {
|
|
|
16
16
|
token?: never;
|
|
17
17
|
error: string;
|
|
18
18
|
};
|
|
19
|
+
export type CreateStreamResult = {
|
|
20
|
+
stream: {
|
|
21
|
+
id: string;
|
|
22
|
+
roomId: string;
|
|
23
|
+
title: string | null;
|
|
24
|
+
status: string;
|
|
25
|
+
};
|
|
26
|
+
error?: never;
|
|
27
|
+
} | {
|
|
28
|
+
stream?: never;
|
|
29
|
+
error: string;
|
|
30
|
+
};
|
|
19
31
|
export declare function fetchActiveStreams(): Promise<FetchStreamsResult>;
|
|
32
|
+
export declare function createStream(params?: {
|
|
33
|
+
title?: string | null;
|
|
34
|
+
roomId?: string | null;
|
|
35
|
+
}): Promise<CreateStreamResult>;
|
|
20
36
|
export declare function mintViewerToken(params: {
|
|
21
37
|
roomId: string;
|
|
22
38
|
viewerId?: string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"livestream.service.d.ts","sourceRoot":"","sources":["../../src/services/livestream.service.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,MAAM,kBAAkB,GAC1B;IAAE,OAAO,EAAE,cAAc,EAAE,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,GAC5C;IAAE,OAAO,EAAE,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"livestream.service.d.ts","sourceRoot":"","sources":["../../src/services/livestream.service.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,MAAM,kBAAkB,GAC1B;IAAE,OAAO,EAAE,cAAc,EAAE,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,GAC5C;IAAE,OAAO,EAAE,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAUnC,MAAM,MAAM,qBAAqB,GAC7B;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,GAChC;IAAE,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAErC,MAAM,MAAM,kBAAkB,GAC1B;IAAE,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,GAC/F;IAAE,MAAM,CAAC,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtC,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CA+BtE;AAED,wBAAsB,YAAY,CAAC,MAAM,CAAC,EAAE;IAC1C,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAsC9B;AAED,wBAAsB,eAAe,CAAC,MAAM,EAAE;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAyBjC;AAED,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAGD,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C"}
|
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
* Livestream API: fetch active streams from HTTP; signaling URL from config.
|
|
3
3
|
*/
|
|
4
4
|
import { getApiKey, getBaseUrl, getSignalingUrl as getUrlFromConfig } from '../config';
|
|
5
|
+
function normalizeStreamRow(row) {
|
|
6
|
+
const roomId = typeof row?.roomId === 'string' ? row.roomId : typeof row?.room_id === 'string' ? row.room_id : '';
|
|
7
|
+
if (!roomId)
|
|
8
|
+
return null;
|
|
9
|
+
const viewerCount = typeof row?.viewerCount === 'number' ? row.viewerCount : typeof row?.viewer_count === 'number' ? row.viewer_count : 0;
|
|
10
|
+
const producerCount = typeof row?.producerCount === 'number' ? row.producerCount : typeof row?.producer_count === 'number' ? row.producer_count : 0;
|
|
11
|
+
return { roomId, viewerCount, producerCount };
|
|
12
|
+
}
|
|
5
13
|
export async function fetchActiveStreams() {
|
|
6
14
|
const base = getBaseUrl();
|
|
7
15
|
if (!base) {
|
|
@@ -26,13 +34,61 @@ export async function fetchActiveStreams() {
|
|
|
26
34
|
if (data.error) {
|
|
27
35
|
return { streams: [], error: data.error };
|
|
28
36
|
}
|
|
29
|
-
|
|
37
|
+
const raw = Array.isArray(data.streams) ? data.streams : [];
|
|
38
|
+
const normalized = raw.map(normalizeStreamRow).filter(Boolean);
|
|
39
|
+
return { streams: normalized };
|
|
30
40
|
}
|
|
31
41
|
catch (e) {
|
|
32
42
|
const message = e instanceof Error ? e.message : 'Unknown error';
|
|
33
43
|
return { streams: [], error: message };
|
|
34
44
|
}
|
|
35
45
|
}
|
|
46
|
+
export async function createStream(params) {
|
|
47
|
+
const base = getBaseUrl();
|
|
48
|
+
if (!base)
|
|
49
|
+
return { error: 'Livestream server not configured' };
|
|
50
|
+
const apiKey = getApiKey();
|
|
51
|
+
if (!apiKey)
|
|
52
|
+
return { error: 'Livestream API key not configured' };
|
|
53
|
+
try {
|
|
54
|
+
const url = `${base.replace(/\/$/, '')}/api/streams`;
|
|
55
|
+
const body = {};
|
|
56
|
+
if (typeof params?.title === 'string')
|
|
57
|
+
body.title = params.title;
|
|
58
|
+
if (typeof params?.roomId === 'string')
|
|
59
|
+
body.roomId = params.roomId;
|
|
60
|
+
const res = await fetch(url, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: {
|
|
63
|
+
'content-type': 'application/json',
|
|
64
|
+
'x-api-key': apiKey,
|
|
65
|
+
},
|
|
66
|
+
body: JSON.stringify(body),
|
|
67
|
+
});
|
|
68
|
+
if (!res.ok)
|
|
69
|
+
return { error: `HTTP ${res.status}` };
|
|
70
|
+
const data = (await res.json());
|
|
71
|
+
if (data?.error)
|
|
72
|
+
return { error: data.error };
|
|
73
|
+
const s = data?.stream || {};
|
|
74
|
+
const id = typeof s?.id === 'string' ? s.id : '';
|
|
75
|
+
const roomId = typeof s?.roomId === 'string' ? s.roomId : typeof s?.room_id === 'string' ? s.room_id : '';
|
|
76
|
+
if (!id || !roomId)
|
|
77
|
+
return { error: 'Invalid stream response' };
|
|
78
|
+
return {
|
|
79
|
+
stream: {
|
|
80
|
+
id,
|
|
81
|
+
roomId,
|
|
82
|
+
title: typeof s?.title === 'string' ? s.title : null,
|
|
83
|
+
status: typeof s?.status === 'string' ? s.status : 'created',
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
const message = e instanceof Error ? e.message : 'Unknown error';
|
|
89
|
+
return { error: message };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
36
92
|
export async function mintViewerToken(params) {
|
|
37
93
|
const base = getBaseUrl();
|
|
38
94
|
if (!base)
|
package/package.json
CHANGED