This message was deleted.
# helpdesk
s
This message was deleted.
b
My first thought would be, does your token have the permission
m
Can you share some code pls @dry-farmer-50272 ?
d
import {AudioPresets, ConnectionQuality, DataPacket_Kind, Room, RoomEvent, Track, VideoPresets} from 'livekit-client';
const encoder = new TextEncoder()
const decoder = new TextDecoder()
class Client {
constructor() {
this.room = new Room({
videoCaptureDefaults: {
resolution: VideoPresets.h216.resolution
},
adaptiveStream: false,
publishDefaults: {
videoCodec: "h264",
red: false,
dtx: false,
simulcast: false,
}
});
this.room.on(RoomEvent.DataReceived, OnDataReceived)
}
async sendMessage(_data_, _participantSIDs_) {
const strData = JSON.stringify(_data_)
const encodedData = encoder.encode(strData)
await this.room.localParticipant.publishData(encodedData, DataPacket_Kind.RELIABLE)
}
async connect(_token_) {
`await this.room.connect(
<ws://localhost:7880>
, token, {`
autoSubscribe: true, maxRetries: 3, peerConnectionTimeout: 15_000, rtcConfig: {
bundlePolicy: "max-bundle", rtcpMuxPolicy: "require"
}
})
}
}
function OnDataReceived(_payload_, _participant_, _kind_) {
const strData = decoder.decode(_payload_)
console.log('data received', strData, _participant_, _kind_)
}
const client = new Client()
export {client}
b
Simply to validate, in your video grant, you do have
canPublishData: true
? Ref: https://docs.livekit.io/concepts/authentication/#video-grant
d
this is the code of server
func getJoinToken(apiKey, apiSecret, room, identity string) (string, error) {
at := auth.NewAccessToken("devkey", "secretsecretsecretsecretsecretsecretsecretsecret")
CanPublish := true
CanSubscribe := true
CanPublishData := true
grant := &auth.VideoGrant{
RoomCreate:           false,
RoomList:             false,
RoomJoin:             true,
Room:                 room,
CanPublish:           &CanPublish,
CanSubscribe:         &CanSubscribe,
CanPublishData:       &CanPublishData,
CanPublishSources:    nil,
CanUpdateOwnMetadata: nil,
Hidden:               false,
}
at.AddGrant(grant).SetIdentity(identity).SetValidFor(time.Hour)
return at.ToJWT()
}
I read the whole doc of livekit itself , js and go sdk
b
Your
sendMessage
method seems correct. May I ask you if you are using the LK Cloud or your own LK Server?
d
its my own
I just simply downloaded the binary and ran it
m
Are you attempting to send a data message to the same participant? I don’t think that works. (Full disclosure: I’ve only taken a quick glance)
d
why should I do that ? 😁 I simply just want to send a json to server
m
Well, it looks like you’re sending data messages between participants (facilitated via server).
d
yeah some messages should be send to other users through livekit server and some messages should be send to Go sdk only
@magnificent-art-43333 do you have a working example of sending message with js and go sdk so I can compare it to my code??
b
@dry-farmer-50272 You should be able to look up the examples provided here : https://github.com/livekit/client-sdk-js/tree/main/example
d
thanks
it seems to be exactly like mine its really weird that is doesnt work 🤔
@dry-elephant-14928 any opinion about this problem ?
b
As a suggestion, I'd probably create an account on cloud, see if you are facing the same issue or not. This would validate if its something with the LK Server Setup or the code.
d
Sorry, I don't have enough context here. But if it works with JS example app that Pat pointed you to, but not your own. My guess is there are differences in how you are using the APIs? Are you expecting to deliver a message to the same instance of the client?
As Russ mentioned, you can send data messages to other participants, but not to itself.
d
yeah , I passed empty string array (also tried undefined) as participant sids in order to send to all other participants but does not have any affect
m
@dry-farmer-50272 you need to have multiple participants in a room to be able to send messages back and forth. We use this feature extensively in example apps.