steep-balloon-41261
11/17/2022, 2:49 PMdry-elephant-14928
11/19/2022, 7:39 AMlksdk.ConnectToRoom(url, token, roomCB, lksdk.WithAutoSubscribe(false))wonderful-application-12620
11/21/2022, 4:50 PMroom, err := lksdk.ConnectToRoom(url, lksdk.ConnectInfo{
APIKey: "A....DYA",
APISecret: "....So0yCfxc",
RoomName: "TestRoom001",
ParticipantIdentity: "Robot007",
}, &lksdk.RoomCallback{
ParticipantCallback: lksdk.ParticipantCallback{
OnTrackSubscribed: onTrackSubscribed,
OnDataReceived: onDataReceived,
},
})
Now the onDatarReceived method should be called when another participant sends something via data channel. For testing i left out the target info (empty array) and thus all participants should receive the data event. Browser based client does, but not the client using the code above. Wierdly enough, if i send something, basically with
err = room.LocalParticipant.PublishData(payload,
livekit.DataPacket_RELIABLE,
[]string{})
The same go code running on the server side is receiving the data. Also the web client.
Thus 2 out of 3 participants are receiving but one participant stays in the dark. the two go implementations behave differently.
``````wonderful-application-12620
11/21/2022, 5:47 PMearly-gigabyte-44411
11/23/2022, 2:35 AMfunc createAgent(roomName string, callback *RoomCallback, name string) (*Room, error) {
room, err := ConnectToRoom(host, ConnectInfo{
APIKey: apiKey,
APISecret: apiSecret,
RoomName: roomName,
ParticipantIdentity: name,
}, callback)
if err != nil {
return nil, err
}
return room, nil
}
func TestDatachannel(t *testing.T) {
pub, err := createAgent(t.Name(), nil, "publisher")
require.NoError(t, err)
var dataLock sync.Mutex
var receivedData string
subCB := &RoomCallback{
ParticipantCallback: ParticipantCallback{
OnDataReceived: func(data []byte, rp *RemoteParticipant) {
dataLock.Lock()
receivedData = string(data)
dataLock.Unlock()
},
},
}
sub, err := createAgent(t.Name(), subCB, "subscriber")
require.NoError(t, err)
pub.LocalParticipant.PublishData([]byte("test"), livekit.DataPacket_RELIABLE, nil)
require.Eventually(t, func() bool {
dataLock.Lock()
defer dataLock.Unlock()
return receivedData == "test"
}, 5*time.Second, 100*time.Millisecond)
pub.Disconnect()
sub.Disconnect()
}