Skip to content

Commit

Permalink
change to protobuf-ts
Browse files Browse the repository at this point in the history
  • Loading branch information
KW-M committed Oct 1, 2024
1 parent d69e61a commit b7bd971
Show file tree
Hide file tree
Showing 38 changed files with 5,019 additions and 19,825 deletions.
70 changes: 0 additions & 70 deletions frontend/pack,kjaged.json

This file was deleted.

11 changes: 5 additions & 6 deletions frontend/src/components/3dScene/rovViz.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@
rovHeading.set(rovHeading.get() + 0.001);
const drivingVector = rovDrivingVector.get();
const moveZ = drivingVector.VelocityX * rovSpeed;
const moveX = -1 * drivingVector.VelocityY * rovSpeed;
const moveY = drivingVector.VelocityZ * rovSpeed;
const moveZ = drivingVector.velocityX * rovSpeed;
const moveX = -1 * drivingVector.velocityY * rovSpeed;
const moveY = drivingVector.velocityZ * rovSpeed;
rovModel.translateX(moveX);
rovModel.translateY(moveY);
rovModel.translateZ(moveZ);
const moveYaw = -drivingVector.AngularVelocityYaw * rovTurnSpeed;
const moveYaw = -drivingVector.angularVelocityYaw * rovTurnSpeed;
propellerL.rotation.z += moveZ * 0.15 - moveYaw * 8;
propellerR.rotation.z += moveZ * 0.15 + moveYaw * 8;
Expand All @@ -198,8 +198,7 @@
headLight.intensity = 500 * Math.max(-moveY, 0);
// console.log(drivingVector.ButtonBitmask);
if (drivingVector.ButtonBitmask !== 0) {
if (drivingVector.buttonBitmask !== 0) {
const _cameraOffset = new Vector3(0, 20, 50);
cameraOffsetLength = _cameraOffset.length();
cameraOffsetNorm = _cameraOffset.normalize();
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/DropdownMenuPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
export const changeSelected = (delta: number) => {
if (!open) {
popupCombobox.forceOpen = true;
console.log("changeSelectedOpening", delta, open);
openButton.click();
}
(document.activeElement as HTMLElement).blur ? (document.activeElement as HTMLElement).blur() : null;
Expand Down
33 changes: 17 additions & 16 deletions frontend/src/components/Modals/LogTimeline.svelte
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<script lang="ts">
import { onMount } from "svelte";
import { log, logDebug, logError, logInfo, LogLevelConsole, LogOrigin, logWarn, mainLogr } from "../../js/shared/logging";
import { log, logDebug, logError, logInfo, LogLevel, LogOrigin, logWarn, mainLogr } from "../../js/shared/logging";
import { getModalStore } from "@skeletonlabs/skeleton";
import { Close as CloseIcon, Save_alt as DownloadIcon, Restore as RefreshIcon } from "svelte-google-materialdesign-icons";
import { fade } from "svelte/transition";
import { frontendConnMngr } from "../../js/frontendConnManager";
import { rov_actions_proto } from "../../js/shared/protobufs/rovActionsProto";
import { type RovAction } from "../../js/shared/protobufs/rov_actions";
// export let parent;
const modalStore = getModalStore();
let logs = mainLogr.getLogs();
const fetchRovLogs = async () => {
const msg = rov_actions_proto.RovAction.create({
SendRovLogs: {},
const response = await frontendConnMngr.sendMessageToRov({
body: {
oneofKind: "sendRovLogs",
sendRovLogs: {},
},
});
const response = await frontendConnMngr.sendMessageToRov(msg);
logDebug("fetchRovLogs Response=", response);
};
Expand All @@ -30,7 +32,6 @@
};
onMount(() => {
console.log("Log Timeline Open");
mainLogr.subscribe(() => {
logs = mainLogr.getLogs();
});
Expand All @@ -49,16 +50,16 @@
class:border-l-8={log.origin === LogOrigin.PILOT}
class:!border-t-4={log.origin !== logs[Math.max(i - 1, 0)].origin}
class:border-r-8={log.origin === LogOrigin.ROV}
class:bg-sky-700={log.level === LogLevelConsole.Info}
class:bg-yellow-600={log.level === LogLevelConsole.Warn}
class:bg-red-700={log.level === LogLevelConsole.Error}
class:bg-green-700={log.level === LogLevelConsole.Debug}
class:bg-slate-800={log.level === LogLevelConsole.Console}
class:border-sky-600={log.level === LogLevelConsole.Info}
class:border-yellow-500={log.level === LogLevelConsole.Warn}
class:border-red-600={log.level === LogLevelConsole.Error}
class:border-green-600={log.level === LogLevelConsole.Debug}
class:border-purple-800={log.level === LogLevelConsole.Console}
class:bg-sky-700={log.level === LogLevel.Info}
class:bg-yellow-600={log.level === LogLevel.Warning}
class:bg-red-700={log.level === LogLevel.Error}
class:bg-green-700={log.level === LogLevel.Debug}
class:bg-slate-800={log.level === LogLevel.Console}
class:border-sky-600={log.level === LogLevel.Info}
class:border-yellow-500={log.level === LogLevel.Warning}
class:border-red-600={log.level === LogLevel.Error}
class:border-green-600={log.level === LogLevel.Debug}
class:border-purple-800={log.level === LogLevel.Console}
>
{#if body && body.length > 0}
<details>
Expand Down
77 changes: 44 additions & 33 deletions frontend/src/components/Modals/VideoSettings.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script context="module" lang="ts">
import nStore from "../../js/shared/libraries/nStore";
export const onLivekitVideoOptionsChange = (options: rov_actions_proto.ILivekitVideoStatsResponse) => {
export const onLivekitVideoOptionsChange = (options: LivekitVideoStatsResponse) => {
// if (lastChangeTimestamp + 1000 > unixTimeNow()) return;
// useLivekit.set(options.Enabled);
// if (options.Enabled) {
Expand All @@ -16,7 +16,7 @@
lkSenderVideoStats.set(options.stats);
};
export const onSimplePeerVideoOptionsChange = (options: rov_actions_proto.ISimplePeerVideoStatsResponse) => {
export const onSimplePeerVideoOptionsChange = (options: SimplePeerVideoStatsResponse) => {
// if (lastChangeTimestamp + 1000 > unixTimeNow()) return;
// const videoStream = frontendConnMngr.simplePeerConnection.remoteVideoStreams.get().values().next().value;
// const enabled = videoStream && videoStream.getTracks().length > 0 && videoStream.getTracks()[0].enabled;
Expand Down Expand Up @@ -52,7 +52,6 @@
import { onDestroy, onMount } from "svelte";
import { Close } from "svelte-google-materialdesign-icons";
import { frontendConnMngr } from "../../js/frontendConnManager";
import { rov_actions_proto } from "../../js/shared/protobufs/rovActionsProto";
import { waitfor } from "../../js/shared/util";
import { ConnectionStates } from "../../js/shared/consts";
import { displayHumanBits, displayNum } from "../../js/util";
Expand All @@ -62,6 +61,7 @@
import { logDebug } from "../../js/shared/logging";
import { unixTimeNow } from "../../js/shared/time";
import { browser } from "$app/environment";
import type { LivekitVideoStatsResponse, RovAction, SimplePeerVideoStatsResponse, VideoStreamOptions } from "../../js/shared/protobufs/rov_actions";
const LK_STATS_ACCORDION_ID = "lk_stats_accordion";
const SP_STATS_ACCORDION_ID = "sp_stats_accordion";
Expand Down Expand Up @@ -139,12 +139,15 @@
const sendTwitchLivestreamChange = () => {
logCurrentState("Sending twitch video change. current state:");
frontendConnMngr.sendMessageToRov(
rov_actions_proto.RovAction.create({
SetLivestreamingEnabled: {
Enabled: useTwitch.get(),
{
body: {
oneofKind: "setLivestreamingEnabled",
setLivestreamingEnabled: {
enabled: useTwitch.get(),
},
},
}),
false
},
true
);
};
Expand All @@ -153,23 +156,27 @@
lastChangeTimestamp = unixTimeNow();
logCurrentState("Sending lk video change. current state:");
const baseStream: rov_actions_proto.IVideoStreamOptions = {
MaxBitrate: maxBitrate.get(),
Height: size.get(),
Fps: 60,
Width: 0,
const baseStream: VideoStreamOptions = {
maxBitrate: maxBitrate.get(),
height: size.get(),
width: 0,
fps: 60,
};
frontendConnMngr.sendMessageToRov(
rov_actions_proto.RovAction.create({
SetLivekitVideoOptions: {
Enabled: useLivekit.get(),
AllowBackupCodec: allowBkupCodec.get(),
Codec: codec.get(),
BaseStream: keepFullResLayer.get() ? undefined : baseStream,
SimulcastLayers: keepFullResLayer.get() ? [baseStream] : undefined,
{
body: {
oneofKind: "setLivekitVideoOptions",
setLivekitVideoOptions: {
enabled: useLivekit.get(),
allowBackupCodec: allowBkupCodec.get(),
codec: codec.get(),
baseStream: keepFullResLayer.get() ? undefined : baseStream,
simulcastLayers: keepFullResLayer.get() ? [baseStream] : [],
},
},
}),
false
},
true
);
};
Expand All @@ -181,18 +188,23 @@
const mimeType = `video/${codec.get().toLowerCase()}`;
frontendConnMngr.setSimplePeerCodec(mimeType);
frontendConnMngr.sendMessageToRov(
rov_actions_proto.RovAction.create({
SetSimplePeerVideoOptions: {
Enabled: useSimplePeer.get(),
Codec: codec.get().toUpperCase(),
BaseStream: {
Height: size.get(),
Width: size.get() * (16 / 9),
Fps: 60,
{
body: {
oneofKind: "setSimplePeerVideoOptions",
setSimplePeerVideoOptions: {
enabled: useSimplePeer.get(),
codec: codec.get().toUpperCase(),
bitrate: maxBitrate.get(),
baseStream: {
maxBitrate: maxBitrate.get(),
height: size.get(),
width: size.get() * (16 / 9),
fps: 60,
},
},
},
}),
false
},
true
);
};
Expand Down Expand Up @@ -260,7 +272,6 @@
for (const [_, stream] of streams) {
for (const track of stream.getTracks()) {
track.enabled = true;
console.log(track);
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/components/VideoPlayer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
} else {
logInfo("VideoPlayer: Starting livekit video stream", livekitVideoStream.stream);
if (livekitVideoStream.stream) (livekitVideoStream.stream as RemoteTrack).start();
if (livekitVideoStream.stream == null) {
showToastMessage("Waiting for livekit video stream...", 1000, false, ToastSeverity.info);
}
}
if (videoIsReady(simplePeerVideoStream)) {
currentVideoSource.set(VideoSource.SimplePeer);
Expand Down Expand Up @@ -116,7 +113,7 @@
updateVideoVisibility();
});
spUnsub = frontendConnMngr.simplePeerConnection.remoteVideoStreams.subscribe((streams) => {
console.log("spstreams", streams);
logDebug("spstreams", streams);
const stream = streams.values().next().value as MediaStream | null;
if (stream) {
if (simplePeerVideoStream.streamId == stream.id) logWarn("VideoPlayer: SP: repeat stream ID!", stream.id);
Expand Down
19 changes: 14 additions & 5 deletions frontend/src/js/frontendConnManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ConnectionStates, LIVEKIT_FRONTEND_ROOM_CONFIG, LIVEKIT_FRONTEND_ROOM_C
import { default as nStore, type nStoreT } from "./shared/libraries/nStore";
import { listLivekitRoomsWithoutSDK, getAuthTokenFromLivekitRoomMetadata, type AuthTokenInfo } from "./shared/livekit/adminlessActions";
import { LivekitViewerConnection } from "./livekitViewerConn";
import { rov_actions_proto } from "./shared/protobufs/rovActionsProto";
import { SimplePeerConnection } from "./shared/simplePeer";
import { changesSubscribe, oneShotSubscribe, waitfor } from "./shared/util";
import { showToastMessage, ToastSeverity } from "./toastMessageManager";
Expand All @@ -11,6 +10,7 @@ import { frontendRovMsgHandler } from "./rovMessageHandler";
import { log, logDebug, logInfo, logWarn, logError } from "../js/shared/logging"
import { type Room } from "livekit-server-sdk";
import { type ComputedRtpStats } from "./shared/videoStatsParser";
import { RovAction } from "./shared/protobufs/rov_actions";

export interface LivekitRoomInfo {
name: string;
Expand Down Expand Up @@ -52,7 +52,14 @@ export class FrontendConnectionManager {
frontendRovMsgHandler.handleRecivedMessage(msg)
})
this._cleanupFuncs['outSignal'] = changesSubscribe(this.simplePeerConnection.outgoingSignalingMessages, (msg) => {
this.sendMessageToRov({ SimplePeerSignal: { Message: msg } }, true)
this.sendMessageToRov({
body: {
oneofKind: "simplePeerSignal",
simplePeerSignal: {
message: msg
}
}
}, true)
})
this.startVideoStatsCollection();
}
Expand Down Expand Up @@ -214,9 +221,10 @@ export class FrontendConnectionManager {
* @param msg - the message to send to the rov
* @param reliable - whether or not to use tcp and force the livekit connection.
*/
public async sendMessageToRov(msg: rov_actions_proto.IRovAction, reliable: boolean = true) {
public async sendMessageToRov(msg: RovAction, reliable: boolean = true) {
if (!this.livekitConnection) throw new Error("sendMessageToRov() called before livekitConnection was initilized")
const msgBytes = rov_actions_proto.RovAction.encode(msg).finish();
// const msgBytes = rov_actions_proto.RovAction.encode(msg).finish();
const msgBytes = RovAction.toBinary(msg)
const rovUserId = this.livekitConnection._rovRoomName;
if (URL_PARAMS.DEBUG_MODE) logDebug("Sending Message to ", rovUserId, reliable ? "reliably" : "unreliably", ":", msg);
if (reliable && this.livekitConnection.connectionState.get() === ConnectionStates.connected) {
Expand All @@ -228,7 +236,8 @@ export class FrontendConnectionManager {
}
}

public async close() {
public close() {
this.connectionState.set(ConnectionStates.disconnectedOk);
if (this.livekitConnection) this.livekitConnection.close();
if (this.simplePeerConnection) this.simplePeerConnection.stop();
if (this._videoStatsIntervalId) clearInterval(this._videoStatsIntervalId);
Expand Down
Loading

0 comments on commit b7bd971

Please sign in to comment.