This message was deleted.
# helpdesk
s
This message was deleted.
d
Can you try to put in a slight delay before sending that message? I'm wondering if it's some sort of timing issue of some sort.
d
I added 1 second sleep at first line of OnParticipantConnected function and now it become slightly better but after for example 3-4 user connection still it does not send the data that Im trying to send in that callback It seems a little deadlock in livekit to me 🤔
d
can you share the code you are using? LiveKit regularly handles 10k+ participant rooms (in Cloud). it's highly unlikely that you would hit a deadlock with 3-4 users...
d
yeah sure !!
var RoomClient client
type client struct {
*lksdk.RoomServiceClient
}
func InitLiveKit() {
RoomClient = client{lksdk.NewRoomServiceClient(fmt.Sprintf("<http://%s:%s>", os.Getenv("LIVEKIT_HOST"), os.Getenv("LIVEKIT_PORT")), os.Getenv("LIVEKIT_API_KEY"), os.Getenv("LIVEKIT_SECRET_KEY"))}
}
func (c *client) ConnectToRoom(roomName, identity string) (*Session, error) {
r, err := lksdk.ConnectToRoom(fmt.Sprintf("<http://%s:%s>", os.Getenv("LIVEKIT_HOST"), os.Getenv("LIVEKIT_PORT")), lksdk.ConnectInfo{
APIKey:              os.Getenv("LIVEKIT_API_KEY"),
APISecret:           os.Getenv("LIVEKIT_SECRET_KEY"),
RoomName:            roomName,
ParticipantIdentity: identity,
}, &lksdk.RoomCallback{
OnParticipantConnected:    onUserConnected,
OnParticipantDisconnected: onUserDisconnected,
ParticipantCallback: lksdk.ParticipantCallback{
OnDataReceived: onDataReceived,
},
})
if err != nil {
return nil, err
}
return &Session{
Room:                 r,
Key:                  roomName,
}, nil
}
func (s *Session) SendMessage(msg any, sid ...string) error {
bytes, err := json.Marshal(msg)
if err != nil {
return err
}
return s.LocalParticipant.PublishData(bytes, livekit.DataPacket_RELIABLE, sid)
}
func onUserConnected(rp *lksdk.RemoteParticipant) {
if rp.Identity() == "server" || rp.Metadata() == "" {
return
}
log.Println("user connected", rp.Identity(), rp.Metadata())
time.Sleep(1 * time.Second)
//do on user connects stuff
//will be immediately printed but clients receives this message randomly
log.Println("room data sent")
}
func onUserDisconnected(rp *lksdk.RemoteParticipant) {
log.Println("user disconnected")
}
func onDataReceived(data []byte, rp *lksdk.RemoteParticipant) {
log.Println("data received:", string(data), rp.Name())
}
@dry-elephant-14928 no idea about this??
d
Where do you send data? I only see the line
log.Println("room data sent")
, without any calls to
SendMessage
can you upload an example that can reproduce this as a gist? that'd make it easier for us to run
d
sure, here you are ...