Skip to content

Commit

Permalink
add support for json payload in whep and whip
Browse files Browse the repository at this point in the history
  • Loading branch information
deleolajide committed Jan 6, 2025
1 parent 5a75d73 commit 87b0bb9
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 20 deletions.
2 changes: 1 addition & 1 deletion classes/jsp/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ html, body {
margin: 0;
height: 100%;
overflow: hidden;
font-size:14px;
font-size:13px;
}
.form-control {
font-size:12px;
Expand Down
1 change: 0 additions & 1 deletion classes/jsp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@
<script src='./js/0341_Aspirin_sf2_file.js'></script>
<script src='./js/0260_JCLive_sf2_file.js'></script>

<script src="./dist/libsignal-protocol.min.js"></script>
<script src="./dist/converse.js"></script>

<script src="./assets/pedalboard.js" type="module"></script>
Expand Down
2 changes: 1 addition & 1 deletion classes/jsp/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const createOrinAyoWindow = () => {
chrome.windows.create(data, async (win) => {
//await chrome.offscreen.closeDocument();
chrome.storage.local.set({orinAyoWin: win.id});
chrome.windows.update(win.id, {width: 1090, height: 1040});
chrome.windows.update(win.id, {width: 1120, height: 1040});
});
}

Expand Down
69 changes: 53 additions & 16 deletions classes/jsp/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var arrSequence = null;
var realdrumDevice = null;
var arranger = "webaudio";
var arrangerGroup = "imported";
var inputDeviceType = "games-controller";
var inputDeviceType = "keyboard";
var realGuitarStyle = "none";
var midiOutput = null;
var input = null;
Expand Down Expand Up @@ -114,6 +114,7 @@ var forwardChord = null;
var arrChordType = "maj";
var guitarAvailable = false;
var firstChord = [base, base + 4, base + 7];
var lastChord = firstChord;
var rcLooperChord = 0;
var aerosPart = 1;
var aerosChordTrack = 1;
Expand Down Expand Up @@ -752,8 +753,7 @@ async function doLavaGenieSetup(device) {
}

if (chordSelected) {
pad.axis[STRUM] = isStrumUp ? STRUM_UP : STRUM_DOWN;
isStrumUp = !isStrumUp;
pad.axis[STRUM] = autoStrumUpDown();
}

if (pad.buttons[LOGO]) {
Expand Down Expand Up @@ -996,9 +996,19 @@ async function fetchStreams() {

const res = await _converse.api.sendIQ($iq({type: 'set', to: _converse.api.domain}).c('whep', {id: activeStreams.value, xmlns: 'urn:xmpp:whep:0'}).c('sdp', offer.sdp));
console.debug('fetchStreams whep set response', res);
const answer = res.querySelector('sdp').innerHTML;
watchConnection.setRemoteDescription({sdp: answer, type: 'answer'});
console.debug('fetchStreams whep answer', answer);
const answer = res.querySelector('sdp')?.innerHTML;
const json = res.querySelector('json')?.innerHTML;
console.debug('fetchStreams whep answer', answer, json);

if (answer) {
watchConnection.setRemoteDescription({sdp: answer, type: 'answer'});
}

if (json) {
const metaData = JSON.parse(json);
tempo = metaData.tempo;
keyChange = metaData.keyChange;
}
})
}
});
Expand Down Expand Up @@ -1039,11 +1049,12 @@ async function handleMediaStream(started) {
}
})

const json = {tempo, keyChange, name: arrSequence?.name};
const offer = await publishConnection.createOffer();
publishConnection.setLocalDescription(offer);
console.debug('handleMediaStream offer', offer.sdp);

const res = await _converse.api.sendIQ($iq({type: 'set', to: _converse.api.domain}).c('whip', {xmlns: 'urn:xmpp:whip:0'}).c('sdp', offer.sdp));
const res = await _converse.api.sendIQ($iq({type: 'set', to: _converse.api.domain}).c('whip', {xmlns: 'urn:xmpp:whip:0'}).c('sdp').t(offer.sdp).up().c('json', {xmlns: 'urn:xmpp:json:0'}).t(JSON.stringify(json)));
const answer = res.querySelector('sdp').innerHTML;
publishConnection.setRemoteDescription({sdp: answer, type: 'answer'});
console.debug('handleMediaStream answer', answer);
Expand Down Expand Up @@ -1135,6 +1146,7 @@ function startXMPP() {
discover_connection_methods: false,
assets_path: "./dist/",
sounds_path: "./dist/sounds/",
notification_icon: "./assets/icon_128.png",
allow_logout: false,
allow_muc_invitations: false,
allow_contact_requests: false,
Expand Down Expand Up @@ -2381,7 +2393,12 @@ function handleNumPad(name, code) {
}

if (keyboard.get("0") || keyboard.get(".") || keyboard.get("1") || keyboard.get("2") || keyboard.get("3") || keyboard.get("4") || keyboard.get("5") || keyboard.get("6") || keyboard.get("7") || keyboard.get("8") || keyboard.get("9") || keyboard.get("*") || keyboard.get("/") || keyboard.get("Backspace")) {
toggleStrumUpDown();
pad.axis[STRUM] = autoStrumUpDown();

if (midiRealGuitar) {
midiRealGuitar.playNote(pad.axis[STRUM] == STRUM_UP ? 122 : 121, 1, {velocity: getVelocity(), duration: 1000});
}

handled = true;

if (keyboard.get("Backspace") && keyboard.get("0")) { // Fill
Expand Down Expand Up @@ -2522,10 +2539,12 @@ function handleNumPad(name, code) {
return handled;
}

function toggleStrumUpDown() {
pad.axis[STRUM] = isStrumUp ? STRUM_UP : STRUM_DOWN;
if (midiRealGuitar) midiRealGuitar.playNote(isStrumUp ? 122 : 121, 1, {velocity: getVelocity(), duration: 1000});
isStrumUp = !isStrumUp;
function autoStrumUpDown() {
const sameChord = arraysEqual(lastChord, firstChord);
console.debug("autoStrumUpDown", sameChord, firstChord, lastChord);

if (sameChord) return STRUM_UP;
return STRUM_DOWN;
}

function handleNoteOff(note, device, velocity, channel) {
Expand Down Expand Up @@ -2930,7 +2949,8 @@ function connectHandler(e) {

if (e.gamepad.id.indexOf("Guitar") > -1 || (e.gamepad.id.indexOf("248a") > -1 && e.gamepad.id.indexOf("8266") > -1) || e.gamepad.id == "Xbox 360 Controller for Windows (STANDARD GAMEPAD)") {
console.debug("connectHandler found gamepad " + e.gamepad.id, e.gamepad);


inputDeviceType = "games-controller";
if (!game) setup();

for (var i=0; i<e.gamepad.buttons.length; i++) {
Expand Down Expand Up @@ -3749,6 +3769,7 @@ async function setupUI(config,err) {
midiInType.options[3] = new Option("Artiphon Chorda", "chorda", config.inputDeviceType == "chorda");
midiInType.options[4] = new Option("LiberLive C1", "liberlivec1", config.inputDeviceType == "liberlivec1");
midiInType.options[5] = new Option("Lava Genie", "lavagenie", config.inputDeviceType == "lavagenie");
midiInType.options[6] = new Option("PC Keyboard", "keyboard", config.inputDeviceType == "keyboard");

let deviceIndex = 0;
deviceIndex = config.inputDeviceType == "games-controller" ? 0 : deviceIndex;
Expand All @@ -3757,6 +3778,7 @@ async function setupUI(config,err) {
deviceIndex = config.inputDeviceType == "chorda" ? 3 : deviceIndex;
deviceIndex = config.inputDeviceType == "liberlivec1" ? 4 : deviceIndex;
deviceIndex = config.inputDeviceType == "lavagenie" ? 5 : deviceIndex;
deviceIndex = config.inputDeviceType == "keyboard" ? 6 : deviceIndex;
midiInType.selectedIndex = deviceIndex;

inputDeviceType = config.inputDeviceType;
Expand Down Expand Up @@ -5309,10 +5331,15 @@ function playChord(chord, root, type, bass) {
const thirdNote = (chord.length == 4 ? chord[2] : chord[1]);
const fifthNote = (chord.length == 4 ? chord[3] : chord[2]);

firstChord = chord;

arrChordType = (type == 0x20 ? "sus" : (type == 0x08 ? "min" : (type == 0x13 ? "maj7" : "maj")));

if (!activeChord) {
lastChord = firstChord;
firstChord = chord;

if (inputDeviceType == "lavagenie" || inputDeviceType == "keyboard") pad.axis[STRUM] = autoStrumUpDown();

const arrChord = (firstChord.length == 4 ? firstChord[1] : firstChord[0]) % 12;
const key = "key" + arrChord + "_" + arrChordType + "_" + SECTION_IDS[sectionChange];
const bassKey = "key" + (bassNote % 12) + "_" + arrChordType + "_" + SECTION_IDS[sectionChange];
Expand Down Expand Up @@ -7371,8 +7398,7 @@ function scheduleSongNote() {

if (chord.length > 0) {
activeChord = null;
pad.axis[STRUM] = isStrumUp ? STRUM_UP : STRUM_DOWN;
isStrumUp = !isStrumUp;
pad.axis[STRUM] = autoStrumUpDown();
orinayo.innerHTML = displayShape;

if (!game) {
Expand Down Expand Up @@ -7979,6 +8005,17 @@ function midiProgramChangeEvent(target) {
console.debug("midiProgramChangeEvent", target.selectedIndex, target.id);
}

function arraysEqual(a, b) {
if (a === b) return true;
if (a == null || b == null) return false;
if (a.length !== b.length) return false;

for (var i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) return false;
}
return true;
}

// -------------------------------------------------------
//
// X-Touch MIDI Controller Device
Expand Down
2 changes: 2 additions & 0 deletions src/java/org/ifsoft/orinayo/openfire/BroadcastBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public class BroadcastBox implements Plugin, PropertyEventListener, ProcessListe
private JmDNS jmdns;

public static BroadcastBox self;
public ConcurrentHashMap<String, JSONObject> metaData = new ConcurrentHashMap<>();


public void destroyPlugin() {
PropertyEventDispatcher.removeListener(this);
Expand Down
9 changes: 8 additions & 1 deletion src/java/org/ifsoft/orinayo/openfire/WhepIQHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ public IQ handleIQ(IQ iq) {
final String answer = fetch("http://" + ipaddr + ":" + tcpPort + "/api/whep", id, offer, "POST");
final Element childElement = reply.setChildElement(ELEMENT_NAME, NAMESPACE1);
childElement.addElement("sdp").setText(answer);

final JSONObject metaData = BroadcastBox.self.metaData.get(id);

if (metaData != null) {
childElement.addElement("json", "urn:xmpp:json:0").setText(metaData.toString());
}
}
else

Expand All @@ -110,7 +116,8 @@ public IQ handleIQ(IQ iq) {
for (int i=0; i<streams.length(); i++) {
JSONObject stream = streams.getJSONObject(i);
Element item = childElement.addElement("item");
item.addAttribute("id", stream.getString("streamKey"));
String id = stream.getString("streamKey");
item.addAttribute("id", id);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/java/org/ifsoft/orinayo/openfire/WhipIQHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public IQ handleIQ(IQ iq)
final Element sdp = whip.element("sdp");
final String offer = sdp.getText();

final Element json = whip.element("json");
final JSONObject metaData = new JSONObject(json.getText());
BroadcastBox.self.metaData.put(id, metaData);

final String ipaddr = JiveGlobals.getProperty("orinayo.ipaddr", BroadcastBox.getIpAddress());
final String tcpPort = JiveGlobals.getProperty("orinayo.port", BroadcastBox.getPort());
final String webUrl = "http://" + ipaddr + ":" + tcpPort + "/api/whip";
Expand Down

0 comments on commit 87b0bb9

Please sign in to comment.