Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
leanmendoza committed Nov 12, 2024
1 parent 811b9fa commit 9491c01
Show file tree
Hide file tree
Showing 36 changed files with 244 additions and 284 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.79
toolchain: 1.77.2
override: true
components: clippy, rustfmt
- name: Set up cache
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.79
toolchain: 1.77.2
override: true
components: llvm-tools-preview

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.79
toolchain: 1.77.2
override: true

- name: Set up cache
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.79
toolchain: 1.77.2
override: true

# Dependencies section
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.79
toolchain: 1.77.2
override: true
components: clippy, rustfmt
- run: rustup component add rustfmt
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.79
toolchain: 1.77.2
override: true

- name: Set up cache
Expand Down
16 changes: 10 additions & 6 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ publish = false
crate-type = ["cdylib"]

[dependencies]
godot = { version = "0.1.3", features=["experimental-threads", "serde"] }
godot = { git = "https://github.com/godot-rust/gdext", rev ="6a543ceb2d7957da5be198df10167e6f7c685460", features=["experimental-threads", "serde"] }
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0.92", features = ["raw_value"] }
Expand Down Expand Up @@ -41,8 +41,8 @@ tracing-subscriber = "0.3"
poll-promise = "0.2.0"
log-panics = { version = "2", features = ["with-backtrace"]}

v8 = { version = "0.105.1", default-features = false, optional = true }
deno_core = { git = "https://github.com/robtfm/deno_core", branch = "0_307_hotfix", optional = true }
v8 = { version = "0.74.3", optional = true }
deno_core = { version = "0.197", optional = true }
uuid = { version = "1.3.0", features = ["v4"] }
fastwebsockets = { version = "0.3.1", features = ["upgrade"], optional = true }
hyper1 = { package = "hyper", version = "0.14.26", features = ["server","runtime", "http1"], optional = true }
Expand All @@ -55,7 +55,7 @@ bytes = "1.4.0"
tokio-tungstenite = "0.20.1"
futures-util = "0.3.30"

livekit = { git = "https://github.com/robtfm/client-sdk-rust", branch="0.6-h264-false-2", features=["rustls-tls-webpki-roots"], optional = true }
livekit = { git = "https://github.com/livekit/rust-sdks", features=["rustls-tls-webpki-roots"], optional = true, rev="8b276f9d4b98437a139e1cbe41cfda1332ce1120" }

taffy = "0.5.2"
tracing-test = "0.2.4"
Expand Down Expand Up @@ -83,6 +83,10 @@ use_resource_tracking = []
enable_inspector = ["use_deno", "dep:fastwebsockets", "dep:hyper1"]

[build-dependencies]
webrtc-sys-build = { version = "0.3.5", optional = true }
webrtc-sys-build = { git = "https://github.com/livekit/rust-sdks", optional = true, rev="8b276f9d4b98437a139e1cbe41cfda1332ce1120" }
prost-build = "0.11.8"
chrono = "0.4.31"
chrono = "0.4.31"

[patch."https://github.com/godot-rust/godot4-prebuilt".godot4-prebuilt]
git = "https://github.com//godot-rust/godot4-prebuilt"
rev = "bc1e77856d181c14c59d2a5cb6a7e138ea5a2b39"
8 changes: 4 additions & 4 deletions lib/src/avatars/avatar_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ impl DclAvatarWireFormat {

for (i, emote) in DEFAULT_EMOTES.iter().enumerate() {
if let Some(emote) = used_emotes.iter().find(|e| e.slot == i as u32) {
emotes[i] = GString::from(emote.urn.as_str());
emotes.set(i, GString::from(emote.urn.as_str()));
} else {
emotes[i] = GString::from(*emote);
emotes.set(i, GString::from(*emote));
}
}
emotes
Expand Down Expand Up @@ -156,7 +156,7 @@ impl DclAvatarWireFormat {
fn set_wearables(&mut self, wearables: PackedStringArray) {
let mut wearables_vec = Vec::new();
for i in 0..wearables.len() {
wearables_vec.push(wearables.get(i).as_ref().unwrap().to_string());
wearables_vec.push(wearables.get(i).to_string());
}
self.inner.wearables = wearables_vec;
}
Expand All @@ -172,7 +172,7 @@ impl DclAvatarWireFormat {
for i in 0..10 {
emotes_vec.push(AvatarEmote {
slot: i as u32,
urn: emotes.get(i).as_ref().unwrap().to_string(),
urn: emotes.get(i).to_string(),
});
}
self.inner.emotes = Some(emotes_vec);
Expand Down
14 changes: 9 additions & 5 deletions lib/src/comms/adapter/livekit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use livekit::{
audio_source::native::NativeAudioSource,
prelude::{AudioSourceOptions, RtcAudioSource},
},
DataPacket, RoomOptions,
DataPacket, DataPacketKind, RoomOptions,
};
use prost::Message;

Expand Down Expand Up @@ -411,7 +411,7 @@ fn spawn_livekit_task(
echo_cancellation: true,
noise_suppression: true,
auto_gain_control: true,
}, 48000, 1, None);
}, 48000, 1);
let mic_track = LocalTrack::Audio(LocalAudioTrack::create_audio_track("mic", RtcAudioSource::Native(native_source.clone())));
room.local_participant().publish_track(mic_track, TrackPublishOptions{ source: TrackSource::Microphone, ..Default::default() }).await.unwrap();

Expand Down Expand Up @@ -473,7 +473,7 @@ fn spawn_livekit_task(
livekit::track::RemoteTrack::Audio(audio) => {
let sender = sender.clone();
rt2.spawn(async move {
let mut x = livekit::webrtc::audio_stream::native::NativeAudioStream::new(audio.rtc_track(), 48000, 1);
let mut x = livekit::webrtc::audio_stream::native::NativeAudioStream::new(audio.rtc_track());

tracing::debug!("remove track from {:?}", participant.identity().0.as_str());

Expand Down Expand Up @@ -519,8 +519,12 @@ fn spawn_livekit_task(
break 'stream;
};

let reliable = !outgoing.unreliable;
if let Err(e) = room.local_participant().publish_data(DataPacket { payload: outgoing.data, reliable, ..Default::default() }).await {
let kind = if outgoing.unreliable {
DataPacketKind::Lossy
} else {
DataPacketKind::Reliable
};
if let Err(e) = room.local_participant().publish_data(DataPacket { payload: outgoing.data, kind, ..Default::default() }).await {
tracing::debug!("outgoing failed: {e}; not exiting loop though since it often fails at least once or twice at the start...");
// break 'stream;
};
Expand Down
2 changes: 1 addition & 1 deletion lib/src/dcl/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct SceneEntityId {
pub version: u16,
}

impl GodotConvert for SceneEntityId {
impl godot::builtin::meta::GodotConvert for SceneEntityId {
type Via = i32;
}

Expand Down
9 changes: 4 additions & 5 deletions lib/src/dcl/js/adaptation_layer_helper.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::dcl::scene_apis::RpcCall;
use deno_core::{anyhow::anyhow, op2, OpDecl, OpState};
use deno_core::{anyhow::anyhow, op, Op, OpDecl, OpState};
use serde::Serialize;
use std::{cell::RefCell, rc::Rc};

// list of op declarations
pub fn ops() -> Vec<OpDecl> {
vec![op_get_texture_size()]
vec![op_get_texture_size::DECL]
}

#[derive(Serialize)]
Expand All @@ -14,9 +14,8 @@ struct TextureSize {
height: f32,
}

#[op2(async)]
#[serde]
async fn op_get_texture_size(state: Rc<RefCell<OpState>>, #[string] src: String) -> TextureSize {
#[op(v8)]
async fn op_get_texture_size(state: Rc<RefCell<OpState>>, src: String) -> TextureSize {
let (sx, rx) = tokio::sync::oneshot::channel::<Result<godot::builtin::Vector2, String>>();

state
Expand Down
13 changes: 6 additions & 7 deletions lib/src/dcl/js/comms.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{cell::RefCell, rc::Rc};

use deno_core::{op2, JsBuffer, OpDecl, OpState};
use deno_core::{op, JsBuffer, Op, OpDecl, OpState};
use ethers_core::types::H160;

use crate::dcl::scene_apis::RpcCall;
Expand All @@ -12,28 +12,27 @@ pub(crate) struct InternalPendingBinaryMessages {

// list of op declarations
pub fn ops() -> Vec<OpDecl> {
vec![op_comms_send_string(), op_comms_send_binary()]
vec![op_comms_send_string::DECL, op_comms_send_binary::DECL]
}

pub(crate) const COMMS_MSG_TYPE_STRING: u8 = 1;
pub(crate) const COMMS_MSG_TYPE_BINARY: u8 = 2;

#[op2(async)]
#[op]
async fn op_comms_send_string(
state: Rc<RefCell<OpState>>,
#[string] message: String,
message: String,
) -> Result<(), anyhow::Error> {
let mut message = message.into_bytes();
message.insert(0, COMMS_MSG_TYPE_STRING);
comms_send(state, vec![message]).await?;
Ok(())
}

#[op2(async)]
#[serde]
#[op]
async fn op_comms_send_binary(
state: Rc<RefCell<OpState>>,
#[serde] messages: Vec<JsBuffer>,
messages: Vec<JsBuffer>,
) -> Result<Vec<Vec<u8>>, anyhow::Error> {
let messages = messages
.iter()
Expand Down
25 changes: 12 additions & 13 deletions lib/src/dcl/js/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
sync::{Arc, Mutex},
};

use deno_core::{op2, OpDecl, OpState};
use deno_core::{op, Op, OpDecl, OpState};

use crate::dcl::{
common::{SceneDying, SceneElapsedTime, SceneLogs, SceneMainCrdtFileContent},
Expand All @@ -27,12 +27,15 @@ use super::{

// list of op declarations
pub fn ops() -> Vec<OpDecl> {
vec![op_crdt_send_to_renderer(), op_crdt_recv_from_renderer()]
vec![
op_crdt_send_to_renderer::DECL,
op_crdt_recv_from_renderer::DECL,
]
}

// receive and process a buffer of crdt messages
#[op2(fast)]
fn op_crdt_send_to_renderer(op_state: Rc<RefCell<OpState>>, #[arraybuffer] messages: &[u8]) {
#[op(v8)]
fn op_crdt_send_to_renderer(op_state: Rc<RefCell<OpState>>, messages: &[u8]) {
let dying = op_state.borrow().borrow::<SceneDying>().0;
if dying {
return;
Expand Down Expand Up @@ -76,20 +79,16 @@ fn op_crdt_send_to_renderer(op_state: Rc<RefCell<OpState>>, #[arraybuffer] messa
.expect("error sending scene response!!")
}

#[op2(async)]
#[serde]
async fn op_crdt_recv_from_renderer(
op_state: Rc<RefCell<OpState>>,
) -> Result<Vec<Vec<u8>>, anyhow::Error> {
#[op(v8)]
async fn op_crdt_recv_from_renderer(op_state: Rc<RefCell<OpState>>) -> Vec<Vec<u8>> {
let dying = op_state.borrow().borrow::<SceneDying>().0;
if dying {
return Ok(vec![]);
return vec![];
}

let mut receiver = op_state
.borrow_mut()
.try_take::<tokio::sync::mpsc::Receiver<RendererResponse>>()
.ok_or(anyhow::Error::msg("already borrowed"))?;
.take::<tokio::sync::mpsc::Receiver<RendererResponse>>();
let response = receiver.recv().await;

let mut op_state = op_state.borrow_mut();
Expand Down Expand Up @@ -183,7 +182,7 @@ async fn op_crdt_recv_from_renderer(
ret.push(main_crdt.0);
}
ret.push(data);
Ok(ret)
ret
}

fn process_local_api_calls(local_api_calls: Vec<LocalCall>, crdt_state: &SceneCrdtState) {
Expand Down
11 changes: 5 additions & 6 deletions lib/src/dcl/js/ethereum_controller.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use deno_core::{anyhow::anyhow, error::AnyError, op2, OpDecl, OpState};
use deno_core::{anyhow::anyhow, error::AnyError, op, Op, OpDecl, OpState};

use std::{cell::RefCell, rc::Rc, sync::Arc};

Expand All @@ -9,15 +9,14 @@ use crate::{

// list of op declarations
pub fn ops() -> Vec<OpDecl> {
vec![op_send_async()]
vec![op_send_async::DECL]
}

#[op2(async)]
#[serde]
#[op]
async fn op_send_async(
state: Rc<RefCell<OpState>>,
#[string] method: String,
#[string] params: String,
method: String,
params: String,
) -> Result<serde_json::Value, AnyError> {
let params: Vec<serde_json::Value> = serde_json::from_str(&params)?;

Expand Down
19 changes: 11 additions & 8 deletions lib/src/dcl/js/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::dcl::{
SceneCrdtStateProtoComponents,
},
};
use deno_core::{op2, OpDecl, OpState};
use deno_core::{op, Op, OpDecl, OpState};
use ethers_core::types::H160;
use serde::Serialize;
use std::{
Expand All @@ -18,7 +18,11 @@ use std::{
};

pub fn ops() -> Vec<OpDecl> {
vec![op_subscribe(), op_unsubscribe(), op_send_batch()]
vec![
op_subscribe::DECL,
op_unsubscribe::DECL,
op_send_batch::DECL,
]
}

#[derive(Serialize)]
Expand Down Expand Up @@ -151,8 +155,8 @@ struct EventSender<T: EventType> {
_p: PhantomData<fn() -> T>,
}

#[op2(fast)]
fn op_subscribe(state: &mut OpState, #[string] id: &str) {
#[op]
fn op_subscribe(state: &mut OpState, id: &str) {
macro_rules! register {
($id: expr, $state: expr, $marker: ty) => {{
if id == <$marker as EventType>::label() {
Expand Down Expand Up @@ -190,8 +194,8 @@ fn op_subscribe(state: &mut OpState, #[string] id: &str) {
tracing::warn!("subscribe to unrecognised event {id}");
}

#[op2(fast)]
fn op_unsubscribe(state: &mut OpState, #[string] id: &str) {
#[op]
fn op_unsubscribe(state: &mut OpState, id: &str) {
macro_rules! unregister {
($id: expr, $state: expr, $marker: ty) => {{
if id == <$marker as EventType>::label() {
Expand Down Expand Up @@ -229,8 +233,7 @@ struct EventGeneric {
event_data: String,
}

#[op2]
#[serde]
#[op]
fn op_send_batch(state: &mut OpState) -> Vec<Event> {
let mut results = Vec::default();

Expand Down
Loading

0 comments on commit 9491c01

Please sign in to comment.