This module supports the RTMP protocol.
RTMPHaishinKit is RTMP protocols stack in Swift.
- FMLE-compatible Authentication
- Publish
- H264, HEVC, AAC and OPUS support.
- Playback
- H264, HEVC and AAC support.
- Action Message Format
- AMF0
- AMF3
- SharedObject
- RTMPS
- Native (RTMP over SSL/TLS)
- Enhanced RTMP
let mixer = MediaMixer()
let connection = RTMPConnection()
let stream = RTMPStream(connection: connection)
let hkView = MTHKView(frame: view.bounds)
Task {
do {
try await mixer.attachAudio(AVCaptureDevice.default(for: .audio))
} catch {
print(error)
}
do {
try await mixer.attachVideo(AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back))
} catch {
print(error)
}
await mixer.addOutput(stream)
}
Task { MainActor in
await stream.addOutput(hkView)
// add ViewController#view
view.addSubview(hkView)
}
Task {
do {
try await connection.connect("rtmp://localhost/appName/instanceName")
try await stream.publish(streamName)
} catch RTMPConnection.Error.requestFailed(let response) {
print(response)
} catch RTMPStream.Error.requestFailed(let response) {
print(response)
} catch {
print(error)
}
}let connection = RTMPConnection()
let stream = RTMPStream(connection: connection)
let audioPlayer = AudioPlayer(AVAudioEngine())
let hkView = MTHKView(frame: view.bounds)
Task { MainActor in
await stream.addOutput(hkView)
}
Task {
// requires attachAudioPlayer
await stream.attachAudioPlayer(audioPlayer)
do {
try await connection.connect("rtmp://localhost/appName/instanceName")
try await stream.play(streamName)
} catch RTMPConnection.Error.requestFailed(let response) {
print(response)
} catch RTMPStream.Error.requestFailed(let response) {
print(response)
} catch {
print(error)
}
}It supports FME-compatible authentication. Some other services may use their own unique authentication methods, so connection may not be possible in those cases.
var connection = RTMPConnection()
connection.connect("rtmp://username:password@localhost/appName/instanceName")