-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Improvement]SpeakerManager callSettings observation
- Loading branch information
1 parent
6448985
commit 0671dd4
Showing
7 changed files
with
249 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
Sources/StreamVideo/Utils/PublishedWeak/PublishedWeak.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// Copyright © 2024 Stream.io Inc. All rights reserved. | ||
// | ||
|
||
import Combine | ||
import Foundation | ||
|
||
/// A property wrapper that publishes updates to a weakly referenced value. | ||
/// | ||
/// `PublishedWeak` uses a weak reference for the wrapped value, meaning it does not retain | ||
/// the value, and the value can become `nil` when there are no strong references left. | ||
/// | ||
/// This property wrapper is useful for weakly-referenced objects where you want to | ||
/// broadcast changes without retaining the object. | ||
/// | ||
/// - Note: This wrapper only works with classes because it relies on weak references. | ||
@propertyWrapper | ||
final class PublishedWeak<Value: AnyObject> { | ||
|
||
private weak var _value: Value? | ||
private let subject = PassthroughSubject<Value?, Never>() | ||
|
||
/// The published publisher for observing changes to the wrapped value. | ||
var projectedValue: AnyPublisher<Value?, Never> { | ||
subject.eraseToAnyPublisher() | ||
} | ||
|
||
/// The wrapped value, weakly referenced. Assigning a new value triggers the publisher. | ||
var wrappedValue: Value? { | ||
get { _value } | ||
|
||
set { | ||
/// We send first the newValue to subscribers to emulate how property wrappers work | ||
/// using `willSet`. | ||
subject.send(newValue) | ||
_value = newValue | ||
} | ||
} | ||
|
||
/// Initializes the property wrapper with an initial value. | ||
init(wrappedValue: Value?) { | ||
_value = wrappedValue | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.