DTMF control for Pexip Meetings

import xapi from 'xapi';

xapi.Command.UserInterface.Extensions.Panel.Save({ PanelId: 'pexip_panel' }, `<Extensions>
  <Version>1.0</Version>
  <Panel>
    <Order>4</Order>
    <PanelId>pexip_panel</PanelId>
    <Origin>local</Origin>
    <Type>InCall</Type>
    <Icon>Sliders</Icon>
    <Color>#A866FF</Color>
    <Name>Pexip Controls</Name>
    <ActivityType>Custom</ActivityType>
    <Page>
      <Name>Pexip DTMF Controls</Name>
      <Row>
	  <Name> In conference control</Name>
        <Widget>
          <WidgetId>changelayout</WidgetId>
          <Name>Change Layout</Name>
          <Type>Button</Type>
          <Options>size=4</Options>
        </Widget>
		<Widget>
          <WidgetId>lock</WidgetId>
          <Name>Lock/Unlock conference</Name>
          <Type>Button</Type>
          <Options>size=4</Options>
        </Widget>
		<Widget>
          <WidgetId>presoinmix</WidgetId>
          <Name>Show/Hide presentation in mix</Name>
          <Type>Button</Type>
          <Options>size=4</Options>
        </Widget>
		<Widget>
          <WidgetId>muteguests</WidgetId>
          <Name>Mute/Unmute all guests</Name>
          <Type>Button</Type>
          <Options>size=4</Options>
        </Widget>
      </Row>
    </Page>
  </Panel>
</Extensions>`);

//Function to send the DTMF tones during the call.  This receives the DTMF tones from the Event Listenter below.

const sleep = (timeout) => new Promise((resolve) => {
  setTimeout(resolve, timeout);
});
async function sendDTMF(code, message) {
    console.log(message);

    try {
        const Level = await xapi.Status.Audio.Volume.get();
        await xapi.Command.Audio.Volume.Set({
            Level: "30",
        });
        console.log("Volume set to 30");

        await sleep(200);
        xapi.Command.Call.DTMFSend({
            DTMFString: code,
        });
        console.log("DTMF Values Sent")

        await sleep(750);
        await xapi.Command.Audio.Volume.Set({
            Level
        });
        console.log("Volume Set Back to " + Level)

    } catch (error) {
        console.error(error);
    }
}

//Event Listener - In this listener we are checking against various Widget ID's to see if they are pressed, and if they are we then send the appropriate DTMF tones to the sendDTMF function listed above.  You can edit each of these to match your WigitID's and/or add/subtract addtional case statements.

xapi.Event.UserInterface.Extensions.Widget.Action.on((event) => {
  if (event.Type !== 'pressed'){
    return;
  }
    switch (event.WidgetId) {
      case "changelayout":
        return sendDTMF('*8', 'Change Layout was Pressed');
      
      case "lock":
        return sendDTMF('*7', 'Conference locked');
        
      case "presoinmix":
        return sendDTMF('*4', 'Presentation in mix switch pressed');
        
      case "muteguests":
        return sendDTMF('*5', 'Mute all guests pressed');
        
    }});
1 Like