Hi Carlos,
I’ve tried to send the signal from the server to the front-end and it worked, however some parameters value are missing.
I leave here the example code of my front-end application:
// Permette di ottenere i dati della sessione.
onRoomCreated(room: Room): void
{
console.log('onRoomCreated()');
// Listener per la registrazione della sessione.
room.on(RoomEvent.RecordingStatusChanged, async (recordingStatus: boolean) =>
{
console.log('Recording status changed: ', recordingStatus);
});
// Listener per i signal verso partecipanti remoti.
room.on(RoomEvent.DataReceived, (payload: Uint8Array, participant?: RemoteParticipant, kind?: DataPacket_Kind, topic?: string) =>
{
console.log('payload: ', JSON.parse(new TextDecoder().decode(payload)));
console.log('participant: ', participant);
console.log('kind: ', kind);
console.log('topic: ', topic);
});
}
Then, I leave here the example code of my backend application:
$svc = new RoomServiceClient($sLiveKitAPIURL, $sLiveKitAPIKey, $sLiveKitAPISecret);
$svc -> sendData($aData['eventCode'], json_encode(['data' => $aEgressData]), 1, [], 'recordingStarted');
Here’s the result handled by my front-end application:
Why participant and topic parameters are empty while kind parameter not?
I’ve also checked the sendData() method in the LiveKit PHP library and the parameters are all setted up correctly on my end.
/**
* Sends data message to participants in the room.
*
* @param string $roomName
* The name of the room.
* @param string $data
* The payload to send.
* @param int $kind
* The delivery reliability.
* @param string[] $destinationIdentities
* Optional, list of participant identities to receive packet,
* leave blank to send the packet to everyone.
* @param string|null $topic
* Optional, topic for the packet.
*
* @return \Livekit\SendDataResponse
* The SendDataResponse object.
*/
public function sendData(string $roomName, string $data, int $kind, array $destinationIdentities = [], ?string $topic = NULL): SendDataResponse {
$videoGrant = new VideoGrant();
$videoGrant->setRoomName($roomName);
$videoGrant->setRoomAdmin();
return $this->rpc->SendData(
$this->authHeader($videoGrant),
new SendDataRequest([
'room' => $roomName,
'data' => $data,
'kind' => $kind,
'destination_identities' => $destinationIdentities,
'topic' => $topic,
'nonce' => random_bytes(16),
])
);
}
Greetings, Matteo.
