kasunk99-livestream-core 0.1.0 → 0.1.1

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/config.d.ts CHANGED
@@ -4,12 +4,18 @@
4
4
  export type LivestreamConfig = {
5
5
  /** Base HTTP URL of the livestream server (e.g. http://localhost:3000) */
6
6
  serverHttpUrl: string;
7
+ /**
8
+ * Optional API key for merchant endpoints and Socket.IO auth.
9
+ * WARNING: do not ship secrets in client apps; prefer a server-minted viewer token.
10
+ */
11
+ apiKey?: string;
7
12
  /** Optional: return display name for viewer in chat/room (default: 'Viewer') */
8
13
  getDisplayName?: () => string;
9
14
  };
10
15
  export declare function setLivestreamConfig(cfg: LivestreamConfig): void;
11
16
  export declare function getLivestreamConfig(): LivestreamConfig | null;
12
17
  export declare function getBaseUrl(): string;
18
+ export declare function getApiKey(): string;
13
19
  /**
14
20
  * Socket.IO server URL.
15
21
  *
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,0EAA0E;IAC1E,aAAa,EAAE,MAAM,CAAC;IACtB,gFAAgF;IAChF,cAAc,CAAC,EAAE,MAAM,MAAM,CAAC;CAC/B,CAAC;AAIF,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,gBAAgB,GAAG,IAAI,CAE/D;AAED,wBAAgB,mBAAmB,IAAI,gBAAgB,GAAG,IAAI,CAE7D;AASD,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAKxC;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAM1C;AAED,wBAAgB,cAAc,IAAI,MAAM,CAEvC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,0EAA0E;IAC1E,aAAa,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,cAAc,CAAC,EAAE,MAAM,MAAM,CAAC;CAC/B,CAAC;AAIF,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,gBAAgB,GAAG,IAAI,CAE/D;AAED,wBAAgB,mBAAmB,IAAI,gBAAgB,GAAG,IAAI,CAE7D;AAeD,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAKxC;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAM1C;AAED,wBAAgB,cAAc,IAAI,MAAM,CAEvC"}
package/dist/config.js CHANGED
@@ -15,9 +15,18 @@ const getGlobalServerUrl = () => {
15
15
  const g = globalThis;
16
16
  return g?.__LIVESTREAM_SERVER_HTTP_URI ?? '';
17
17
  };
18
+ const getGlobalApiKey = () => {
19
+ if (typeof globalThis === 'undefined')
20
+ return '';
21
+ const g = globalThis;
22
+ return g?.__LIVESTREAM_API_KEY ?? '';
23
+ };
18
24
  export function getBaseUrl() {
19
25
  return config?.serverHttpUrl ?? getGlobalServerUrl();
20
26
  }
27
+ export function getApiKey() {
28
+ return config?.apiKey ?? getGlobalApiKey();
29
+ }
21
30
  /**
22
31
  * Socket.IO server URL.
23
32
  *
@@ -1 +1 @@
1
- {"version":3,"file":"useViewerSocket.d.ts","sourceRoot":"","sources":["../../src/hooks/useViewerSocket.ts"],"names":[],"mappings":"AACA,OAAO,EAAM,KAAK,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAInD,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7D,KAAK,iBAAiB,GAAG;IACvB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,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;CACzB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,iBAAiB,GAAG;IAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAubpG"}
@@ -1,6 +1,6 @@
1
1
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
2
  import { io } from 'socket.io-client';
3
- import { getDisplayName } from '../config';
3
+ import { getApiKey, getDisplayName } from '../config';
4
4
  import { ensureMediasoupGlobals } from '../services/mediasoup-init';
5
5
  import { getSignalingUrl } from '../services/livestream.service';
6
6
  /**
@@ -102,12 +102,19 @@ export function useViewerSocket(roomId) {
102
102
  };
103
103
  });
104
104
  }, JOIN_TIMEOUT_MS);
105
+ const apiKey = getApiKey();
105
106
  // Match web client (Client/src/streamService.js): websocket first, then polling.
106
107
  const socket = io(signalingUrl, {
107
108
  transports: ['websocket', 'polling'],
108
109
  reconnection: true,
109
110
  autoConnect: true,
110
111
  timeout: 10000,
112
+ ...(apiKey
113
+ ? {
114
+ auth: { apiKey },
115
+ extraHeaders: { 'x-api-key': apiKey },
116
+ }
117
+ : {}),
111
118
  });
112
119
  socketRef.current = socket;
113
120
  socket.on('connect', () => {
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * @livestream/core — Reusable livestream module for React Native (Expo).
3
3
  * Configure with setLivestreamConfig() before using components/hooks.
4
4
  */
5
- export { setLivestreamConfig, getLivestreamConfig, getBaseUrl, getSignalingUrl, getSignalingWsUrl, getDisplayName, } from './config';
5
+ export { setLivestreamConfig, getLivestreamConfig, getBaseUrl, getApiKey, getSignalingUrl, getSignalingWsUrl, getDisplayName, } from './config';
6
6
  export type { LivestreamConfig } from './config';
7
7
  export { fetchActiveStreams } from './services/livestream.service';
8
8
  export type { FetchStreamsResult } from './services/livestream.service';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;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AmC,CAAC;AAEzE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * @livestream/core — Reusable livestream module for React Native (Expo).
3
3
  * Configure with setLivestreamConfig() before using components/hooks.
4
4
  */
5
- export { setLivestreamConfig, getLivestreamConfig, getBaseUrl, getSignalingUrl, getSignalingWsUrl, getDisplayName, } from './config';
5
+ export { setLivestreamConfig, getLivestreamConfig, getBaseUrl, getApiKey, getSignalingUrl, getSignalingWsUrl, getDisplayName, } from './config';
6
6
  export { fetchActiveStreams } from './services/livestream.service';
7
7
  export { ensureMediasoupGlobals } from './services/mediasoup-init';
8
8
  export { useViewerSocket } from './hooks/useViewerSocket';
@@ -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;AAEnC,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAoBtE;AAED,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAGD,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C"}
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;AAEnC,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CA6BtE;AAED,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAGD,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C"}
@@ -1,15 +1,24 @@
1
1
  /**
2
2
  * Livestream API: fetch active streams from HTTP; signaling URL from config.
3
3
  */
4
- import { getBaseUrl, getSignalingUrl as getUrlFromConfig } from '../config';
4
+ import { getApiKey, getBaseUrl, getSignalingUrl as getUrlFromConfig } from '../config';
5
5
  export async function fetchActiveStreams() {
6
6
  const base = getBaseUrl();
7
7
  if (!base) {
8
8
  return { streams: [], error: 'Livestream server not configured' };
9
9
  }
10
+ const apiKey = getApiKey();
11
+ if (!apiKey) {
12
+ return { streams: [], error: 'Livestream API key not configured' };
13
+ }
10
14
  try {
11
15
  const url = `${base.replace(/\/$/, '')}/api/live-streams`;
12
- const res = await fetch(url, { method: 'GET' });
16
+ const res = await fetch(url, {
17
+ method: 'GET',
18
+ headers: {
19
+ 'x-api-key': apiKey,
20
+ },
21
+ });
13
22
  if (!res.ok) {
14
23
  return { streams: [], error: `HTTP ${res.status}` };
15
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kasunk99-livestream-core",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Reusable livestream viewer/host module for React Native (Expo) — mediasoup + Socket.IO",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",