hello , i'm trying to implement a delegateProtocol...
# kotlin-native
m
hello , i'm trying to implement a delegateProtocol and facing a problem that none of it's methods are getting called but in swift side i was able to implement the delegate and make a simple working example so i think it might be related to the objective-c memory model when they are created in kotlin side🤔 sample code in threads any help is appreciated😃.
Copy code
@OptIn(ExperimentalForeignApi::class)
class IosRoomDelegate : NSObject(), RoomDelegateProtocol {
    override fun room(room: Room, participantDidConnect: RemoteParticipant) {
        println("participantDidConnect called")
    }

    override fun room(room: Room, participant: Participant, didUpdatePermissions: ParticipantPermissions) {
        println("didUpdatePermissions called")
    }

    override fun room(room: Room, localParticipant: LocalParticipant, didPublishTrack: LocalTrackPublication) {
        println("didPublishTrack called")
    }

    override fun room(room: Room, participant: Participant, didUpdateConnectionQuality: ConnectionQuality) {
        println("connection quality updated")
    }

}
Copy code
@Composable
fun RoomScreen() {
    Column(
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = androidx.compose.ui.Alignment.CenterHorizontally,
        modifier = Modifier.fillMaxSize(),
    ) {
        val roomDelegate = remember {
            IosRoomDelegate()
        }

        val room = remember(roomDelegate) {
            println("room delegate is $roomDelegate")
            IosRoom(roomDelegate)
        }

        var textFieldState by remember { mutableStateOf("") }

        TextField(
            value = textFieldState,
            onValueChange = { textFieldState = it },
            label = { },
        )

        val scope = rememberCoroutineScope()

        Button(
            onClick = {
                scope.launch {
                    room.connect(
                        url = "",
                        token = textFieldState,
                    )
                }
            }
        ) {
            Text("Connect")
        }

    }

}
and here is the Room code
Copy code
@OptIn(ExperimentalForeignApi::class)
class IosRoom(
    private val roomDelegate: IosRoomDelegate,
) : RoomWrapper {


    private val scope = CoroutineScope(
        SupervisorJob() + Dispatchers.Main + CoroutineName("IosRoomCoroutine")
    )


    private val room: Room = Room().apply {
        addDelegate(roomDelegate)
    }

    

    override suspend fun connect(url: String, token: String) {
        room.connectWithUrl(
            url = url,
            token = token,
            connectOptions = null,
            roomOptions = null,
            completionHandler = {},
        )
    }

    override fun disconnect() {
        room.disconnectWithCompletionHandler(completionHandler = {})
    }
    

}