expo-realtime-ivs-broadcast 0.2.5 → 0.2.6

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.
@@ -920,18 +920,38 @@ class IVSStageManager: NSObject, IVSStageStreamDelegate, IVSStageStrategy, IVSSt
920
920
  }
921
921
 
922
922
  // MARK: - PiP Frame Capture Setup
923
+ //
924
+ // PiP uses the Video Call API which requires:
925
+ // 1. setupWithSourceView() - sets the visible view that shows video in the app
926
+ // 2. enqueueFrame() - feeds video frames to the PiP display layer
927
+ //
928
+ // LOCAL (Broadcaster) PiP:
929
+ // - Source view: ExpoIVSStagePreviewView (local camera preview)
930
+ // - Frame source: IVSImageDevice from cameraStream (IVSCamera or IVSCustomImageSource)
931
+ // - The device frame callback provides CVPixelBuffers directly
932
+ //
933
+ // REMOTE (Viewer) PiP:
934
+ // - Source view: ExpoIVSRemoteStreamView (remote video preview)
935
+ // - Frame source: IVSImageDevice from remote participant's video stream
936
+ // - The device frame callback provides CVPixelBuffers from WebRTC
937
+ //
938
+ // Both use the SAME Video Call API approach - the only difference is:
939
+ // - Which view is used as the source view
940
+ // - Which IVSImageDevice provides the frames
923
941
 
924
942
  @available(iOS 15.0, *)
925
943
  private func setupPiPFrameCapture() {
926
944
  if _pipOptions.sourceView == .local {
927
- // For local camera (broadcaster mode)
945
+ // LOCAL/BROADCASTER MODE
946
+ // Use the local camera preview view and camera stream device
928
947
  if let sourceView = localPreviewView {
929
948
  setupLocalCameraPiP(sourceView: sourceView)
930
949
  } else {
931
950
  print("🖼️ [PiP] Warning: Local preview view not registered yet. PiP will be set up when view is registered.")
932
951
  }
933
952
  } else {
934
- // For remote streams, use IVSImageDevice frame callback
953
+ // REMOTE/VIEWER MODE
954
+ // Use the remote stream view and remote participant's video device
935
955
  updatePiPSourceIfNeeded()
936
956
  }
937
957
  }
@@ -1031,7 +1051,14 @@ class IVSStageManager: NSObject, IVSStageStreamDelegate, IVSStageStrategy, IVSSt
1031
1051
  pipHasValidSourceView = false
1032
1052
  }
1033
1053
 
1034
- /// Attach frame callback to an IVS Image Device
1054
+ /// Attach frame callback to an IVS Image Device (primarily for REMOTE streams)
1055
+ ///
1056
+ /// This function is called for remote/viewer PiP:
1057
+ /// 1. Sets up the Video Call API source view (ExpoIVSRemoteStreamView)
1058
+ /// 2. Attaches frame callback to the remote participant's IVSImageDevice
1059
+ /// 3. The device callback provides frames from the WebRTC stream
1060
+ ///
1061
+ /// For local/broadcaster PiP, use setupLocalCameraPiP() instead.
1035
1062
  @available(iOS 15.0, *)
1036
1063
  private func attachToDevice(_ device: IVSImageDevice, sourceView: UIView? = nil) {
1037
1064
  // If we are already attached to this device AND have a valid source view, do nothing
@@ -1093,38 +1120,26 @@ class IVSStageManager: NSObject, IVSStageStreamDelegate, IVSStageStrategy, IVSSt
1093
1120
  }
1094
1121
  }
1095
1122
 
1096
- // For remote streams, the device frame callback may not work properly
1097
- // Use ViewFrameCapture to capture frames from the actual UIView instead
1098
- if _pipOptions.sourceView == .remote {
1099
- // Use view capture for remote streams - more reliable than device callback
1100
- if let targetView = pipTargetView {
1101
- print("🖼️ [PiP] Using ViewFrameCapture for remote stream")
1102
- pipController.startViewCapture(from: targetView)
1103
- } else {
1104
- print("🖼️ [PiP] Warning: No target view for ViewFrameCapture, trying device callback")
1105
- // Fallback to device callback
1106
- let frameQueue = DispatchQueue(label: "com.ivs.pip.frameCallback", qos: .userInteractive)
1107
- device.setOnFrameCallbackQueue(frameQueue, includePixelBuffer: true) { [weak self] frame in
1108
- guard let self = self else { return }
1109
- if let pixelBuffer = frame.pixelBuffer {
1110
- self.pipController.enqueueFrame(pixelBuffer)
1111
- }
1112
- }
1113
- }
1114
- } else {
1115
- // For local streams (broadcaster), use device frame callback
1116
- print("🖼️ [PiP] Using device frame callback for local stream")
1117
- let frameQueue = DispatchQueue(label: "com.ivs.pip.frameCallback", qos: .userInteractive)
1118
- device.setOnFrameCallbackQueue(frameQueue, includePixelBuffer: true) { [weak self] frame in
1119
- guard let self = self else { return }
1120
- if let pixelBuffer = frame.pixelBuffer {
1121
- self.pipController.enqueueFrame(pixelBuffer)
1122
- }
1123
+ // Set frame callback to receive CVPixelBuffers (only if not already set on this device)
1124
+ let frameQueue = DispatchQueue(label: "com.ivs.pip.frameCallback", qos: .userInteractive)
1125
+ device.setOnFrameCallbackQueue(frameQueue, includePixelBuffer: true) { [weak self] frame in
1126
+ guard let self = self else { return }
1127
+
1128
+ if let pixelBuffer = frame.pixelBuffer {
1129
+ self.pipController.enqueueFrame(pixelBuffer)
1123
1130
  }
1124
1131
  }
1125
1132
  }
1126
1133
 
1127
- /// Update PiP source when streams change
1134
+ /// Update PiP source when streams change (REMOTE/VIEWER mode only)
1135
+ ///
1136
+ /// This function finds the appropriate remote video stream and view, then calls
1137
+ /// attachToDevice() to set up the Video Call API for viewer PiP.
1138
+ ///
1139
+ /// Called when:
1140
+ /// - PiP is enabled with sourceView = .remote
1141
+ /// - A remote participant adds video streams
1142
+ /// - ExpoIVSRemoteStreamView starts rendering a stream
1128
1143
  @available(iOS 15.0, *)
1129
1144
  func updatePiPSourceIfNeeded() {
1130
1145
  guard pipController.isEnabled, _pipOptions.sourceView == .remote else { return }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-realtime-ivs-broadcast",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "An Expo module for real-time broadcasting using Amazon IVS.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",