Understanding command sendEndpointTextMessage

Hi Everyone,

I am trying to understand how the API Command “sendEndpointTextMessage” works

I had a requirement to send Notification(Popup) to participants based on their participant ID and was able to achieve it. In the text field of API i am passing custom json payload with like below

executeCommand("sendEndpointTextMessage","323138e9", JSON.stringify({message:"text", showMessage: false}));

When I use sendEndpointTextMessage from API it was received on conference.js—ENDPOINT_MESSAGE_RECEIVED callback and here in the call back I am showing Notification

 JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
            (...args) => {
                APP.store.dispatch(endpointMessageReceived(...args));
                if (args && args.length >= 2) {
                    const [ sender, eventData ] = args;
                    //Below code to send custom Notification using execute command
                    let customData = this.tryParseJSON(eventData.text);
                    if(customData && customData.showNotifyMessage) {
                        APP.store.dispatch(showNotification({
                            titleArguments: {
                                customMessage: customData.customMessage
                            },
                            titleKey: "notify.customNotificationTitle"
                        }, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
                        return;
                    }
                }
            });

The above code works fine for me and I am able to send the notifications to the participant that I want

Can someone clarify below

  • My question is whether the above code will break any other functionality

  • What happens internally when I use this command, few blogs say it uses chat channel, what is this, if someone else uses this to just send a message rather than json payload that I am sending then will the existing functionality break

No it won’t because you are checking for your custom attribute.

This command sends the data over to the other ppeer using the “bridge channel”, a communications channel which goes through the JVB and not the XMPP / signalling server.

Your functionality shouldn’t break because you are using that helper to parse JSON which fails gracefuly.

Thanks Saghul
@saghul

Can I pass an event listener in the payload json ? like below
JSON.stringify({message:"text", showMessage: false, customListener: "readyToClose"})) ;

I want to handle the listener in the ENDPOINT_MESSAGE_RECEIVED

How could I trigger the passed listener here in ENDPOINT_MESSAGE_RECEIVED ?

As Saul said, as long as your payload is a stringified JSON message (or any other text message), it should go through the backend without causing any side effects.

However, I wouldn’t alter the ENDPOINT_MESSAGE_RECEIVED handler. How are you integrating jitsi-meet? Are you using the IFrame API? If so, I would do something like this :

This is the receiving part …

const api = new JitsiMeetExternalAPI(...);
api.addEventListener('endpointTextMessageReceived', function(data) {
  const customData = JSON.parse(data.event.text); // this is your custom payload (needs safety handling)
  if (customData.commandName == 'showNotification') { // this is your custom event name
    api.executeCommand(customData.commandName, customData.commandPayload);
  }
});

… and this is the sending part

const api = new JitsiMeetExternalAPI(...);
const receiverParticipantId = ...;
const text = JSON.stringify({
  commandName: 'showNotification',
  commandPayload: {
    title: 'custom title',
    message: 'custom message'
  }
});
api.executeCommand('sendEndpointTextMessage', receiverParticipantId, text);

As a bonus point, this snippet can be used to run arbitrary API commands with little modification!

For more information on how to use the showNotification & sendEndpointTextMessage commands and handling the endpointTextMessageReceived event, have a look at our Iframe guide here

@gpolitis
Appreciate your reply here and your approach seems good

we are using Jitsi Meet in IFrame API
And also different code base for Mobile(android and IPhone) Few questions that I have in the receiving part

The below code shows notification to the participant that was mentioned in the sending part and others will no receive it, correct ?

 if (customData.commandName == 'showNotification') { // this is your custom event name
    api.executeCommand(customData.commandName, customData.commandPayload);
  }

I want to attach a listener from the sending side and handle the listener at the receiving side ? How coudl that be done ?

Yep, that’s right! Because customData.commandName == 'showNotification'.

I am not sure I understand your question correctly, but I think this small code snippet can be easily modified to achieve what you want:

this is the modified receiving part

const api = new JitsiMeetExternalAPI(...);
api.addEventListener('endpointTextMessageReceived', function(data) {
  const customData = JSON.parse(data.event.text); // this is your custom payload (needs safety handling)
  if (customData.commandName == 'showNotification') { // this is your custom event name
    api.executeCommand(customData.commandName, customData.commandPayload);
  } else if (customData.commandName == 'readyToClose') {
    // onReadyToClose is your listener. You need to somehow get a reference to it...
    onReadyToClose(commandData.commandPayload);
  }
});

… and this is the sending part for your listener

const api = new JitsiMeetExternalAPI(...);
const receiverParticipantId = ...;
const text = JSON.stringify({
  commandName: 'readyToClose',
  commandPayload: { notifyBeforeClosing: false } // this is just an example payload
});
api.executeCommand('sendEndpointTextMessage', receiverParticipantId, text);