livekit / client-sdk-swift

LiveKit Swift Client SDK. Easily build live audio or video experiences into your mobile app, game or website.
https://livekit.io
Apache License 2.0
173 stars 84 forks source link

There are some participant bugs here, in version 2.0.10 #413

Closed wzJun1 closed 1 week ago

wzJun1 commented 1 week ago

Describe the bug

  1. Why is there a local participant in room.remoteParticipants
  2. Why is the attribute of localParticipant nil after connecting for a certain period of time.
  3. Why does room connect after initialization, and local participant cannot obtain identity and metadata
  4. Based on the above issues, then delegate will also become abnormal, for example, local participants will trigger room(_ room: Room, participantDidConnect participant: RemoteParticipant), It's too outrageous

SDK Version 2.0.10

iOS/macOS Version iOS 17.2

Steps to Reproduce

  1. It can be replicated through foreach of room.remoteParticipants
  2. After initialization is completed, you can start connecting eg:
    
    var room = Room()

Task { do { try await room.connect(url: "", token: "") print("metadata = (room.localParticipant.metadata)") print("identity = (room.localParticipant.identity)") //They will print NIL, but if the sleep takes a certain amount of time, it will become normal to work } catch {} }


3. After using sleep to solve the 2 issue, After connecting to print, it will print out the localParticipant.identity normally, but if it prints again later, it will become nil

---------

hope the developers can take these issues seriously. Thank you!

---------

Paste a few problem codes:

1.

import UIKit

class TestViewController: UIViewController, RoomDelegate {

private var room = Room()

override func viewDidLoad() {
    self.view.backgroundColor = UIColor.white
    Task{
        await connect()
    }
}

func connect() async {
    //If written in this way, it will inevitably result in room. localParticipant. identity being nil
    room = Room(
         delegate: self
    )
    do{
        //But if I join the sleep, the result will become different, and at this point, room.localParticipant.identity is normal
        //eg: try await Task.sleep(nanoseconds: 1500000000)

        try await room.connect(url: "", token: "")
        print("metadata = \(String(describing: room.localParticipant.metadata))")
        print("identity = \(String(describing: room.localParticipant.identity))")

    }catch{
        print(error.localizedDescription)
    }
}

}


2. 

import UIKit

class TestViewController: UIViewController, RoomDelegate {

private var room = Room()

override func viewDidLoad() {
    self.view.backgroundColor = UIColor.white
    Task{
        await connect()
    }
}

func connect() async {
    room = Room(
        delegate: self
    )
    do{
        try await Task.sleep(nanoseconds: 1500000000)
        try await room.connect(url: "wss://aes1-88j8rdbt.livekit.cloud", token: "eyJhbGciOiJIUzI1NiJ9.eyJtZXRhZGF0YSI6IntcInN0YXJ0UHVibGlzaFwiOmZhbHNlLFwidXNlckluZm9cIjp7XCJ1c2VySWRcIjpcIjQ1NlwiLFwibmlja25hbWVcIjpcIuaOpeWQrOeahOS6ulwiLFwiYXZhdGFyXCI6XCJodHRwczovL2ltZzIud295YW9nZXhpbmcuY29tLzIwMjMvMDYvMjIvNWEzODQ2ZDk5Yzk3NDFkYmJiMGIzZjRlYzRjY2M5ZjIuanBnXCJ9fSIsInZpZGVvIjp7InJvb21DcmVhdGUiOnRydWUsInJvb21Kb2luIjp0cnVlLCJyb29tIjoiMTIzNDU2Nzg5MjIyMiIsImNhblVwZGF0ZU93bk1ldGFkYXRhIjp0cnVlfSwiaXNzIjoiQVBJWmJ1QjVLWjZmcWhoIiwiZXhwIjoxNzM2Njc1MDU1LCJuYmYiOjAsInN1YiI6IjQ1NiJ9.MFwx_XUspV2A_iIz_PsVgLxyalQDfdqV-dpKOm6J5B0")
        print("connect(): metadata = \(room.localParticipant.metadata)")
        print("connect(): identity = \(room.localParticipant.identity)")
        checkLocalParticipantInfo()
    }catch{
        print(error.localizedDescription)
    }
}

func checkLocalParticipantInfo(){
    //Delaying by 5 seconds to get identity. In fact, no matter how long the delay is, it is impossible to obtain identity, which is outrageous
    DispatchQueue.main.asyncAfter(deadline: .now() + 5){ [weak self] in
        if(self?.room.connectionState == .connected){
            print("checkLocalParticipantInfo(): identity = \(self?.room.localParticipant.identity)")
        }else{
            print("checkLocalParticipantInfo(): room connectionState is not connected")
        }
    } 
}

}



<img width="1491" alt="iShot_2024-06-26_17 50 53" src="https://github.com/livekit/client-sdk-swift/assets/52230047/6f0ac5da-1314-471f-89ed-10b22c01f29d">
wzJun1 commented 1 week ago

⚠️The above issues will occur in both Livekit Cloud and locally built Livekit servers. The Android SDK (version 2.4) does not have these issues.

wzJun1 commented 1 week ago

I think the most important issue is that after the room connection is successful, some information of local participants is missing. This is a fatal problem for our team.

Because he cannot obtain the parameters of the desired local participant at any time.

Our previous version of the product used 1.0.14, and the client-sdk-swift SDK is relatively stable.

hiroshihorie commented 1 week ago

Hello, I'm investigating but can't reproduce at the moment. Can you try v2.0.11 ?

Screenshot 2024-06-26 20 06 48
wzJun1 commented 1 week ago

great!

They have been fixed in version 2.0.11, Thx!!!😄😄😄