added force end transmition for dispatchers
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
import { Router } from "express";
|
||||
import { AccessToken } from "livekit-server-sdk";
|
||||
|
||||
if (!process.env.LIVEKIT_API_KEY) throw new Error("LIVEKIT_API_KEY not set");
|
||||
if (!process.env.LIVEKIT_API_SECRET) throw new Error("LIVEKIT_API_SECRET not set");
|
||||
|
||||
const createToken = async (roomName: string) => {
|
||||
// If this room doesn't exist, it'll be automatically created when the first
|
||||
// participant joins
|
||||
// Identifier to be used for participant.
|
||||
// It's available as LocalParticipant.identity with livekit-client SDK
|
||||
// TODO: Move function to dispatch nextjs app as API route to use authentication of nextAuth
|
||||
const participantName = "quickstart-username" + Math.random().toString(36).substring(7);
|
||||
|
||||
const at = new AccessToken(process.env.LIVEKIT_API_KEY, process.env.LIVEKIT_API_SECRET, {
|
||||
identity: participantName,
|
||||
// Token to expire after 10 minutes
|
||||
ttl: "10m",
|
||||
});
|
||||
at.addGrant({ roomJoin: true, room: roomName });
|
||||
|
||||
return await at.toJwt();
|
||||
};
|
||||
|
||||
const router: Router = Router();
|
||||
|
||||
router.get("/token", async (req, res) => {
|
||||
const roomName = req.query.roomName as string;
|
||||
res.send({
|
||||
token: await createToken(roomName),
|
||||
});
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Router } from "express";
|
||||
import livekitRouter from "./livekit";
|
||||
import dispatcherRotuer from "./dispatcher";
|
||||
import missionRouter from "./mission";
|
||||
import statusRouter from "./status";
|
||||
@@ -8,7 +7,6 @@ import reportRouter from "./report";
|
||||
|
||||
const router: Router = Router();
|
||||
|
||||
router.use("/livekit", livekitRouter);
|
||||
router.use("/dispatcher", dispatcherRotuer);
|
||||
router.use("/mission", missionRouter);
|
||||
router.use("/status", statusRouter);
|
||||
|
||||
@@ -62,6 +62,7 @@ export const handleConnectDispatch =
|
||||
esimatedLogoutTime: parsedLogoffDate?.toISOString() || null,
|
||||
lastHeartbeat: new Date().toISOString(),
|
||||
userId: user.id,
|
||||
zone: selectedZone,
|
||||
loginTime: new Date().toISOString(),
|
||||
},
|
||||
});
|
||||
@@ -72,20 +73,29 @@ export const handleConnectDispatch =
|
||||
io.to("dispatchers").emit("dispatchers-update");
|
||||
io.to("pilots").emit("dispatchers-update");
|
||||
|
||||
// dispatch-events
|
||||
socket.on("ptt", async ({ shouldTransmit, channel }) => {
|
||||
if (shouldTransmit) {
|
||||
io.to("dispatchers").emit("other-ptt", {
|
||||
publicUser: getPublicUser(user),
|
||||
channel,
|
||||
source: "Leitstelle",
|
||||
socket.on("stop-other-transmition", async ({ ownRole, otherRole }) => {
|
||||
const aircrafts = await prisma.connectedAircraft.findMany({
|
||||
where: {
|
||||
Station: {
|
||||
bosCallsignShort: otherRole,
|
||||
},
|
||||
logoutTime: null,
|
||||
},
|
||||
include: {
|
||||
Station: true,
|
||||
},
|
||||
});
|
||||
const dispatchers = await prisma.connectedDispatcher.findMany({
|
||||
where: {
|
||||
zone: otherRole,
|
||||
logoutTime: null,
|
||||
},
|
||||
});
|
||||
[...aircrafts, ...dispatchers].forEach((entry) => {
|
||||
io.to(`user:${entry.userId}`).emit("force-end-transmission", {
|
||||
by: ownRole,
|
||||
});
|
||||
io.to("piots").emit("other-ptt", {
|
||||
publicUser: getPublicUser(user),
|
||||
channel,
|
||||
source: "Leitstelle",
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
socket.on("disconnect", async () => {
|
||||
|
||||
Reference in New Issue
Block a user