Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

statusの送信 10fps #30

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 51 additions & 22 deletions src/pages/shooter/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { type KeyboardEventHandler, useState } from "react";
import {
type KeyboardEventHandler,
useCallback,
useEffect,
useState,
} from "react";
import { DefaultButton } from "../../components/ui/Button";
import { Modal } from "../../components/ui/Modal";
import { ShooterButton } from "../../components/ui/ShooterButton";
Expand All @@ -21,6 +26,50 @@ const Shooter = () => {
const [images, setImages] = useState(initialImages);
const uuid = useUUIDStore((state) => state.uuid);

const sendData = useCallback(
(mes_type: message_type) => {
const data: Schema = {
id: uuid,
interval: 0,
angle: {
x: orientationDiff.beta,
y: orientationDiff.gamma,
},
acceleration: {
x: 0,
y: 0,
z: 0,
},
distance: {
x: 0,
y: 0,
z: 0,
},
message_type: mes_type,
event_type: event_type.shooter,
};
console.log(data);
socketRef?.current?.send(JSON.stringify(data));
},
[uuid, orientationDiff, socketRef],
);

useEffect(() => {
let intervalId: number | null = null;

if (!isOpen) {
intervalId = window.setInterval(() => {
sendData(message_type.status);
}, 100);
}

return () => {
if (intervalId !== null) {
clearInterval(intervalId);
}
};
}, [isOpen, sendData]);

const handleClick = () => {
const audio = new Audio("/sound/cork_sound.mp3");
audio
Expand All @@ -29,27 +78,7 @@ const Shooter = () => {
.catch((error) => {
console.error("オーディオの音が出なかった", error);
});
const data: Schema = {
id: uuid,
interval: 0,
angle: {
x: orientationDiff.beta,
y: orientationDiff.gamma,
},
acceleration: {
x: 0,
y: 0,
z: 0,
},
distance: {
x: 0,
y: 0,
z: 0,
},
message_type: message_type.action,
event_type: event_type.shooter,
};
socketRef?.current?.send(JSON.stringify(data));
sendData(message_type.action);
setImages((prevImages) => prevImages.slice(1));
};

Expand Down
2 changes: 1 addition & 1 deletion src/type/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface distance {
}

export enum message_type {
pointer = "pointer",
status = "status",
action = "action",
}

Expand Down
Loading