@stream-io/video-react-native-sdk 1.29.4 → 1.30.0
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/CHANGELOG.md +11 -0
- package/dist/commonjs/components/Call/CallContent/CallContent.js +13 -7
- package/dist/commonjs/components/Call/CallContent/CallContent.js.map +1 -1
- package/dist/commonjs/components/Call/CallContent/RTCViewPipIOS.js +50 -14
- package/dist/commonjs/components/Call/CallContent/RTCViewPipIOS.js.map +1 -1
- package/dist/commonjs/components/Call/CallContent/RTCViewPipNative.js +27 -0
- package/dist/commonjs/components/Call/CallContent/RTCViewPipNative.js.map +1 -1
- package/dist/commonjs/components/Call/CallLayout/CallParticipantsGrid.js +19 -10
- package/dist/commonjs/components/Call/CallLayout/CallParticipantsGrid.js.map +1 -1
- package/dist/commonjs/components/Call/CallLayout/CallParticipantsSpotlight.js +12 -9
- package/dist/commonjs/components/Call/CallLayout/CallParticipantsSpotlight.js.map +1 -1
- package/dist/commonjs/components/Call/CallParticipantsList/CallParticipantsList.js +19 -4
- package/dist/commonjs/components/Call/CallParticipantsList/CallParticipantsList.js.map +1 -1
- package/dist/commonjs/utils/hooks/index.js +0 -11
- package/dist/commonjs/utils/hooks/index.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/module/components/Call/CallContent/CallContent.js +10 -4
- package/dist/module/components/Call/CallContent/CallContent.js.map +1 -1
- package/dist/module/components/Call/CallContent/RTCViewPipIOS.js +52 -16
- package/dist/module/components/Call/CallContent/RTCViewPipIOS.js.map +1 -1
- package/dist/module/components/Call/CallContent/RTCViewPipNative.js +27 -0
- package/dist/module/components/Call/CallContent/RTCViewPipNative.js.map +1 -1
- package/dist/module/components/Call/CallLayout/CallParticipantsGrid.js +19 -10
- package/dist/module/components/Call/CallLayout/CallParticipantsGrid.js.map +1 -1
- package/dist/module/components/Call/CallLayout/CallParticipantsSpotlight.js +15 -12
- package/dist/module/components/Call/CallLayout/CallParticipantsSpotlight.js.map +1 -1
- package/dist/module/components/Call/CallParticipantsList/CallParticipantsList.js +20 -5
- package/dist/module/components/Call/CallParticipantsList/CallParticipantsList.js.map +1 -1
- package/dist/module/utils/hooks/index.js +0 -1
- package/dist/module/utils/hooks/index.js.map +1 -1
- package/dist/module/version.js +1 -1
- package/dist/typescript/components/Call/CallContent/CallContent.d.ts.map +1 -1
- package/dist/typescript/components/Call/CallContent/RTCViewPipIOS.d.ts.map +1 -1
- package/dist/typescript/components/Call/CallContent/RTCViewPipNative.d.ts +18 -0
- package/dist/typescript/components/Call/CallContent/RTCViewPipNative.d.ts.map +1 -1
- package/dist/typescript/components/Call/CallLayout/CallParticipantsGrid.d.ts.map +1 -1
- package/dist/typescript/components/Call/CallLayout/CallParticipantsSpotlight.d.ts.map +1 -1
- package/dist/typescript/components/Call/CallParticipantsList/CallParticipantsList.d.ts.map +1 -1
- package/dist/typescript/utils/hooks/index.d.ts +0 -1
- package/dist/typescript/utils/hooks/index.d.ts.map +1 -1
- package/dist/typescript/version.d.ts +1 -1
- package/ios/PictureInPicture/PictureInPictureAvatarView.swift +273 -0
- package/ios/PictureInPicture/PictureInPictureConnectionQualityIndicator.swift +162 -0
- package/ios/PictureInPicture/PictureInPictureContent.swift +173 -0
- package/ios/PictureInPicture/PictureInPictureContentState.swift +123 -0
- package/ios/PictureInPicture/PictureInPictureDelegateProxy.swift +89 -0
- package/ios/PictureInPicture/PictureInPictureEnforcedStopAdapter.swift +166 -0
- package/ios/PictureInPicture/PictureInPictureLogger.swift +16 -0
- package/ios/PictureInPicture/PictureInPictureParticipantOverlayView.swift +217 -0
- package/ios/PictureInPicture/PictureInPictureReconnectionView.swift +193 -0
- package/ios/PictureInPicture/StreamAVPictureInPictureVideoCallViewController.swift +125 -7
- package/ios/PictureInPicture/StreamPictureInPictureController.swift +237 -63
- package/ios/PictureInPicture/StreamPictureInPictureControllerProtocol.swift +30 -0
- package/ios/PictureInPicture/StreamPictureInPictureVideoRenderer.swift +384 -12
- package/ios/RTCViewPip.swift +187 -21
- package/ios/RTCViewPipManager.mm +9 -0
- package/ios/RTCViewPipManager.swift +3 -3
- package/package.json +3 -3
- package/src/components/Call/CallContent/CallContent.tsx +16 -8
- package/src/components/Call/CallContent/RTCViewPipIOS.tsx +81 -15
- package/src/components/Call/CallContent/RTCViewPipNative.tsx +36 -0
- package/src/components/Call/CallLayout/CallParticipantsGrid.tsx +28 -14
- package/src/components/Call/CallLayout/CallParticipantsSpotlight.tsx +19 -10
- package/src/components/Call/CallParticipantsList/CallParticipantsList.tsx +20 -5
- package/src/utils/hooks/index.ts +0 -1
- package/src/version.ts +1 -1
- package/dist/commonjs/utils/hooks/useDebouncedValue.js +0 -24
- package/dist/commonjs/utils/hooks/useDebouncedValue.js.map +0 -1
- package/dist/module/utils/hooks/useDebouncedValue.js +0 -19
- package/dist/module/utils/hooks/useDebouncedValue.js.map +0 -1
- package/dist/typescript/utils/hooks/useDebouncedValue.d.ts +0 -8
- package/dist/typescript/utils/hooks/useDebouncedValue.d.ts.map +0 -1
- package/src/utils/hooks/useDebouncedValue.ts +0 -21
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright © 2024 Stream.io Inc. All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
// Adapted from stream-video-swift PictureInPictureStore for React Native SDK
|
|
5
|
+
// The React Native SDK receives state from the JavaScript bridge rather than
|
|
6
|
+
// observing call state internally, so this is a simplified state container.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Combine
|
|
10
|
+
import Foundation
|
|
11
|
+
|
|
12
|
+
/// Manages the content state for the Picture-in-Picture window.
|
|
13
|
+
///
|
|
14
|
+
/// This class provides centralized state management for the PiP content view system.
|
|
15
|
+
/// Unlike the upstream `PictureInPictureStore` which uses a Flux-like action/dispatch pattern,
|
|
16
|
+
/// this implementation is optimized for the React Native bridge where state updates come
|
|
17
|
+
/// from the JavaScript layer.
|
|
18
|
+
///
|
|
19
|
+
/// State changes are published via Combine to allow reactive updates in the view layer.
|
|
20
|
+
///
|
|
21
|
+
/// Concurrency model:
|
|
22
|
+
/// - This state container is main-thread confined.
|
|
23
|
+
/// - `RTCVideoTrack` references are never sent across queues.
|
|
24
|
+
final class PictureInPictureContentState {
|
|
25
|
+
|
|
26
|
+
/// A full state snapshot that can be applied atomically.
|
|
27
|
+
struct Snapshot {
|
|
28
|
+
var track: RTCVideoTrack?
|
|
29
|
+
var participantName: String?
|
|
30
|
+
var participantImageURL: String?
|
|
31
|
+
var isVideoEnabled: Bool
|
|
32
|
+
var isScreenSharing: Bool
|
|
33
|
+
var isReconnecting: Bool
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// MARK: - Published State
|
|
37
|
+
|
|
38
|
+
/// The current content being displayed in the PiP window.
|
|
39
|
+
@Published private(set) var content: PictureInPictureContent = .inactive
|
|
40
|
+
|
|
41
|
+
/// Publisher for observing content changes.
|
|
42
|
+
var contentPublisher: AnyPublisher<PictureInPictureContent, Never> {
|
|
43
|
+
$content.eraseToAnyPublisher()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// MARK: - Private
|
|
47
|
+
|
|
48
|
+
private var snapshot: Snapshot = makeDefaultSnapshot()
|
|
49
|
+
|
|
50
|
+
// MARK: - Initialization
|
|
51
|
+
|
|
52
|
+
init() {}
|
|
53
|
+
|
|
54
|
+
// MARK: - State Update
|
|
55
|
+
|
|
56
|
+
/// Applies all content inputs in one step to avoid parallel update paths.
|
|
57
|
+
func apply(_ snapshot: Snapshot) {
|
|
58
|
+
ensureMainThread()
|
|
59
|
+
self.snapshot = snapshot
|
|
60
|
+
publishIfNeeded(for: snapshot)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/// Resets all state to defaults.
|
|
64
|
+
/// Called when cleaning up after a call ends.
|
|
65
|
+
func reset() {
|
|
66
|
+
ensureMainThread()
|
|
67
|
+
snapshot = Self.makeDefaultSnapshot()
|
|
68
|
+
if content != .inactive {
|
|
69
|
+
content = .inactive
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/// Computes and publishes content based on the latest snapshot.
|
|
74
|
+
private func publishIfNeeded(for snapshot: Snapshot) {
|
|
75
|
+
let newContent: PictureInPictureContent
|
|
76
|
+
|
|
77
|
+
// Priority order: reconnecting > screen sharing > avatar (video disabled) > video > avatar fallback
|
|
78
|
+
if snapshot.isReconnecting {
|
|
79
|
+
newContent = .reconnecting
|
|
80
|
+
} else if snapshot.isScreenSharing {
|
|
81
|
+
newContent = .screenSharing(
|
|
82
|
+
track: snapshot.track,
|
|
83
|
+
participantName: snapshot.participantName
|
|
84
|
+
)
|
|
85
|
+
} else if !snapshot.isVideoEnabled {
|
|
86
|
+
newContent = .avatar(
|
|
87
|
+
participantName: snapshot.participantName,
|
|
88
|
+
participantImageURL: snapshot.participantImageURL
|
|
89
|
+
)
|
|
90
|
+
} else if snapshot.isVideoEnabled, snapshot.track != nil {
|
|
91
|
+
newContent = .video(
|
|
92
|
+
track: snapshot.track,
|
|
93
|
+
participantName: snapshot.participantName,
|
|
94
|
+
participantImageURL: snapshot.participantImageURL
|
|
95
|
+
)
|
|
96
|
+
} else {
|
|
97
|
+
newContent = .avatar(
|
|
98
|
+
participantName: snapshot.participantName,
|
|
99
|
+
participantImageURL: snapshot.participantImageURL
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if content != newContent {
|
|
104
|
+
content = newContent
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/// PiP content state is expected to be mutated on the main thread only.
|
|
109
|
+
private func ensureMainThread() {
|
|
110
|
+
dispatchPrecondition(condition: .onQueue(.main))
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private static func makeDefaultSnapshot() -> Snapshot {
|
|
114
|
+
Snapshot(
|
|
115
|
+
track: nil,
|
|
116
|
+
participantName: nil,
|
|
117
|
+
participantImageURL: nil,
|
|
118
|
+
isVideoEnabled: true,
|
|
119
|
+
isScreenSharing: false,
|
|
120
|
+
isReconnecting: false
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright © 2024 Stream.io Inc. All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import AVKit
|
|
6
|
+
import Combine
|
|
7
|
+
|
|
8
|
+
/// A wrapper around AVPictureInPictureControllerDelegate that publishes all
|
|
9
|
+
/// delegate method calls via a single Combine publisher.
|
|
10
|
+
///
|
|
11
|
+
/// This proxy enables reactive handling of PiP lifecycle events and allows
|
|
12
|
+
/// multiple subscribers to observe PiP state changes through a unified interface.
|
|
13
|
+
final class PictureInPictureDelegateProxy: NSObject, AVPictureInPictureControllerDelegate {
|
|
14
|
+
|
|
15
|
+
/// Enum representing each AVPictureInPictureControllerDelegate method call
|
|
16
|
+
/// with its respective associated values.
|
|
17
|
+
enum Event: CustomStringConvertible {
|
|
18
|
+
case willStart(AVPictureInPictureController)
|
|
19
|
+
case didStart(AVPictureInPictureController)
|
|
20
|
+
case failedToStart(AVPictureInPictureController, Error)
|
|
21
|
+
case willStop(AVPictureInPictureController)
|
|
22
|
+
case didStop(AVPictureInPictureController)
|
|
23
|
+
case restoreUI(AVPictureInPictureController, (Bool) -> Void)
|
|
24
|
+
|
|
25
|
+
var description: String {
|
|
26
|
+
switch self {
|
|
27
|
+
case .willStart:
|
|
28
|
+
return ".willStart"
|
|
29
|
+
case .didStart:
|
|
30
|
+
return ".didStart"
|
|
31
|
+
case let .failedToStart(_, error):
|
|
32
|
+
return ".failedToStart(error: \(error.localizedDescription))"
|
|
33
|
+
case .willStop:
|
|
34
|
+
return ".willStop"
|
|
35
|
+
case .didStop:
|
|
36
|
+
return ".didStop"
|
|
37
|
+
case .restoreUI:
|
|
38
|
+
return ".restoreUI"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// The Combine publisher that emits Picture-in-Picture delegate events.
|
|
44
|
+
var publisher: AnyPublisher<Event, Never> {
|
|
45
|
+
eventSubject.eraseToAnyPublisher()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private let eventSubject = PassthroughSubject<Event, Never>()
|
|
49
|
+
|
|
50
|
+
// MARK: - AVPictureInPictureControllerDelegate
|
|
51
|
+
|
|
52
|
+
func pictureInPictureControllerWillStartPictureInPicture(
|
|
53
|
+
_ pictureInPictureController: AVPictureInPictureController
|
|
54
|
+
) {
|
|
55
|
+
eventSubject.send(.willStart(pictureInPictureController))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
func pictureInPictureControllerDidStartPictureInPicture(
|
|
59
|
+
_ pictureInPictureController: AVPictureInPictureController
|
|
60
|
+
) {
|
|
61
|
+
eventSubject.send(.didStart(pictureInPictureController))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
func pictureInPictureController(
|
|
65
|
+
_ pictureInPictureController: AVPictureInPictureController,
|
|
66
|
+
failedToStartPictureInPictureWithError error: Error
|
|
67
|
+
) {
|
|
68
|
+
eventSubject.send(.failedToStart(pictureInPictureController, error))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
func pictureInPictureControllerWillStopPictureInPicture(
|
|
72
|
+
_ pictureInPictureController: AVPictureInPictureController
|
|
73
|
+
) {
|
|
74
|
+
eventSubject.send(.willStop(pictureInPictureController))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
func pictureInPictureControllerDidStopPictureInPicture(
|
|
78
|
+
_ pictureInPictureController: AVPictureInPictureController
|
|
79
|
+
) {
|
|
80
|
+
eventSubject.send(.didStop(pictureInPictureController))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
func pictureInPictureController(
|
|
84
|
+
_ pictureInPictureController: AVPictureInPictureController,
|
|
85
|
+
restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: @escaping (Bool) -> Void
|
|
86
|
+
) {
|
|
87
|
+
eventSubject.send(.restoreUI(pictureInPictureController, completionHandler))
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright © 2024 Stream.io Inc. All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import AVKit
|
|
6
|
+
import Combine
|
|
7
|
+
import UIKit
|
|
8
|
+
|
|
9
|
+
/// An adapter responsible for enforcing the stop of Picture-in-Picture
|
|
10
|
+
/// playback when the application returns to the foreground.
|
|
11
|
+
///
|
|
12
|
+
/// This adapter listens to application state changes and PiP activity to ensure
|
|
13
|
+
/// PiP is stopped when the app becomes active (foreground). This behavior matches
|
|
14
|
+
/// iOS user expectations where PiP should dismiss when returning to the app.
|
|
15
|
+
final class PictureInPictureEnforcedStopAdapter {
|
|
16
|
+
|
|
17
|
+
private enum DisposableKey: String {
|
|
18
|
+
case stopEnforceOperation
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
private enum ApplicationState: Equatable {
|
|
22
|
+
case foreground
|
|
23
|
+
case background
|
|
24
|
+
case unknown
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/// Refresh-rate-based timer interval used for enforcement attempts.
|
|
28
|
+
private let refreshRate: TimeInterval
|
|
29
|
+
|
|
30
|
+
/// Lifecycle subscriptions.
|
|
31
|
+
private var cancellables: Set<AnyCancellable> = []
|
|
32
|
+
|
|
33
|
+
/// Keyed operations that can be replaced/cancelled independently.
|
|
34
|
+
private var operationCancellables: [String: AnyCancellable] = [:]
|
|
35
|
+
|
|
36
|
+
/// Initializes the adapter with a Picture-in-Picture controller and
|
|
37
|
+
/// starts observing application state and PiP activity to enforce stop.
|
|
38
|
+
///
|
|
39
|
+
/// - Parameter pictureInPictureController: The PiP controller to manage.
|
|
40
|
+
init(_ pictureInPictureController: StreamPictureInPictureControllerProtocol) {
|
|
41
|
+
refreshRate = Self.makeRefreshRate()
|
|
42
|
+
|
|
43
|
+
// Keep enforcement strictly state-driven: we only run the stop loop
|
|
44
|
+
// while the app is foregrounded *and* PiP is still active.
|
|
45
|
+
Publishers
|
|
46
|
+
.CombineLatest(
|
|
47
|
+
Self.makeApplicationStatePublisher(),
|
|
48
|
+
pictureInPictureController
|
|
49
|
+
.isPictureInPictureActivePublisher
|
|
50
|
+
.removeDuplicates()
|
|
51
|
+
)
|
|
52
|
+
.receive(on: DispatchQueue.main)
|
|
53
|
+
.sink { [weak self, weak pictureInPictureController] applicationState, isActive in
|
|
54
|
+
self?.didUpdate(
|
|
55
|
+
applicationState: applicationState,
|
|
56
|
+
isPictureInPictureActive: isActive,
|
|
57
|
+
pictureInPictureController: pictureInPictureController
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
.store(in: &cancellables)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
deinit {
|
|
64
|
+
cancellables.removeAll()
|
|
65
|
+
removeAllOperations()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// MARK: - Private helpers
|
|
69
|
+
|
|
70
|
+
private func didUpdate(
|
|
71
|
+
applicationState: ApplicationState,
|
|
72
|
+
isPictureInPictureActive: Bool,
|
|
73
|
+
pictureInPictureController: StreamPictureInPictureControllerProtocol?
|
|
74
|
+
) {
|
|
75
|
+
switch (applicationState, isPictureInPictureActive) {
|
|
76
|
+
case (.foreground, true):
|
|
77
|
+
// Foreground + active PiP is the only state where we enforce stop.
|
|
78
|
+
startStopEnforcement(for: pictureInPictureController)
|
|
79
|
+
default:
|
|
80
|
+
// Any other state (background/inactive PiP) should tear down the loop.
|
|
81
|
+
removeOperation(for: DisposableKey.stopEnforceOperation.rawValue)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private func startStopEnforcement(
|
|
86
|
+
for pictureInPictureController: StreamPictureInPictureControllerProtocol?
|
|
87
|
+
) {
|
|
88
|
+
guard let pictureInPictureController else {
|
|
89
|
+
removeOperation(for: DisposableKey.stopEnforceOperation.rawValue)
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let operation = Timer
|
|
94
|
+
.publish(every: refreshRate, on: .main, in: .common)
|
|
95
|
+
.autoconnect()
|
|
96
|
+
.filter { _ in
|
|
97
|
+
UIApplication.shared.applicationState == .active
|
|
98
|
+
}
|
|
99
|
+
.sink { [weak pictureInPictureController] _ in
|
|
100
|
+
// Calling stop repeatedly at display cadence covers cases where
|
|
101
|
+
// AVKit does not settle PiP shutdown on the first attempt.
|
|
102
|
+
pictureInPictureController?.stopPictureInPicture()
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
store(operation, key: DisposableKey.stopEnforceOperation.rawValue)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private func store(_ operation: AnyCancellable, key: String) {
|
|
109
|
+
// Keyed replacement ensures exactly one enforcement loop is active.
|
|
110
|
+
removeOperation(for: key)
|
|
111
|
+
operationCancellables[key] = operation
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private func removeOperation(for key: String) {
|
|
115
|
+
operationCancellables[key]?.cancel()
|
|
116
|
+
operationCancellables[key] = nil
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private func removeAllOperations() {
|
|
120
|
+
operationCancellables.values.forEach { $0.cancel() }
|
|
121
|
+
operationCancellables.removeAll()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private static func makeApplicationStatePublisher(
|
|
125
|
+
notificationCenter: NotificationCenter = .default
|
|
126
|
+
) -> AnyPublisher<ApplicationState, Never> {
|
|
127
|
+
let foreground = Publishers.Merge(
|
|
128
|
+
notificationCenter
|
|
129
|
+
.publisher(for: UIApplication.willEnterForegroundNotification)
|
|
130
|
+
.map { _ in ApplicationState.foreground },
|
|
131
|
+
notificationCenter
|
|
132
|
+
.publisher(for: UIApplication.didBecomeActiveNotification)
|
|
133
|
+
.map { _ in ApplicationState.foreground }
|
|
134
|
+
)
|
|
135
|
+
let background = notificationCenter
|
|
136
|
+
.publisher(for: UIApplication.didEnterBackgroundNotification)
|
|
137
|
+
.map { _ in ApplicationState.background }
|
|
138
|
+
|
|
139
|
+
return Publishers.Merge(foreground, background)
|
|
140
|
+
// Emit the current app state immediately so newly created adapters
|
|
141
|
+
// do not wait for the next lifecycle notification.
|
|
142
|
+
.prepend(currentApplicationState())
|
|
143
|
+
.removeDuplicates()
|
|
144
|
+
.eraseToAnyPublisher()
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private static func currentApplicationState() -> ApplicationState {
|
|
148
|
+
switch UIApplication.shared.applicationState {
|
|
149
|
+
case .active:
|
|
150
|
+
return .foreground
|
|
151
|
+
case .background:
|
|
152
|
+
return .background
|
|
153
|
+
case .inactive:
|
|
154
|
+
return .unknown
|
|
155
|
+
@unknown default:
|
|
156
|
+
return .unknown
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private static func makeRefreshRate() -> TimeInterval {
|
|
161
|
+
// Keep cadence aligned to the device's display refresh rate while
|
|
162
|
+
// enforcing a practical minimum (30fps) for older/limited devices.
|
|
163
|
+
let maximumFramesPerSecond = max(30, UIScreen.main.maximumFramesPerSecond)
|
|
164
|
+
return 1.0 / Double(maximumFramesPerSecond)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright © 2024 Stream.io Inc. All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import Foundation
|
|
6
|
+
|
|
7
|
+
/// Centralized logger for Picture in Picture diagnostics.
|
|
8
|
+
///
|
|
9
|
+
/// Logging is debug-only to avoid production noise and overhead.
|
|
10
|
+
enum PictureInPictureLogger {
|
|
11
|
+
static func log(_ message: @autoclosure () -> String) {
|
|
12
|
+
#if DEBUG
|
|
13
|
+
NSLog("PiP - %@", message())
|
|
14
|
+
#endif
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright © 2024 Stream.io Inc. All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import UIKit
|
|
6
|
+
|
|
7
|
+
/// A view that displays participant information overlay in Picture-in-Picture mode.
|
|
8
|
+
/// Shows participant name, pin indicator, sound indicator, and video paused indicator
|
|
9
|
+
/// at the bottom-left of the PiP window.
|
|
10
|
+
/// This aligns with upstream stream-video-swift ParticipantInfoView.
|
|
11
|
+
final class PictureInPictureParticipantOverlayView: UIView {
|
|
12
|
+
|
|
13
|
+
// MARK: - Properties
|
|
14
|
+
|
|
15
|
+
/// The participant's name to display
|
|
16
|
+
var participantName: String? {
|
|
17
|
+
didSet {
|
|
18
|
+
nameLabel.text = participantName
|
|
19
|
+
updateVisibility()
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/// Whether the participant is pinned
|
|
24
|
+
var isPinned: Bool = false {
|
|
25
|
+
didSet {
|
|
26
|
+
pinIconView.isHidden = !isPinned
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/// Whether the participant has audio enabled (not muted)
|
|
31
|
+
var hasAudio: Bool = true {
|
|
32
|
+
didSet {
|
|
33
|
+
updateSoundIndicator()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/// Whether the video track is paused/disabled
|
|
38
|
+
var isTrackPaused: Bool = false {
|
|
39
|
+
didSet {
|
|
40
|
+
updateVideoPausedIndicator()
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/// Controls whether the overlay is shown
|
|
45
|
+
var isOverlayEnabled: Bool = true {
|
|
46
|
+
didSet {
|
|
47
|
+
updateVisibility()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// MARK: - UI Components
|
|
52
|
+
|
|
53
|
+
/// Container for the bottom info bar with gradient background
|
|
54
|
+
private lazy var containerView: UIView = {
|
|
55
|
+
let view = UIView()
|
|
56
|
+
view.translatesAutoresizingMaskIntoConstraints = false
|
|
57
|
+
return view
|
|
58
|
+
}()
|
|
59
|
+
|
|
60
|
+
/// Gradient layer for the bottom fade effect
|
|
61
|
+
private lazy var gradientLayer: CAGradientLayer = {
|
|
62
|
+
let layer = CAGradientLayer()
|
|
63
|
+
layer.colors = [
|
|
64
|
+
UIColor.clear.cgColor,
|
|
65
|
+
UIColor.black.withAlphaComponent(0.6).cgColor
|
|
66
|
+
]
|
|
67
|
+
layer.locations = [0.0, 1.0]
|
|
68
|
+
return layer
|
|
69
|
+
}()
|
|
70
|
+
|
|
71
|
+
/// Container for the content (name + indicators)
|
|
72
|
+
private lazy var contentStackView: UIStackView = {
|
|
73
|
+
let stack = UIStackView()
|
|
74
|
+
stack.translatesAutoresizingMaskIntoConstraints = false
|
|
75
|
+
stack.axis = .horizontal
|
|
76
|
+
stack.spacing = 4
|
|
77
|
+
stack.alignment = .center
|
|
78
|
+
return stack
|
|
79
|
+
}()
|
|
80
|
+
|
|
81
|
+
/// Pin indicator icon (shown when participant is pinned)
|
|
82
|
+
private lazy var pinIconView: UIImageView = {
|
|
83
|
+
let imageView = UIImageView()
|
|
84
|
+
imageView.translatesAutoresizingMaskIntoConstraints = false
|
|
85
|
+
imageView.contentMode = .scaleAspectFit
|
|
86
|
+
imageView.tintColor = .white
|
|
87
|
+
|
|
88
|
+
// Use SF Symbol for pin
|
|
89
|
+
let config = UIImage.SymbolConfiguration(pointSize: 10, weight: .medium)
|
|
90
|
+
imageView.image = UIImage(systemName: "pin.fill", withConfiguration: config)
|
|
91
|
+
imageView.isHidden = true // Hidden by default
|
|
92
|
+
imageView.setContentHuggingPriority(.required, for: .horizontal)
|
|
93
|
+
imageView.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
94
|
+
return imageView
|
|
95
|
+
}()
|
|
96
|
+
|
|
97
|
+
/// Label showing participant name
|
|
98
|
+
private lazy var nameLabel: UILabel = {
|
|
99
|
+
let label = UILabel()
|
|
100
|
+
label.translatesAutoresizingMaskIntoConstraints = false
|
|
101
|
+
label.font = .systemFont(ofSize: 11, weight: .medium)
|
|
102
|
+
label.textColor = .white
|
|
103
|
+
label.lineBreakMode = .byTruncatingTail
|
|
104
|
+
label.setContentHuggingPriority(.defaultLow, for: .horizontal)
|
|
105
|
+
label.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
|
|
106
|
+
return label
|
|
107
|
+
}()
|
|
108
|
+
|
|
109
|
+
/// Video paused indicator icon (wifi.slash when track is paused)
|
|
110
|
+
private lazy var videoPausedIconView: UIImageView = {
|
|
111
|
+
let imageView = UIImageView()
|
|
112
|
+
imageView.translatesAutoresizingMaskIntoConstraints = false
|
|
113
|
+
imageView.contentMode = .scaleAspectFit
|
|
114
|
+
imageView.tintColor = .white
|
|
115
|
+
|
|
116
|
+
// Use SF Symbol for video paused (wifi.slash as in upstream)
|
|
117
|
+
let config = UIImage.SymbolConfiguration(pointSize: 10, weight: .medium)
|
|
118
|
+
imageView.image = UIImage(systemName: "wifi.slash", withConfiguration: config)
|
|
119
|
+
imageView.isHidden = true // Hidden by default
|
|
120
|
+
imageView.setContentHuggingPriority(.required, for: .horizontal)
|
|
121
|
+
imageView.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
122
|
+
return imageView
|
|
123
|
+
}()
|
|
124
|
+
|
|
125
|
+
/// Sound indicator icon (microphone on/off)
|
|
126
|
+
private lazy var soundIndicatorView: UIImageView = {
|
|
127
|
+
let imageView = UIImageView()
|
|
128
|
+
imageView.translatesAutoresizingMaskIntoConstraints = false
|
|
129
|
+
imageView.contentMode = .scaleAspectFit
|
|
130
|
+
imageView.tintColor = .white
|
|
131
|
+
imageView.setContentHuggingPriority(.required, for: .horizontal)
|
|
132
|
+
imageView.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
133
|
+
return imageView
|
|
134
|
+
}()
|
|
135
|
+
|
|
136
|
+
// MARK: - Initialization
|
|
137
|
+
|
|
138
|
+
override init(frame: CGRect) {
|
|
139
|
+
super.init(frame: frame)
|
|
140
|
+
setUp()
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
required init?(coder: NSCoder) {
|
|
144
|
+
fatalError("init(coder:) has not been implemented")
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
override func layoutSubviews() {
|
|
148
|
+
super.layoutSubviews()
|
|
149
|
+
// Update gradient frame when view bounds change
|
|
150
|
+
CATransaction.begin()
|
|
151
|
+
CATransaction.setDisableActions(true)
|
|
152
|
+
gradientLayer.frame = containerView.bounds
|
|
153
|
+
CATransaction.commit()
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// MARK: - Private Methods
|
|
157
|
+
|
|
158
|
+
private func setUp() {
|
|
159
|
+
isUserInteractionEnabled = false
|
|
160
|
+
isHidden = true // Hidden by default until participant info is set
|
|
161
|
+
|
|
162
|
+
addSubview(containerView)
|
|
163
|
+
containerView.layer.insertSublayer(gradientLayer, at: 0)
|
|
164
|
+
containerView.addSubview(contentStackView)
|
|
165
|
+
|
|
166
|
+
contentStackView.addArrangedSubview(pinIconView)
|
|
167
|
+
contentStackView.addArrangedSubview(nameLabel)
|
|
168
|
+
contentStackView.addArrangedSubview(videoPausedIconView)
|
|
169
|
+
contentStackView.addArrangedSubview(soundIndicatorView)
|
|
170
|
+
|
|
171
|
+
NSLayoutConstraint.activate([
|
|
172
|
+
// Container positioned at the bottom
|
|
173
|
+
containerView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
174
|
+
containerView.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
175
|
+
containerView.bottomAnchor.constraint(equalTo: bottomAnchor),
|
|
176
|
+
containerView.heightAnchor.constraint(equalToConstant: 28),
|
|
177
|
+
|
|
178
|
+
// Content stack with padding
|
|
179
|
+
contentStackView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 8),
|
|
180
|
+
contentStackView.trailingAnchor.constraint(lessThanOrEqualTo: containerView.trailingAnchor, constant: -8),
|
|
181
|
+
contentStackView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: -6),
|
|
182
|
+
|
|
183
|
+
// Icon sizes
|
|
184
|
+
pinIconView.widthAnchor.constraint(equalToConstant: 12),
|
|
185
|
+
pinIconView.heightAnchor.constraint(equalToConstant: 12),
|
|
186
|
+
videoPausedIconView.widthAnchor.constraint(equalToConstant: 12),
|
|
187
|
+
videoPausedIconView.heightAnchor.constraint(equalToConstant: 12),
|
|
188
|
+
soundIndicatorView.widthAnchor.constraint(equalToConstant: 12),
|
|
189
|
+
soundIndicatorView.heightAnchor.constraint(equalToConstant: 12)
|
|
190
|
+
])
|
|
191
|
+
|
|
192
|
+
// Initialize indicators
|
|
193
|
+
updateSoundIndicator()
|
|
194
|
+
updateVideoPausedIndicator()
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
private func updateVisibility() {
|
|
198
|
+
// Show overlay only if enabled and we have a participant name
|
|
199
|
+
let hasName = participantName != nil && !(participantName?.isEmpty ?? true)
|
|
200
|
+
isHidden = !isOverlayEnabled || !hasName
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
private func updateSoundIndicator() {
|
|
204
|
+
let config = UIImage.SymbolConfiguration(pointSize: 10, weight: .medium)
|
|
205
|
+
if hasAudio {
|
|
206
|
+
soundIndicatorView.image = UIImage(systemName: "mic.fill", withConfiguration: config)
|
|
207
|
+
soundIndicatorView.tintColor = .white
|
|
208
|
+
} else {
|
|
209
|
+
soundIndicatorView.image = UIImage(systemName: "mic.slash.fill", withConfiguration: config)
|
|
210
|
+
soundIndicatorView.tintColor = UIColor(white: 0.7, alpha: 1.0) // Slightly dimmed when muted
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private func updateVideoPausedIndicator() {
|
|
215
|
+
videoPausedIconView.isHidden = !isTrackPaused
|
|
216
|
+
}
|
|
217
|
+
}
|