kasunk99-livestream-core 0.3.0 → 0.3.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.
@@ -1 +1 @@
1
- {"version":3,"file":"useHostSocket.d.ts","sourceRoot":"","sources":["../../src/hooks/useHostSocket.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAYH,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,mBAAmB,CAAC;AAoB3B,MAAM,MAAM,oBAAoB,GAAG;IACjC,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG;IAC5C,YAAY,EAAE,eAAe,EAAE,CAAC;IAChC,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,YAAY,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,gBAAgB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC,CAAC;AAMF,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,mBAAmB,CA4nBrF"}
1
+ {"version":3,"file":"useHostSocket.d.ts","sourceRoot":"","sources":["../../src/hooks/useHostSocket.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAYH,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,mBAAmB,CAAC;AAoB3B,MAAM,MAAM,oBAAoB,GAAG;IACjC,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG;IAC5C,YAAY,EAAE,eAAe,EAAE,CAAC;IAChC,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,YAAY,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,gBAAgB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC,CAAC;AAMF,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,mBAAmB,CAupBrF"}
@@ -327,6 +327,20 @@ export function useHostSocket(options = {}) {
327
327
  screenStreamToStop.release?.();
328
328
  }
329
329
  catch { /* ignore */ }
330
+ if (Platform.OS !== 'android') {
331
+ // iOS: camera was never stopped — the existing track in localStream is still live.
332
+ // Just switch the producer back to it; no getUserMedia call needed.
333
+ const existingCamTrack = hostSession.localStream?.getVideoTracks()?.[0];
334
+ if (existingCamTrack) {
335
+ patchHostState({ streamURL: getStreamURL(hostSession.localStream), captureMode: 'camera' });
336
+ await replaceVideoProducer(existingCamTrack);
337
+ }
338
+ else {
339
+ patchHostState({ captureMode: 'camera' });
340
+ }
341
+ return;
342
+ }
343
+ // Android: camera was stopped when screen share started — re-acquire it.
330
344
  try {
331
345
  const { isFrontCamera: front } = getHostState();
332
346
  const newCamStream = (await mediaDevices.getUserMedia({
@@ -385,17 +399,31 @@ export function useHostSocket(options = {}) {
385
399
  return;
386
400
  }
387
401
  hostSession.screenStream = screenStream;
388
- // Free the camera hardware while screen sharing
389
- hostSession.localStream?.getVideoTracks()
390
- ?.forEach((t) => { try {
391
- t.stop?.();
402
+ if (Platform.OS === 'android') {
403
+ // Android: stop camera hardware — MediaProjection captures the hardware
404
+ // display independently, so stopping the camera is safe and saves battery.
405
+ hostSession.localStream?.getVideoTracks()
406
+ ?.forEach((t) => { try {
407
+ t.stop?.();
408
+ }
409
+ catch { /* ignore */ } });
410
+ // Point the RTCView preview at the screen capture stream.
411
+ patchHostState({ streamURL: getStreamURL(screenStream), captureMode: 'screen' });
412
+ }
413
+ else {
414
+ // iOS: keep camera hardware running.
415
+ // RPScreenRecorder captures the app's own screen; if we stopped the camera
416
+ // first, the app would display black and that black frame would be captured
417
+ // → host and viewers both see a black screen. Keeping the camera alive
418
+ // means the host's RTCView still shows the camera preview while the
419
+ // WebRTC producer (replaced below) delivers screen content to viewers.
420
+ patchHostState({ captureMode: 'screen' });
421
+ // Update the preview URL so the RTCView keeps showing the local camera stream.
422
+ patchHostState({ streamURL: getStreamURL(hostSession.localStream) });
392
423
  }
393
- catch { /* ignore */ } });
394
- // Point preview at the native screenStream — avoids the black-screen bug
395
- // caused by copying a screen-capture track into a different MediaStream object.
396
- patchHostState({ streamURL: getStreamURL(screenStream), captureMode: 'screen' });
397
424
  await replaceVideoProducer(screenVideoTrack);
398
- // Auto-revert when user dismisses screen share from the Android notification bar
425
+ // Auto-revert when user dismisses screen share
426
+ // (Android: from the notification bar; iOS: from the status-bar recording dot)
399
427
  screenVideoTrack.addEventListener?.('ended', () => {
400
428
  void stopScreenShare();
401
429
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kasunk99-livestream-core",
3
- "version": "0.3.0",
3
+ "version": "0.3.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",