2024-06-25 00:55:32 -06:00
|
|
|
//
|
|
|
|
// ReactNativeVideoManager.swift
|
|
|
|
// react-native-video
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
public class ReactNativeVideoManager: RNVPlugin {
|
2025-01-04 05:47:22 -07:00
|
|
|
private let expectedMaxVideoCount = 2
|
2024-06-25 00:55:32 -06:00
|
|
|
|
|
|
|
// create a private initializer
|
|
|
|
private init() {}
|
|
|
|
|
|
|
|
public static let shared: ReactNativeVideoManager = .init()
|
|
|
|
|
2025-01-04 05:47:22 -07:00
|
|
|
private var instanceCount = 0
|
|
|
|
private var pluginList: [RNVPlugin] = Array()
|
2024-06-25 00:55:32 -06:00
|
|
|
|
|
|
|
/**
|
2025-01-04 05:47:22 -07:00
|
|
|
* register a new view
|
2024-06-25 00:55:32 -06:00
|
|
|
*/
|
2025-01-04 05:47:22 -07:00
|
|
|
func registerView(newInstance _: RCTVideo) {
|
|
|
|
if instanceCount > expectedMaxVideoCount {
|
2024-06-25 00:55:32 -06:00
|
|
|
DebugLog("multiple Video displayed ?")
|
|
|
|
}
|
2025-01-04 05:47:22 -07:00
|
|
|
instanceCount += 1
|
2024-06-25 00:55:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2025-01-04 05:47:22 -07:00
|
|
|
* unregister existing view
|
2024-06-25 00:55:32 -06:00
|
|
|
*/
|
2025-01-04 05:47:22 -07:00
|
|
|
func unregisterView(newInstance _: RCTVideo) {
|
|
|
|
instanceCount -= 1
|
2024-06-25 00:55:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* register a new plugin in the managed list
|
|
|
|
*/
|
|
|
|
public func registerPlugin(plugin: RNVPlugin) {
|
|
|
|
pluginList.append(plugin)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
public func onInstanceCreated(id: String, player: Any) {
|
|
|
|
pluginList.forEach { it in it.onInstanceCreated(id: id, player: player) }
|
|
|
|
}
|
|
|
|
|
|
|
|
public func onInstanceRemoved(id: String, player: Any) {
|
|
|
|
pluginList.forEach { it in it.onInstanceRemoved(id: id, player: player) }
|
|
|
|
}
|
|
|
|
}
|