Skip to content

Commit

Permalink
Bump to HaishinKit.swift up 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Sep 18, 2024
1 parent 5e9dc07 commit 5d8f721
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 245 deletions.
8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ PODS:
- Flutter (1.0.0)
- haishin_kit (0.13.0):
- Flutter
- HaishinKit (= 1.9.2)
- HaishinKit (1.9.2):
- HaishinKit (= 2.0.0-beta.3)
- HaishinKit (2.0.0-beta.3):
- Logboard (~> 2.5.0)
- Logboard (2.5.0)
- permission_handler_apple (9.3.0):
Expand Down Expand Up @@ -35,8 +35,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
audio_session: 088d2483ebd1dc43f51d253d4a1c517d9a2e7207
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
haishin_kit: 9008ff8d1017cbecece1cb5dab147685846e1156
HaishinKit: dc4a571fc6018372922f309987fcf061f3f7dc86
haishin_kit: 9d6d1c420c32030f80a02a4219703054e1f3795b
HaishinKit: b520432ee67c3aeb1820e177a09bc26e188fc317
Logboard: 4674a3d86681539a0ad1fca528d888b90871e268
permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2

Expand Down
6 changes: 3 additions & 3 deletions ios/Classes/ASObjectUil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import HaishinKit

enum ASObjectUtil {
static func removeEmpty(_ value: Any?) -> Any? {
if var value = value as? ASObject {
if var value = value as? AMFObject {
for element in value {
value[element.key] = removeEmpty(element.value)
}
return value.isEmpty ? nil : value
}
if let value = value as? ASArray {
if let value = value as? AMFArray {
var result: [Any?] = []
for i in 0..<value.length {
result.append(removeEmpty(value[i]))
}
return result.isEmpty ? nil : result
}
if let value = value {
if value is ASUndefined {
if value is AMFUndefined {
return nil
}
return value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
import HaishinKit
import AVFoundation

final class IOStreamDrawableTexture: NSObject, FlutterTexture {
final class HKStreamFlutterTexture: NSObject, FlutterTexture {
static let defaultOptions: [String: Any] = [
kCVPixelBufferCGImageCompatibilityKey as String: true,
kCVPixelBufferCGBitmapContextCompatibilityKey as String: true,
Expand All @@ -18,12 +18,7 @@ final class IOStreamDrawableTexture: NSObject, FlutterTexture {
private var currentSampleBuffer: CMSampleBuffer?
private let registry: FlutterTextureRegistry
private let context = CIContext()
private var queue = DispatchQueue(label: "com.haishinkit.NetStreamDrawableTexture")
private weak var currentStream: IOStream? {
didSet {
currentStream?.view = self
}
}
private var queue = DispatchQueue(label: "com.haishinkit.HKStreamFlutterTexture")

init(registry: FlutterTextureRegistry) {
self.registry = registry
Expand Down Expand Up @@ -79,20 +74,13 @@ final class IOStreamDrawableTexture: NSObject, FlutterTexture {
}
}

extension IOStreamDrawableTexture: IOStreamView {
// MARK: - NetStreamDrawable
func attachStream(_ stream: IOStream?) {
if Thread.isMainThread {
currentStream = stream
} else {
DispatchQueue.main.async {
self.currentStream = stream
}
}
extension HKStreamFlutterTexture: HKStreamOutput {
// MARK: HKStreamOutput
func stream(_ stream: some HaishinKit.HKStream, didOutput audio: AVAudioBuffer, when: AVAudioTime) {
}

func enqueue(_ sampleBuffer: CMSampleBuffer?) {
currentSampleBuffer = sampleBuffer
self.registry.textureFrameAvailable(id)
func stream(_ stream: some HaishinKit.HKStream, didOutput video: CMSampleBuffer) {
self.currentSampleBuffer = video
registry.textureFrameAvailable(id)
}
}
44 changes: 17 additions & 27 deletions ios/Classes/RTMPConnectionHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,33 @@ final class RTMPConnectionHandler: NSObject, MethodCallHandler {
self.channel = nil
}
instance = RTMPConnection()
instance?.addEventListener(.rtmpStatus, selector: #selector(handler), observer: self)
instance?.addEventListener(.ioError, selector: #selector(handler), observer: self)
channel?.setStreamHandler(self)
}

func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
switch call.method {
case "RtmpConnection#connect":
guard
let arguments = call.arguments as? [String: Any?],
let command = arguments["command"] as? String else {
return
Task {
switch call.method {
case "RtmpConnection#connect":
guard
let arguments = call.arguments as? [String: Any?],
let command = arguments["command"] as? String else {
return
}
try? await instance?.connect(command)
case "RtmpConnection#close":
try? await instance?.close()
case "RtmpConnection#dispose":
instance = nil
plugin.onDispose(id: Int(bitPattern: ObjectIdentifier(self)))
default:
result(FlutterMethodNotImplemented)
}
instance?.connect(command)
case "RtmpConnection#close":
instance?.close()
case "RtmpConnection#dispose":
instance = nil
plugin.onDispose(id: Int(bitPattern: ObjectIdentifier(self)))
default:
result(FlutterMethodNotImplemented)
}
}

@objc
private func handler(_ notification: Notification) {
let event = Event.from(notification)
var map: [String: Any?] = [:]
map["type"] = event.type.rawValue
if let data = event.data {
map["data"] = ASObjectUtil.removeEmpty(data)
}
eventSink?(map)
}
}

extension RTMPConnectionHandler: FlutterStreamHandler {
// MARK: FlutterStreamHandler
public func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? {
self.eventSink = events
return nil
Expand Down
Loading

0 comments on commit 5d8f721

Please sign in to comment.