Skip to content

Commit

Permalink
Merge branch 'consume-output-of-balancer' of https://github.com/Victo…
Browse files Browse the repository at this point in the history
…r-M-Giraldo/opentogethertube into consume-output-of-balancer
  • Loading branch information
Victor committed Jan 13, 2024
2 parents 834a32d + f3937c8 commit 6f3064b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions client/src/components/UserList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export const UserList = defineComponent({
await API.post("/user", { username: inputUsername.value });
showEditName.value = false;
setUsernameFailureText.value = "";
roomapi.notify("usernameChanged");
} catch (err) {
setUsernameFailureText.value = err.response
? err.response.data.error.message
Expand Down
9 changes: 8 additions & 1 deletion client/src/util/roomapi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OttRoomConnection } from "@/plugins/connection";
import { RoomRequestType } from "ott-common/models/messages";
import { ClientMessageNotify, RoomRequestType } from "ott-common/models/messages";
import { ClientId, Role } from "ott-common/models/types";
import { VideoId } from "ott-common/models/video";

Expand Down Expand Up @@ -151,4 +151,11 @@ class RoomApi {
},
});
}

notify(message: ClientMessageNotify["message"]) {
this.connection.send({
action: "notify",
message,
});
}
}
11 changes: 11 additions & 0 deletions common/models/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export type ClientMessage =
| ClientMessageKickMe
| ClientMessagePlayerStatus
| ClientMessageAuthenticate
| ClientMessageNotify
| ClientMessageRoomRequest;

interface ClientMessageBase {
Expand All @@ -144,6 +145,16 @@ export interface ClientMessageAuthenticate extends ClientMessageBase {
token: AuthToken;
}

/**
* Used to notify the monolith of events that occur on the client that imply a change in state that needs to be propagated to other clients.
*
* Currently only used to notify the monolith of a username change.
*/
export interface ClientMessageNotify extends ClientMessageBase {
action: "notify";
message: "usernameChanged";
}

export interface ClientMessageRoomRequest extends ClientMessageBase {
action: "req";
request: RoomRequest;
Expand Down
10 changes: 7 additions & 3 deletions crates/ott-balancer/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,15 @@ impl Service<Request<IncomingBody>> for BalancerService {
warn!("no route found for {}", req.uri().path());
return Box::pin(async move { Ok(not_found()) });
};
tracing::Span::current().record("handler", route.handler());
info!("inbound request");
let handler = **route.handler();
tracing::Span::current().record("handler", handler);
match handler {
"status" | "health" | "metrics" => debug!("inbound request"),
_ => info!("inbound request"),
}

Box::pin(async move {
let res = match **route.handler() {
let res = match handler {
"health" => mk_response("OK".to_owned()),
"status" => {
let ctx_read = ctx.read().await;
Expand Down
7 changes: 7 additions & 0 deletions server/clientmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Request } from "express";
import { createSubscriber, redisClient } from "./redisclient";
import {
ClientMessage,
ClientMessageKickMe,
RoomRequest,
RoomRequestType,
ServerMessage,
Expand Down Expand Up @@ -151,6 +152,12 @@ async function onClientMessage(client: Client, msg: ClientMessage) {
await makeRoomRequest(client, request);
} else if (msg.action === "req") {
await makeRoomRequest(client, msg.request);
} else if (msg.action === "notify") {
if (msg.message === "usernameChanged") {
onUserModified(client.token!);
} else {
log.warn(`Unknown notify message: ${msg.message}`);
}
} else {
log.warn(`Unknown client message: ${(msg as { action: string }).action}`);
return;
Expand Down
4 changes: 3 additions & 1 deletion server/services/direct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ export default class DirectVideoAdapter extends ServiceAdapter {
}
const fileInfo = await this.ffprobe.getFileInfo(link);
const duration = Math.ceil(this.getDuration(fileInfo));
const title = fileInfo.format?.tags?.title ?? fileName;
const title =
fileInfo.format?.tags?.title ??
decodeURIComponent(fileName).slice(0, -extension.length - 1);
const video: Video = {
service: this.serviceId,
id: link,
Expand Down

0 comments on commit 6f3064b

Please sign in to comment.