Код: Выделить всё
__attribute__((swift_name("Test")))
@protocol ComposeAppTest
@required
- (void)prepare __attribute__((swift_name("prepare()")));
- (void)start __attribute__((swift_name("start()")));
- (void)stop __attribute__((swift_name("stop()")));
@end
< /code>
Это генерирует что -то вроде этого: < /p>
// Generated protocol from Kotlin Multiplatform which I can't modify
public protocol Test {
func prepare()
func start()
func stop()
}
< /code>
Мне нужно ADPOT к этому протоколу и реализовать его в Swift 6 Env. Подготовьте
class DummyTest: Test {
private var connection: RTMPConnection? // this is an actor
private var stream: RTMPStream? // this is another actor
private var mixer: MediaMixer? // and this is another actor
init() {}
func prepare() { // caller need to be blocked until preparation will not finish
connection = RTMPConnection()
stream = RTMPStream(connection: connection!)
mixer = MediaMixer(
multiCamSessionEnabled: false,
multiTrackAudioMixingEnabled: false,
useManualCapture: true
)
let output = MTHKView(frame: .zero) // 1 need to be called from Main
await mixer!.setVideoOrientation(.landscapeRight) // 2
await mixer!.addOutput(stream!) // 3
await stream!.addOutput(output) // 4
}
func start() { // caller need to be blocked until method will not finish but I can't add async
do {
var response = try await connection!.connect("https://test-live-rtmp.twitch.tv:443") // 5
print(">>> Connect response: \(response)")
response = try await stream!.publish("appId") // 6
print(">>> Publish response: \(response)")
} catch RTMPConnection.Error.requestFailed(let response) {
print(">>> RTMPConnection.Error.requestFailed: \(response)")
} catch RTMPStream.Error.requestFailed(let response) {
print(">>> RTMPStream.Error.requestFailed: \(response)")
} catch {
print(">>> Other.Error: \(error)")
}
}
func stop() { // caller need to be blocked until method will not finish but I can't add async
try? await connection!.close() // 7
}
}
< /code>
Issue 1: Need to be called from Main
Issues 2, 3, 4: 'await' in a function that does not support concurrency
Issues 5, 6, 7: 'async' call in a function that does not support concurrency
< /code>
Variables connection, stream, mixer are all actors. I'm just learning Swift Concurrency and for me this is too big for beginner. I'm asking some more experienced devs how to approach for this implementation. I was thinking to use Locks but I'm trying to avoid it in favor of Swift Concurrency approach but I don't know how in this case. This is really deep water for me.
Подробнее здесь: https://stackoverflow.com/questions/796 ... s-approach