Skip to content

v2.3.3 #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spacesvr",
"version": "2.3.2",
"version": "2.3.3",
"private": true,
"description": "A standardized reality for future of the 3D Web",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/layers/Environment/ui/PauseMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function PauseMenu(props: PauseMenuProps) {
const PAUSE_ITEMS: PauseItem[] = [
...pauseMenuItems,
{
text: "v2.3.2",
text: "v2.3.3",
link: "https://www.npmjs.com/package/spacesvr",
},
...menuItems,
Expand Down
1 change: 0 additions & 1 deletion src/layers/Network/ideas/NetworkedEntities/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { useNetwork } from "../../logic/network";
import { useLimitedFrame } from "../../../../logic/limiter";
import { SnapshotInterpolation } from "@geckos.io/snapshot-interpolation";
import {
Snapshot,
Entity as EntityState,
Quat,
} from "@geckos.io/snapshot-interpolation/lib/types";
Expand Down
5 changes: 3 additions & 2 deletions src/layers/Network/ideas/NetworkedEntities/logic/entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo, useRef, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import { useLimitedFrame } from "../../../../../logic/limiter";
import { useNetwork } from "../../../logic/network";
import { PositionalAudio } from "three";
Expand Down Expand Up @@ -26,7 +26,7 @@ export const useEntities = (): Entity[] => {
const needsAudio = (e: Entity) => mediaConnections.has(e.id) && !e.posAudio;

// check for a change in player list, re-render if there is a change
useLimitedFrame(5, () => {
useLimitedFrame(3, () => {
if (!connected) return;

// changed flag to trigger re-render at the end
Expand Down Expand Up @@ -68,6 +68,7 @@ export const useEntities = (): Entity[] => {
const mediaConn = mediaConnections.get(e.id);
if (!mediaConn) return;
if (!mediaConn.remoteStream) return;
console.log("adding audio for", e.id);

const audioElem = document.createElement("audio");
audioElem.srcObject = mediaConn.remoteStream; // remote is incoming, local is own voice
Expand Down
25 changes: 13 additions & 12 deletions src/layers/Network/logic/mic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ export const useMicrophone = (enabled = true): MediaStream | undefined => {

setAttempted(true);

navigator.getUserMedia =
navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia;

navigator.getUserMedia(
{ audio: true },
(str) => setLocalStream(str),
(err) => {
navigator.mediaDevices
.getUserMedia({
audio: {
echoCancellation: true,
noiseSuppression: true,
autoGainControl: true,
},
})
.then((stream) => {
setLocalStream(stream);
})
.catch((err) => {
console.error(err);
}
);
});
}, [attempted, enabled, firstPaused]);

return localStream;
Expand Down
45 changes: 17 additions & 28 deletions src/layers/Network/logic/voice.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import { DataConnection, Peer, MediaConnection } from "peerjs";
import { useEffect, useMemo, useState } from "react";
import { useEffect, useMemo } from "react";
import { useMicrophone } from "./mic";
import { useEnvironment } from "../../Environment";

type GetUserMedia = (
options: { video?: boolean; audio?: boolean },
success: (stream: any) => void,
error?: (error: string) => void
) => void;

declare global {
interface Navigator {
getUserMedia: GetUserMedia;
webkitGetUserMedia?: GetUserMedia;
mozGetUserMedia?: GetUserMedia;
msGetUserMedia?: GetUserMedia;
}
}

/**
* When enabled, is responsible for requesting mic permissions, calling and answering peers to create media connections,
Expand All @@ -37,16 +21,8 @@ export const useVoiceConnections = (

// handle calling and answering peers
useEffect(() => {
if (!peer || !localStream) return;

const call = (conn: DataConnection) => {
console.log("calling peer with id", conn.peer);
handleMediaConn(peer.call(conn.peer, localStream));
conn.on("close", () => {
console.log("closing voice stream with peer", conn.peer);
mediaConns.delete(conn.peer);
});
};
if (!peer || !localStream || !enabled) return;
console.log("running voice connection effect");

// handle a new media connection (incoming or created
const handleMediaConn = (mediaConn: MediaConnection) => {
Expand All @@ -65,9 +41,22 @@ export const useVoiceConnections = (
});
};

const call = (conn: DataConnection) => {
console.log("calling peer with id", conn.peer);
handleMediaConn(peer.call(conn.peer, localStream));
conn.on("close", () => {
console.log("closing voice stream with peer", conn.peer);
mediaConns.delete(conn.peer);
});
};

const handleDataConn = (conn: DataConnection) => {
conn.on("open", () => call(conn));
};

// set up incoming and outgoing calls for any future connections
peer.on("call", handleMediaConn);
peer.on("connection", call);
peer.on("connection", handleDataConn);

// call any already connected peers
for (const [peerId, conn] of connections) {
Expand Down