1.0.2 • Published 4 months ago

misty2-js v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Quick start

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="style.css">
    <title>Misty 2</title>
  </head>
  <body>
    <canvas id="camera"></canvas>
    <script type="module" src="/main.js"></script>
  </body>
</html>

main.js

import { Misty2Robot, drawMessage} from "misty2-js";

const camera = document.getElementById("camera");
const ipAddress = prompt("What is Misty's IP address?");
const robot = new Misty2Robot(ipAddress);

robot.restart();
setTimeout(() => {
    robot.getVideoStream().then((ws) => {
        ws.onmessage = (evt) => {
            drawMessage(camera, evt);
        };
        ws.onclose = () => {
            console.log("Video stream closed.");
        };
    }).catch((error) => {
        console.error("Failed to start video stream:", error);
    });
}, 50*1000);


let currentGamepad;
window.addEventListener("gamepadconnected", (event) => {
    currentGamepad = event.gamepad;
    (function loop() {
        let gamepadList = navigator.getGamepads();
        if (gamepadList[currentGamepad.index]) {
            robot.update(gamepadList[currentGamepad.index]);
        }
        requestAnimationFrame(loop);
    })();
})
1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

7 months ago