Files
element-call-Github/sdk/index.html
2025-12-01 14:09:09 +01:00

73 lines
2.3 KiB
HTML

<!doctype html>
<html>
<head>
<title>Godot MatrixRTC Widget</title>
<meta charset="utf-8" />
<script type="module">
// TODO use the url where the matrixrtc-sdk.js file from dist is hosted
import { createMatrixRTCSdk } from "http://localhost:8123/matrixrtc-sdk.js";
try {
console.log("Hello from index.html");
try {
window.matrixRTCSdk = await createMatrixRTCSdk();
console.info("createMatrixRTCSdk was created!");
} catch (e) {
console.error("createMatrixRTCSdk", e);
}
// const sdk = window.matrixRTCSdk;
console.info("matrixRTCSdk join ", window.matrixRTCSdk);
await window.matrixRTCSdk.join();
console.info("matrixRTCSdk joined ");
const div = document.getElementById("data");
div.innerHTML = "<h3>Data:</h3>";
window.matrixRTCSdk.data$.subscribe((data) => {
const child = document.createElement("p");
child.innerHTML = JSON.stringify(data);
div.appendChild(child);
// TODO forward to godot
});
window.matrixRTCSdk.members$.subscribe((memberObjects) => {
console.info("members changed", memberObjects);
// reset div
const div = document.getElementById("members");
div.innerHTML = "<h3>Members:</h3>";
// create member list
const members = memberObjects.map((member) => member.userId);
console.info("members changed", members);
for (const m of members) {
console.info("member", m);
const child = document.createElement("p");
child.innerHTML = m;
div.appendChild(child);
}
// TODO forward to godot
});
// TODO use it as godot HTML template
// var engine = new Engine($GODOT_CONFIG);
// engine.startGame();
} catch (e) {
console.error("catchALL,", e);
}
</script>
<!--// TODO use it as godot HTML template-->
<!--<script src="$GODOT_URL"></script>-->
</head>
<body>
<button onclick="window.matrixRTCSdk.leave();">Leave</button>
<button onclick="window.matrixRTCSdk.sendData({prop: 'Hello, world!'});">
Send Text
</button>
<div id="members"></div>
<div id="data"></div>
<canvas id="canvas"></canvas>
</body>
</html>