Skip to content

Commit

Permalink
hooks: Don't override handleUserActivity on FVTT v11+
Browse files Browse the repository at this point in the history
This fix has been included in Foundry v11
  • Loading branch information
bekriebel committed Jun 29, 2023
1 parent 6699223 commit e7b4ad1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
8 changes: 8 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ export function isVersion10AV(): boolean {
);
}

// Returns if the current version is using the new v10 AV
export function isVersion11AV(): boolean {
return isNewerVersion(
getGame().release.version || getGame().data.version || 0,
"11.292"
);
}

/**
* Dynamically load additional script files, returning when loaded
* @param scriptSrc The location of the script file
Expand Down
47 changes: 25 additions & 22 deletions src/utils/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SocketMessage } from "../../types/avclient-livekit";
import LiveKitAVConfig from "../LiveKitAVConfig";
import { MODULE_NAME } from "./constants";
import { getGame } from "./helpers";
import { getGame, isVersion11AV } from "./helpers";
import registerModuleSettings from "./registerModuleSettings";

/* -------------------------------------------- */
Expand Down Expand Up @@ -55,28 +55,31 @@ Hooks.on("ready", () => {
});

// TODO: Remove when FoundryVTT includes this patch
AVSettings.prototype.handleUserActivity = function handleUserActivity(
userId: string,
settings: AVSettingsData
) {
const current = this.activity[userId] || {};
this.activity[userId] = foundry.utils.mergeObject(current, settings, {
inplace: false,
});
const hiddenChanged =
"hidden" in settings && current.hidden !== settings.hidden;
const mutedChanged =
"muted" in settings && current.muted !== settings.muted;
if (
(hiddenChanged || mutedChanged) &&
ui.webrtc?.getUserVideoElement(userId)
if (!isVersion11AV()) {
AVSettings.prototype.handleUserActivity = function handleUserActivity(
userId: string,
settings: AVSettingsData
) {
// @ts-expect-error Using a protected method
ui.webrtc?._refreshView(userId);
}
if ("speaking" in settings)
ui.webrtc?.setUserIsSpeaking(userId, settings.speaking || false);
};
const current = this.activity[userId] || {};
this.activity[userId] = foundry.utils.mergeObject(current, settings, {
inplace: false,
});
if (!ui.webrtc) return;
const hiddenChanged =
"hidden" in settings && current.hidden !== settings.hidden;
const mutedChanged =
"muted" in settings && current.muted !== settings.muted;
if (
(hiddenChanged || mutedChanged) &&
ui.webrtc?.getUserVideoElement(userId)
) {
// @ts-expect-error Using a protected method
ui.webrtc._refreshView(userId);
}
if ("speaking" in settings)
ui.webrtc?.setUserIsSpeaking(userId, settings.speaking || false);
};
}
});

// Listen for DebugSet event
Expand Down

0 comments on commit e7b4ad1

Please sign in to comment.