-
-
Save gigabyteservice/1063fec73dbde8fd147b43a6073b6eb0 to your computer and use it in GitHub Desktop.
Script showing how to send data through a Jitsi channel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<b>Message:</b> | |
<input | |
onchange="sendMessage(this.value)" | |
placeholder="Type and press enter to send message" | |
style="width: 640px" | |
/> | |
</div> | |
<div | |
id="info" | |
></div> | |
<div | |
id="jitsi" | |
style="width: 640px; height: 480px;" | |
></div> | |
<script src="https://meet.jit.si/external_api.js"></script> | |
<script> | |
const {offsetWidth: width, offsetHeight: height} = document.querySelector("#jitsi"); | |
const domain = 'meet.jit.si'; | |
const options = { | |
roomName: 'SendingManyData', | |
width, | |
height, | |
parentNode: document.querySelector('#jitsi') | |
}; | |
const api = new JitsiMeetExternalAPI(domain, options); | |
api.addEventListener('endpointTextMessageReceived', (rawMsg) => { | |
const text = rawMsg.data.eventData.text; | |
const msg = JSON.parse(text); | |
switch(msg.type) { | |
case "type_1": | |
document.querySelector("#info").innerHTML = `<pre>${JSON.stringify(msg, " ", 2)}</pre>`; | |
console.log("Got message type 1", msg); | |
break; | |
} | |
}); | |
function sendMessage(value) { | |
const msg = { | |
type: "type_1", | |
payload: value | |
}; | |
for(const participant in api._participants) { | |
let send = true; | |
if(!{}.hasOwnProperty.call(api._participants, participant)) { | |
continue; | |
} | |
const itsme = (api._participants[participant].formattedDisplayName.slice(-5) === " (me)"); | |
if(itsme) { | |
continue; | |
} | |
api.executeCommand('sendEndpointTextMessage', participant, JSON.stringify(msg)); | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment