Skip to content

Commit

Permalink
feat(client): Add new voice methods
Browse files Browse the repository at this point in the history
  • Loading branch information
xLuxy committed Dec 28, 2023
1 parent eec9390 commit 20d9082
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 1 deletion.
112 changes: 112 additions & 0 deletions client/src/namespaces/VoiceNamespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,113 @@ static void AvailableInputDevicesGetter(js::PropertyContext& ctx)
ctx.Return(devicesArr);
}

static void VoicePlayersGetter(js::PropertyContext& ctx)
{
auto players = alt::ICore::Instance().GetVoicePlayers();

js::Array playersArr(players.size());
for(auto& remoteId : players)
playersArr.Push(remoteId);

ctx.Return(playersArr);
}

static void ToggleInput(js::FunctionContext& ctx)
{
bool enabled;
if(!ctx.GetArg(0, enabled)) return;
alt::ICore::Instance().ToggleVoiceInput(enabled);
}

static void RemoveVoicePlayer(js::FunctionContext& ctx)
{
if (!ctx.CheckArgCount(1)) return;

uint32_t remoteId;
if (!ctx.GetArg(1, remoteId)) return;

alt::ICore::Instance().RemoveVoicePlayer(remoteId);
}

static void GetPlayerSpatialVolume(js::FunctionContext& ctx)
{
if (!ctx.CheckArgCount(1)) return;

uint32_t remoteId;
if (!ctx.GetArg(1, remoteId)) return;

ctx.Return(alt::ICore::Instance().GetVoiceSpatialVolume(remoteId));
}

static void SetPlayerSpatialVolume(js::FunctionContext& ctx)
{
if (!ctx.CheckArgCount(2)) return;

uint32_t remoteId;
if (!ctx.GetArg(1, remoteId)) return;

float volume;
if (!ctx.GetArg(2, volume)) return;

alt::ICore::Instance().SetVoiceSpatialVolume(remoteId, volume);
}

static void GetPlayerNonSpatialVolume(js::FunctionContext& ctx)
{
if (!ctx.CheckArgCount(1)) return;

uint32_t remoteId;
if (!ctx.GetArg(1, remoteId)) return;

ctx.Return(alt::ICore::Instance().GetVoiceNonSpatialVolume(remoteId));
}

static void SetPlayerNonSpatialVolume(js::FunctionContext& ctx)
{
if (!ctx.CheckArgCount(2)) return;

uint32_t remoteId;
if (!ctx.GetArg(1, remoteId)) return;

float volume;
if (!ctx.GetArg(2, volume)) return;

alt::ICore::Instance().SetVoiceNonSpatialVolume(remoteId, volume);
}

static void AddPlayerFilter(js::FunctionContext& ctx)
{
if (!ctx.CheckArgCount(2)) return;

uint32_t remoteId;
if (!ctx.GetArg(1, remoteId)) return;

alt::IAudioFilter* filter;
if (!ctx.GetArg(2, filter)) return;

alt::ICore::Instance().AddVoiceFilter(remoteId, filter);
}

static void RemovePlayerFilter(js::FunctionContext& ctx)
{
if (!ctx.CheckArgCount(1)) return;

uint32_t remoteId;
if (!ctx.GetArg(1, remoteId)) return;

alt::ICore::Instance().RemoveVoiceFilter(remoteId);
}

static void GetPlayerFilter(js::FunctionContext& ctx)
{
if (!ctx.CheckArgCount(1)) return;

uint32_t remoteId;
if (!ctx.GetArg(1, remoteId)) return;

ctx.Return(alt::ICore::Instance().GetVoiceFilter(remoteId));
}

// clang-format off
extern js::Namespace voiceNamespace("Voice", [](js::NamespaceTemplate& tpl) {
tpl.StaticProperty("inputMuted", InputMutedGetter, InputMutedSetter);
Expand All @@ -115,6 +215,18 @@ extern js::Namespace voiceNamespace("Voice", [](js::NamespaceTemplate& tpl) {
tpl.StaticProperty("noiseSuppressionEnabled", NoiseSuppressionEnabledGetter, NoiseSuppressionEnabledSetter);
tpl.StaticProperty("inputDevice", InputDeviceGetter, InputDeviceSetter);
tpl.StaticProperty("availableInputDevices", AvailableInputDevicesGetter);
tpl.StaticProperty("voicePlayers", VoicePlayersGetter);

tpl.StaticFunction("toggleInput", ToggleInput);
tpl.StaticFunction("removeVoicePlayer", RemoveVoicePlayer);

tpl.StaticFunction("getPlayerSpatialVolume", GetPlayerSpatialVolume);
tpl.StaticFunction("setPlayerSpatialVolume", SetPlayerSpatialVolume);

tpl.StaticFunction("getPlayerNonSpatialVolume", GetPlayerNonSpatialVolume);
tpl.StaticFunction("setPlayerNonSpatialVolume", SetPlayerNonSpatialVolume);

tpl.StaticFunction("addPlayerFilter", AddPlayerFilter);
tpl.StaticFunction("removePlayerFilter", RemovePlayerFilter);
tpl.StaticFunction("getPlayerFilter", GetPlayerFilter);
});
12 changes: 12 additions & 0 deletions types/client/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,19 @@ declare module "@altv/client" {
name: string;
}>;

export const voicePlayers: Array<number>;

export function toggleInput(enabled: boolean): void;

export function getPlayerSpatialVolume(remotePlayerId: number): number;
export function SetPlayerSpatialVolume(remotePlayerId: number, volume: number): void;

export function getPlayerNonSpatialVolume(remotePlayerId: number): number;
export function setPlayerNonSpatialVolume(remotePlayerId: number, volume: number): void;

export function addPlayerFilter(remotePlayerId: number, filter: AudioFilter): void;
export function removePlayerFilter(remotePlayerId: number, filter: AudioFilter): void;
export function getPlayerFilter(remotePlayerId: number): AudioFilter;
}

export namespace LocalStorage {
Expand Down
2 changes: 1 addition & 1 deletion types/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@altv/client",
"version": "0.0.16",
"version": "0.0.17",
"description": "This package contains the type definitions for the alt:V JS module v2 client types",
"types": "index.d.ts",
"files": [
Expand Down

0 comments on commit 20d9082

Please sign in to comment.