Skip to content

Commit

Permalink
WIP rewrite for MDNS advertisements
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphiiko committed Mar 23, 2024
1 parent 0fc6520 commit 9519014
Show file tree
Hide file tree
Showing 25 changed files with 1,260 additions and 89 deletions.
16 changes: 16 additions & 0 deletions mdns-sidecar.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mdns-sidecar", "src-mdns-sidecar\mdns-sidecar.csproj", "{1CD17B94-1DA0-43E2-A88A-948494EF2291}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1CD17B94-1DA0-43E2-A88A-948494EF2291}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1CD17B94-1DA0-43E2-A88A-948494EF2291}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1CD17B94-1DA0-43E2-A88A-948494EF2291}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1CD17B94-1DA0-43E2-A88A-948494EF2291}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
"build:pre": "node scripts/pre-build.js && run-p build:front build:sidecars",
"build:front": "ng build",
"build:sidecars": "npm run build:sidecar",
"build:sidecar": "run-p build:sidecar:elevated build:sidecar:overlay",
"build:sidecar": "run-p build:sidecar:elevated build:sidecar:overlay build:sidecar:mdns",
"build:sidecar:elevated": "run-s build:sidecar:elevated:core build:sidecar:elevated:post",
"build:sidecar:elevated:core": "cd src-elevated-sidecar && cargo build --release && cd ..",
"build:sidecar:elevated:post": "node scripts/elevated-sidecar-post-build.js",
"build:sidecar:mdns": "run-s build:sidecar:mdns:core build:sidecar:mdns:post",
"build:sidecar:mdns:core": "cd src-mdns-sidecar && dotnet publish -r win-x64 -c Release && cd ..",
"build:sidecar:mdns:post": "node scripts/mdns-sidecar-post-build.js",
"build:sidecar:overlay": "rimraf src-core/resources/overlay-sidecar && run-p build:sidecar:overlay:ui build:sidecar:overlay:core && run-s build:sidecar:overlay:post",
"build:sidecar:overlay:ui": "cd src-overlay-ui && npm run build && cd ..",
"build:sidecar:overlay:core": "cd src-overlay-sidecar && dotnet publish -r win-x64 -c Release && cd ..",
Expand Down
12 changes: 12 additions & 0 deletions proto/oyasumi-core.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ package OyasumiCore;
service OyasumiCore {
rpc OnOverlaySidecarStart (OverlaySidecarStartArgs) returns (Empty) {}
rpc OnElevatedSidecarStart (ElevatedSidecarStartArgs) returns (Empty) {}
rpc OnMDNSSidecarStart (MDNSSidecarStartArgs) returns (Empty) {}
rpc SendEvent (EventParams) returns (Empty) {}
rpc GetHTTPServerPort (Empty) returns (HTTPServerPort) {}
rpc AddNotification (AddNotificationRequest) returns (AddNotificationResponse) {}
rpc SetVRChatOSCAddress (SetAddressRequest) returns (Empty) {}
rpc SetVRChatOSCQueryAddress (SetAddressRequest) returns (Empty) {}
}

message HTTPServerPort {
Expand All @@ -30,6 +33,10 @@ message ElevatedSidecarStartArgs {
optional uint32 old_pid = 4;
}

message MDNSSidecarStartArgs {
uint32 pid = 1;
}

message EventParams {
string event_name = 1;
oneof event_data {
Expand All @@ -50,4 +57,9 @@ message AddNotificationResponse {
optional string notification_id = 1;
}

message SetAddressRequest {
string host = 1;
uint32 port = 2;
}

message Empty {}
15 changes: 15 additions & 0 deletions scripts/mdns-sidecar-post-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { mkdirp } from 'mkdirp';
import copy from 'recursive-copy';
import { rimraf } from 'rimraf';

async function main() {
const coreSourceDirectory = 'src-mdns-sidecar/bin/Release/net8.0/win-x64/publish';
const coreTargetDirectory = 'src-core/resources/dotnet-sidecars';
await rimraf(coreTargetDirectory);
await mkdirp(coreTargetDirectory);
await copy(coreSourceDirectory, coreTargetDirectory, { overwrite: true });
}

main().catch((e) => {
throw e;
});
4 changes: 2 additions & 2 deletions scripts/overlay-sidecar-post-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { rimraf } from 'rimraf';

async function main() {
const coreSourceDirectory = 'src-overlay-sidecar/bin/Release/net8.0/win-x64/publish';
const coreTargetDirectory = 'src-core/resources/overlay-sidecar';
const coreTargetDirectory = 'src-core/resources/dotnet-sidecars';
await rimraf(coreTargetDirectory);
await mkdirp(coreTargetDirectory);
await copy(coreSourceDirectory, coreTargetDirectory, { overwrite: true });
const webSourceDirectory = 'src-overlay-ui/build';
const webTargetDirectory = 'src-core/resources/overlay-sidecar/ui';
const webTargetDirectory = 'src-core/resources/dotnet-sidecars/ui';
await rimraf(webTargetDirectory);
await mkdirp(webTargetDirectory);
await copy(webSourceDirectory, webTargetDirectory, { overwrite: true });
Expand Down
2 changes: 1 addition & 1 deletion src-core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ steamlocate = "1.2.1"

[dependencies.oyasumivr_oscquery]
git = "https://github.com/Raphiiko/oyasumivr_oscquery.git"
rev = "2599fba"
rev = "2949a3f"
# path = "../../oyasumivr-oscquery"

[dependencies.tauri]
Expand Down
1 change: 0 additions & 1 deletion src-core/flags.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
DISABLE_MDNS = false
ENABLE_PROFILING = false
2 changes: 1 addition & 1 deletion src-core/resources/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Resources that are built
elevated-sidecar/
overlay-sidecar/
dotnet-sidecars/
fonts/
33 changes: 27 additions & 6 deletions src-core/src/grpc/server.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use crate::Models::oyasumi_core::{
AddNotificationRequest, AddNotificationResponse, HttpServerPort,
};

use super::models::oyasumi_core::{
event_params::EventData, oyasumi_core_server::OyasumiCore, ElevatedSidecarStartArgs, Empty,
EventParams, OverlaySidecarStartArgs,
event_params::EventData, oyasumi_core_server::OyasumiCore, AddNotificationRequest,
AddNotificationResponse, ElevatedSidecarStartArgs, Empty, EventParams, HttpServerPort,
MdnsSidecarStartArgs, OverlaySidecarStartArgs, SetAddressRequest,
};
use log::error;
use tonic::{Request, Response, Status};
Expand Down Expand Up @@ -40,6 +37,30 @@ impl OyasumiCore for OyasumiCoreServerImpl {
}
}

async fn on_mdns_sidecar_start(
&self,
request: Request<MdnsSidecarStartArgs>,
) -> Result<Response<Empty>, Status> {
// TODO
Ok(Response::new(Empty {}))
}

async fn set_vr_chat_osc_address(
&self,
request: Request<SetAddressRequest>,
) -> Result<Response<Empty>, Status> {
// TODO
Ok(Response::new(Empty {}))
}

async fn set_vr_chat_osc_query_address(
&self,
request: Request<SetAddressRequest>,
) -> Result<Response<Empty>, Status> {
// TODO
Ok(Response::new(Empty {}))
}

async fn send_event(&self, request: Request<EventParams>) -> Result<Response<Empty>, Status> {
let request = request.get_ref();

Expand Down
31 changes: 17 additions & 14 deletions src-core/src/osc/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,24 @@ pub async fn start_osc_server() -> Option<(String, Option<String>)> {
let cancellation_token = super::spawn_receiver_task().await;
*CANCELLATION_TOKEN.lock().await = Some(cancellation_token);
// Start the OSCQuery server
let mut osc_query_addr_string = None;
if !crate::globals::is_flag_set("DISABLE_MDNS").await {
osc_query_addr_string =
match oyasumivr_oscquery::server::init("OyasumiVR", "127.0.0.1", osc_addr_port).await {
Ok(result) => Some(format!("{}:{}", result.0, result.1)),
Err(err) => {
error!("[Core] Could not initialize OSCQuery server: {:#?}", err);
None
}
};
oyasumivr_oscquery::server::receive_vrchat_avatar_parameters().await;
match oyasumivr_oscquery::server::advertise().await {
Err(err) => error!("[Core] Could not advertise OSCQuery server: {:#?}", err),
_ => {}
let osc_query_addr_string = match oyasumivr_oscquery::server::init(
"OyasumiVR",
"127.0.0.1",
osc_addr_port,
false,
)
.await
{
Ok(result) => Some(format!("{}:{}", result.0, result.1)),
Err(err) => {
error!("[Core] Could not initialize OSCQuery server: {:#?}", err);
None
}
};
oyasumivr_oscquery::server::receive_vrchat_avatar_parameters().await;
match oyasumivr_oscquery::server::advertise().await {
Err(err) => error!("[Core] Could not advertise OSCQuery server: {:#?}", err),
_ => {}
}
// Return bound address
Some((osc_addr_string, osc_query_addr_string))
Expand Down
116 changes: 57 additions & 59 deletions src-core/src/osc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,45 +36,43 @@ pub async fn init() {
}
};
// Start looking for VRChat's OSC and OSCQuery services
if !crate::globals::is_flag_set("DISABLE_MDNS").await {
match oyasumivr_oscquery::client::init().await {
Err(err) => error!("[Core] Could not initialize OSCQuery client: {:#?}", err),
_ => {}
};
tokio::task::spawn(async {
loop {
{
let address = get_vrchat_osc_address().await;
let mut vrc_osc_address_guard = VRC_OSC_ADDRESS.lock().await;
if !match (&address, vrc_osc_address_guard.as_ref()) {
(Some(str1), Some(str2)) => str1 == str2,
(None, None) => true,
_ => false,
} {
*vrc_osc_address_guard = address;
send_event("VRC_OSC_ADDRESS_CHANGED", vrc_osc_address_guard.clone()).await;
}
}
{
let address = get_vrchat_oscquery_address().await;
let mut vrc_oscquery_address_guard = VRC_OSCQUERY_ADDRESS.lock().await;
if !match (&address, vrc_oscquery_address_guard.as_ref()) {
(Some(str1), Some(str2)) => str1 == str2,
(None, None) => true,
_ => false,
} {
*vrc_oscquery_address_guard = address;
send_event(
"VRC_OSCQUERY_ADDRESS_CHANGED",
vrc_oscquery_address_guard.clone(),
)
.await;
}
}
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
}
});
}
// match oyasumivr_oscquery::client::init().await {
// Err(err) => error!("[Core] Could not initialize OSCQuery client: {:#?}", err),
// _ => {}
// };
// tokio::task::spawn(async {
// loop {
// {
// let address = get_vrchat_osc_address().await;
// let mut vrc_osc_address_guard = VRC_OSC_ADDRESS.lock().await;
// if !match (&address, vrc_osc_address_guard.as_ref()) {
// (Some(str1), Some(str2)) => str1 == str2,
// (None, None) => true,
// _ => false,
// } {
// *vrc_osc_address_guard = address;
// send_event("VRC_OSC_ADDRESS_CHANGED", vrc_osc_address_guard.clone()).await;
// }
// }
// {
// let address = get_vrchat_oscquery_address().await;
// let mut vrc_oscquery_address_guard = VRC_OSCQUERY_ADDRESS.lock().await;
// if !match (&address, vrc_oscquery_address_guard.as_ref()) {
// (Some(str1), Some(str2)) => str1 == str2,
// (None, None) => true,
// _ => false,
// } {
// *vrc_oscquery_address_guard = address;
// send_event(
// "VRC_OSCQUERY_ADDRESS_CHANGED",
// vrc_oscquery_address_guard.clone(),
// )
// .await;
// }
// }
// tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
// }
// });
}

async fn spawn_receiver_task() -> CancellationToken {
Expand Down Expand Up @@ -163,24 +161,24 @@ async fn spawn_receiver_task() -> CancellationToken {
cancellation_token
}

async fn get_vrchat_osc_address() -> Option<String> {
if crate::globals::is_flag_set("DISABLE_MDNS").await {
return None;
}
let addr = oyasumivr_oscquery::client::get_vrchat_osc_address().await;
match addr {
Some(addr) => Some(format!("{}:{}", addr.0, addr.1)),
None => None,
}
}
// async fn get_vrchat_osc_address() -> Option<String> {
// if crate::globals::is_flag_set("DISABLE_MDNS").await {
// return None;
// }
// let addr = oyasumivr_oscquery::client::get_vrchat_osc_address().await;
// match addr {
// Some(addr) => Some(format!("{}:{}", addr.0, addr.1)),
// None => None,
// }
// }

async fn get_vrchat_oscquery_address() -> Option<String> {
if crate::globals::is_flag_set("DISABLE_MDNS").await {
return None;
}
let addr = oyasumivr_oscquery::client::get_vrchat_oscquery_address().await;
match addr {
Some(addr) => Some(format!("{}:{}", addr.0, addr.1)),
None => None,
}
}
// async fn get_vrchat_oscquery_address() -> Option<String> {
// if crate::globals::is_flag_set("DISABLE_MDNS").await {
// return None;
// }
// let addr = oyasumivr_oscquery::client::get_vrchat_oscquery_address().await;
// match addr {
// Some(addr) => Some(format!("{}:{}", addr.0, addr.1)),
// None => None,
// }
// }
2 changes: 1 addition & 1 deletion src-core/src/overlay_sidecar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub async fn init() {
let (tx, mut rx) = tokio::sync::mpsc::channel(10);
*SIDECAR_MANAGER.lock().await = Some(SidecarManager::new(
"OVERLAY".to_string(),
"resources/overlay-sidecar/".to_string(),
"resources/dotnet-sidecars/".to_string(),
"overlay-sidecar.exe".to_string(),
tx,
true,
Expand Down
Loading

0 comments on commit 9519014

Please sign in to comment.