Skip to content
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

Audio zone fixes #4278

Merged
merged 7 commits into from
Jun 3, 2021
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
9 changes: 6 additions & 3 deletions src/components/avatar-audio-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ function createWhiteNoise(audioContext, gain) {
return whiteNoise;
}

const tmpWorldPos = new THREE.Vector3();

/**
* @component zone-audio-source
* This component looks for audio sources that get near it, keeping track
Expand Down Expand Up @@ -220,8 +222,9 @@ AFRAME.registerComponent("zone-audio-source", {
},

tick() {
this.el.object3D.getWorldPosition(tmpWorldPos);
if (this.trackingEl) {
const distanceSquared = this.trackingEl.object3D.position.distanceToSquared(this.el.object3D.position);
const distanceSquared = this.trackingEl.object3D.position.distanceToSquared(tmpWorldPos);
if (distanceSquared > this.boundingRadiusSquared) {
this.trackingEl = null;
this.setInput(this.whiteNoise);
Expand All @@ -232,9 +235,9 @@ AFRAME.registerComponent("zone-audio-source", {
const playerInfo = playerInfos[i];
const avatar = playerInfo.el;

if (this.data.onlyMods && !playerInfo.isOwner) continue;
if (this.data.onlyMods && !playerInfo.can("amplify_audio")) continue;

const distanceSquared = avatar.object3D.position.distanceToSquared(this.el.object3D.position);
const distanceSquared = avatar.object3D.position.distanceToSquared(tmpWorldPos);
if (distanceSquared < this.boundingRadiusSquared) {
this.trackingEl = avatar;
if (this.data.muteSelf && this.trackingEl.id === "avatar-rig") {
Expand Down
10 changes: 7 additions & 3 deletions src/components/player-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ AFRAME.registerComponent("player-info", {
this.playerSessionId = NAF.utils.getCreator(networkedEntity);
const playerPresence = window.APP.hubChannel.presence.state[this.playerSessionId];
if (playerPresence) {
this.updateDisplayNameFromPresenceMeta(playerPresence.metas[0]);
this.updateFromPresenceMeta(playerPresence.metas[0]);
}
});
}
Expand Down Expand Up @@ -117,15 +117,19 @@ AFRAME.registerComponent("player-info", {
if (!this.playerSessionId) return;
if (this.playerSessionId !== e.detail.sessionId) return;

this.updateDisplayNameFromPresenceMeta(e.detail);
this.updateFromPresenceMeta(e.detail);
},
updateDisplayNameFromPresenceMeta(presenceMeta) {
updateFromPresenceMeta(presenceMeta) {
this.permissions = presenceMeta.permissions;
this.displayName = presenceMeta.profile.displayName;
this.identityName = presenceMeta.profile.identityName;
this.isRecording = !!(presenceMeta.streaming || presenceMeta.recording);
this.isOwner = !!(presenceMeta.roles && presenceMeta.roles.owner);
this.applyDisplayName();
},
can(perm) {
netpro2k marked this conversation as resolved.
Show resolved Hide resolved
return !!this.permissions && this.permissions[perm];
},
applyDisplayName() {
const store = window.APP.store;

Expand Down
15 changes: 11 additions & 4 deletions src/utils/hub-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ const HUB_CREATOR_PERMISSIONS = [
"update_roles",
"close_hub",
"mute_users",
"kick_users"
"kick_users",
"amplify_audio"
];
const VALID_PERMISSIONS =
HUB_CREATOR_PERMISSIONS +
["tweet", "spawn_camera", "spawn_drawing", "spawn_and_move_media", "pin_objects", "spawn_emoji", "fly"];
const VALID_PERMISSIONS = HUB_CREATOR_PERMISSIONS.concat([
"tweet",
"spawn_camera",
"spawn_drawing",
"spawn_and_move_media",
"pin_objects",
"spawn_emoji",
"fly"
]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, nice catch 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah at first I was like "Wait, js has an array concatenation operator? And then I realized what was going on... Oh javascript. Funny that it just happened to work mostly correctly by chance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good to see it's fixed, noticed that a year ago and I was just about to push a PR for that!
I wondered too at first if I was missing some obscure syntax XD


export default class HubChannel extends EventTarget {
constructor(store, hubId) {
Expand Down