Skip to content

Commit

Permalink
Rename Preference.default
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Jun 22, 2024
1 parent 43298d5 commit 5d3f865
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Examples/iOS/IngestViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class IngestViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

netStreamSwitcher.uri = Preference.defaultInstance.uri ?? ""
netStreamSwitcher.uri = Preference.default.uri ?? ""

stream.screen.size = .init(width: 720, height: 1280)
stream.screen.backgroundColor = UIColor.white.cgColor
Expand Down
8 changes: 4 additions & 4 deletions Examples/iOS/NetStreamSwitcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ final class NetStreamSwitcher {
switch method {
case .ingest:
// Performing operations for FMLE compatibility purposes.
(stream as? RTMPStream)?.fcPublishName = Preference.defaultInstance.streamName
(stream as? RTMPStream)?.fcPublishName = Preference.default.streamName
case .playback:
break
}
Expand Down Expand Up @@ -120,9 +120,9 @@ final class NetStreamSwitcher {
retryCount = 0
switch method {
case .playback:
(stream as? RTMPStream)?.play(Preference.defaultInstance.streamName!)
(stream as? RTMPStream)?.play(Preference.default.streamName!)
case .ingest:
(stream as? RTMPStream)?.publish(Preference.defaultInstance.streamName!)
(stream as? RTMPStream)?.publish(Preference.default.streamName!)
}
case RTMPConnection.Code.connectFailed.rawValue, RTMPConnection.Code.connectClosed.rawValue:
guard retryCount <= NetStreamSwitcher.maxRetryCount else {
Expand All @@ -139,7 +139,7 @@ final class NetStreamSwitcher {
@objc
private func rtmpErrorHandler(_ notification: Notification) {
logger.error(notification)
(connection as? RTMPConnection)?.connect(Preference.defaultInstance.uri!)
(connection as? RTMPConnection)?.connect(Preference.default.uri!)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Examples/iOS/PlaybackViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class PlaybackViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) {
logger.info("viewWillAppear")
super.viewWillAppear(animated)
netStreamSwitcher.uri = Preference.defaultInstance.uri ?? ""
netStreamSwitcher.uri = Preference.default.uri ?? ""
(view as? (any IOStreamView))?.attachStream(stream)
if #available(iOS 15.0, *), let layer = view.layer as? AVSampleBufferDisplayLayer, pictureInPictureController == nil {
pictureInPictureController = AVPictureInPictureController(contentSource: .init(sampleBufferDisplayLayer: layer, playbackDelegate: self))
Expand Down
2 changes: 1 addition & 1 deletion Examples/iOS/Preference.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
struct Preference {
static var defaultInstance = Preference()
static var `default` = Preference()

var uri: String? = "rtmp://192.168.1.6/live"
var streamName: String? = "live"
Expand Down
8 changes: 4 additions & 4 deletions Examples/iOS/PreferenceViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ final class PreferenceViewController: UIViewController {

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
urlField?.text = Preference.defaultInstance.uri
streamNameField?.text = Preference.defaultInstance.streamName
urlField?.text = Preference.default.uri
streamNameField?.text = Preference.default.streamName
}

@IBAction func on(open: UIButton) {
Expand All @@ -20,10 +20,10 @@ final class PreferenceViewController: UIViewController {
extension PreferenceViewController: UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if urlField == textField {
Preference.defaultInstance.uri = textField.text
Preference.default.uri = textField.text
}
if streamNameField == textField {
Preference.defaultInstance.streamName = textField.text
Preference.default.streamName = textField.text
}
textField.resignFirstResponder()
return true
Expand Down
6 changes: 3 additions & 3 deletions Examples/iOS/Screencast/SampleHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ open class SampleHandler: RPBroadcastSampleHandler {
LBLogger.with(HaishinKitIdentifier).level = .info
// rtmpStream.audioMixerSettings = .init(sampleRate: 0, channels: 2)
rtmpStream.audioMixerSettings.tracks[1] = .default
rtmpConnection.connect(Preference.defaultInstance.uri!, arguments: nil)
rtmpConnection.connect(Preference.default.uri!, arguments: nil)
// The volume of the audioApp can be obtained even when muted. A hack to synchronize with the volume.
DispatchQueue.main.async {
let volumeView = MPVolumeView(frame: CGRect.zero)
Expand Down Expand Up @@ -97,7 +97,7 @@ open class SampleHandler: RPBroadcastSampleHandler {
@objc
private func rtmpErrorHandler(_ notification: Notification) {
logger.info(notification)
rtmpConnection.connect(Preference.defaultInstance.uri!)
rtmpConnection.connect(Preference.default.uri!)
}

@objc
Expand All @@ -111,7 +111,7 @@ open class SampleHandler: RPBroadcastSampleHandler {
}
switch code {
case RTMPConnection.Code.connectSuccess.rawValue:
rtmpStream.publish(Preference.defaultInstance.streamName!)
rtmpStream.publish(Preference.default.streamName!)
default:
break
}
Expand Down
10 changes: 5 additions & 5 deletions Examples/iOSSwiftUI/Model/ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ final class ViewModel: ObservableObject {

func startPublish() {
UIApplication.shared.isIdleTimerDisabled = true
logger.info(Preference.defaultInstance.uri!)
logger.info(Preference.default.uri!)

rtmpConnection.addEventListener(.rtmpStatus, selector: #selector(rtmpStatusHandler), observer: self)
rtmpConnection.addEventListener(.ioError, selector: #selector(rtmpErrorHandler), observer: self)
rtmpConnection.connect(Preference.defaultInstance.uri!)
rtmpConnection.connect(Preference.default.uri!)
}

func stopPublish() {
Expand Down Expand Up @@ -211,14 +211,14 @@ final class ViewModel: ObservableObject {
switch code {
case RTMPConnection.Code.connectSuccess.rawValue:
retryCount = 0
rtmpStream.publish(Preference.defaultInstance.streamName!)
rtmpStream.publish(Preference.default.streamName!)
// sharedObject!.connect(rtmpConnection)
case RTMPConnection.Code.connectFailed.rawValue, RTMPConnection.Code.connectClosed.rawValue:
guard retryCount <= maxRetryCount else {
return
}
Thread.sleep(forTimeInterval: pow(2.0, Double(retryCount)))
rtmpConnection.connect(Preference.defaultInstance.uri!)
rtmpConnection.connect(Preference.default.uri!)
retryCount += 1
default:
break
Expand All @@ -228,7 +228,7 @@ final class ViewModel: ObservableObject {
@objc
private func rtmpErrorHandler(_ notification: Notification) {
logger.error(notification)
rtmpConnection.connect(Preference.defaultInstance.uri!)
rtmpConnection.connect(Preference.default.uri!)
}
}

Expand Down
4 changes: 2 additions & 2 deletions Examples/macOS/CameraIngestViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ final class CameraIngestViewController: NSViewController {

override func viewDidLoad() {
super.viewDidLoad()
urlField.stringValue = Preference.defaultInstance.uri ?? ""
urlField.stringValue = Preference.default.uri ?? ""
audioPopUpButton?.present(mediaType: .audio)
cameraPopUpButton?.present(mediaType: .video)
netStreamSwitcher.uri = Preference.defaultInstance.uri ?? ""
netStreamSwitcher.uri = Preference.default.uri ?? ""
lfView?.attachStream(stream)
}

Expand Down
2 changes: 1 addition & 1 deletion Examples/macOS/PlaybackViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class PlaybackViewController: NSViewController {

override func viewDidLoad() {
super.viewDidLoad()
netStreamSwitcher.uri = Preference.defaultInstance.uri!
netStreamSwitcher.uri = Preference.default.uri!
lfView.attachStream(stream)
}

Expand Down
8 changes: 4 additions & 4 deletions Examples/macOS/PreferenceViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ final class PreferenceViewController: NSViewController {

override func viewDidLoad() {
super.viewDidLoad()
urlField.stringValue = Preference.defaultInstance.uri ?? ""
streamNameField.stringValue = Preference.defaultInstance.streamName ?? ""
urlField.stringValue = Preference.default.uri ?? ""
streamNameField.stringValue = Preference.default.streamName ?? ""
}
}

Expand All @@ -18,10 +18,10 @@ extension PreferenceViewController: NSTextFieldDelegate {
return
}
if textFile == urlField {
Preference.defaultInstance.uri = textFile.stringValue
Preference.default.uri = textFile.stringValue
}
if textFile == streamNameField {
Preference.defaultInstance.streamName = textFile.stringValue
Preference.default.streamName = textFile.stringValue
}
}
}
4 changes: 2 additions & 2 deletions Examples/macOS/SCStreamPublishViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class SCStreamPublishViewController: NSViewController {

override func viewDidLoad() {
super.viewDidLoad()
urlField.stringValue = Preference.defaultInstance.uri ?? ""
netStreamSwitcher.uri = Preference.defaultInstance.uri ?? ""
urlField.stringValue = Preference.default.uri ?? ""
netStreamSwitcher.uri = Preference.default.uri ?? ""
mthkView?.attachStream(stream)
if #available(macOS 12.3, *) {
Task {
Expand Down

0 comments on commit 5d3f865

Please sign in to comment.