refactor progress
This commit is contained in:
@@ -19,9 +19,16 @@
|
||||
|
||||
-export([move_member/2]).
|
||||
-export([send_voice_server_update_for_move/5]).
|
||||
-export([send_voice_server_update_for_move/6]).
|
||||
-export([send_voice_server_updates_for_move/4]).
|
||||
|
||||
-ifdef(TEST).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-endif.
|
||||
|
||||
-type guild_state() :: map().
|
||||
-type voice_state() :: map().
|
||||
-type voice_state_map() :: #{binary() => voice_state()}.
|
||||
-type move_request() :: #{
|
||||
user_id := integer(),
|
||||
moderator_id := integer(),
|
||||
@@ -31,10 +38,6 @@
|
||||
deaf := boolean()
|
||||
}.
|
||||
|
||||
-ifdef(TEST).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-endif.
|
||||
|
||||
-spec move_member(move_request(), guild_state()) -> {reply, map(), guild_state()}.
|
||||
move_member(Request, State) ->
|
||||
#{
|
||||
@@ -44,10 +47,17 @@ move_member(Request, State) ->
|
||||
} = Request,
|
||||
ConnectionId = maps:get(connection_id, Request, null),
|
||||
ChannelId = normalize_channel_id(ChannelIdRaw),
|
||||
logger:debug(
|
||||
"Handling voice move_member request",
|
||||
#{
|
||||
user_id => UserId,
|
||||
moderator_id => ModeratorId,
|
||||
channel_id => ChannelId,
|
||||
connection_id => ConnectionId
|
||||
}
|
||||
),
|
||||
VoiceStates = voice_state_utils:voice_states(State),
|
||||
|
||||
UserVoiceStates = find_user_voice_states(UserId, VoiceStates),
|
||||
|
||||
case maps:size(UserVoiceStates) of
|
||||
0 ->
|
||||
{reply, gateway_errors:error(voice_user_not_in_voice), State};
|
||||
@@ -55,11 +65,20 @@ move_member(Request, State) ->
|
||||
ConnectionsToMove = select_connections_to_move(
|
||||
ConnectionId, UserId, VoiceStates, UserVoiceStates
|
||||
),
|
||||
logger:debug(
|
||||
"Selected voice connections to move",
|
||||
#{
|
||||
user_id => UserId,
|
||||
connection_id => ConnectionId,
|
||||
connections_to_move_count => maps:size(ConnectionsToMove)
|
||||
}
|
||||
),
|
||||
handle_move(
|
||||
ConnectionsToMove, ChannelId, UserId, ModeratorId, ConnectionId, VoiceStates, State
|
||||
)
|
||||
end.
|
||||
|
||||
-spec find_user_voice_states(integer(), voice_state_map()) -> voice_state_map().
|
||||
find_user_voice_states(UserId, VoiceStates) ->
|
||||
maps:filter(
|
||||
fun(_ConnId, VoiceState) ->
|
||||
@@ -68,6 +87,8 @@ find_user_voice_states(UserId, VoiceStates) ->
|
||||
VoiceStates
|
||||
).
|
||||
|
||||
-spec select_connections_to_move(binary() | null, integer(), voice_state_map(), voice_state_map()) ->
|
||||
voice_state_map().
|
||||
select_connections_to_move(null, _UserId, _VoiceStates, UserVoiceStates) ->
|
||||
UserVoiceStates;
|
||||
select_connections_to_move(ConnectionId, UserId, VoiceStates, _UserVoiceStates) ->
|
||||
@@ -83,11 +104,16 @@ select_connections_to_move(ConnectionId, UserId, VoiceStates, _UserVoiceStates)
|
||||
end
|
||||
end.
|
||||
|
||||
-spec handle_move(
|
||||
voice_state_map(),
|
||||
integer() | null,
|
||||
integer(),
|
||||
integer(),
|
||||
binary() | null,
|
||||
voice_state_map(),
|
||||
guild_state()
|
||||
) -> {reply, map(), guild_state()}.
|
||||
handle_move(ConnectionsToMove, ChannelId, UserId, ModeratorId, ConnectionId, VoiceStates, State) ->
|
||||
logger:info(
|
||||
"[guild_voice_move] handle_move user_id=~p moderator_id=~p channel_id=~p connection_id=~p connections=~p",
|
||||
[UserId, ModeratorId, ChannelId, ConnectionId, maps:keys(ConnectionsToMove)]
|
||||
),
|
||||
case maps:size(ConnectionsToMove) of
|
||||
0 ->
|
||||
Error =
|
||||
@@ -99,14 +125,24 @@ handle_move(ConnectionsToMove, ChannelId, UserId, ModeratorId, ConnectionId, Voi
|
||||
_ ->
|
||||
case ChannelId of
|
||||
null ->
|
||||
logger:debug(
|
||||
"Disconnect move requested",
|
||||
#{user_id => UserId, connection_id => ConnectionId}
|
||||
),
|
||||
handle_disconnect_move(ConnectionsToMove, UserId, VoiceStates, State);
|
||||
ChannelIdValue ->
|
||||
logger:debug(
|
||||
"Channel move requested",
|
||||
#{user_id => UserId, channel_id => ChannelIdValue, connection_id => ConnectionId}
|
||||
),
|
||||
handle_channel_move(
|
||||
ConnectionsToMove, ChannelIdValue, UserId, ModeratorId, VoiceStates, State
|
||||
)
|
||||
end
|
||||
end.
|
||||
|
||||
-spec handle_disconnect_move(voice_state_map(), integer(), voice_state_map(), guild_state()) ->
|
||||
{reply, map(), guild_state()}.
|
||||
handle_disconnect_move(ConnectionsToMove, UserId, VoiceStates, State) ->
|
||||
NewVoiceStates = maps:fold(
|
||||
fun(ConnId, _VoiceState, Acc) -> maps:remove(ConnId, Acc) end,
|
||||
@@ -114,79 +150,107 @@ handle_disconnect_move(ConnectionsToMove, UserId, VoiceStates, State) ->
|
||||
ConnectionsToMove
|
||||
),
|
||||
NewState = maps:put(voice_states, NewVoiceStates, State),
|
||||
|
||||
maps:foreach(
|
||||
fun(_ConnId, VoiceState) ->
|
||||
OldChannelIdBin = maps:get(<<"channel_id">>, VoiceState, null),
|
||||
DisconnectVoiceState = maps:put(<<"channel_id">>, null, VoiceState),
|
||||
guild_voice_broadcast:broadcast_voice_state_update(
|
||||
DisconnectVoiceState, NewState, OldChannelIdBin
|
||||
)
|
||||
end,
|
||||
ConnectionsToMove
|
||||
),
|
||||
|
||||
spawn(fun() ->
|
||||
maps:foreach(
|
||||
fun(_ConnId, VoiceState) ->
|
||||
OldChannelIdBin = maps:get(<<"channel_id">>, VoiceState, null),
|
||||
DisconnectVoiceState = maps:put(<<"channel_id">>, null, VoiceState),
|
||||
guild_voice_broadcast:broadcast_voice_state_update(
|
||||
DisconnectVoiceState, NewState, OldChannelIdBin
|
||||
)
|
||||
end,
|
||||
ConnectionsToMove
|
||||
)
|
||||
end),
|
||||
{reply, #{success => true, user_id => UserId, connections_moved => ConnectionsToMove},
|
||||
NewState}.
|
||||
|
||||
-spec handle_channel_move(
|
||||
voice_state_map(), integer(), integer(), integer(), voice_state_map(), guild_state()
|
||||
) -> {reply, map(), guild_state()}.
|
||||
handle_channel_move(ConnectionsToMove, ChannelIdValue, UserId, ModeratorId, VoiceStates, State) ->
|
||||
logger:info(
|
||||
"[guild_voice_move] handle_channel_move user_id=~p moderator_id=~p target_channel_id=~p connections=~p",
|
||||
[UserId, ModeratorId, ChannelIdValue, maps:keys(ConnectionsToMove)]
|
||||
),
|
||||
Channel = guild_voice_member:find_channel_by_id(ChannelIdValue, State),
|
||||
case Channel of
|
||||
undefined ->
|
||||
{reply, gateway_errors:error(voice_channel_not_found), State};
|
||||
_ ->
|
||||
StateWithPending0 = guild_virtual_channel_access:mark_pending_join(
|
||||
UserId, ChannelIdValue, State
|
||||
),
|
||||
StateWithPending1 = guild_virtual_channel_access:mark_preserve(
|
||||
UserId, ChannelIdValue, StateWithPending0
|
||||
),
|
||||
StateWithPending2 = guild_virtual_channel_access:mark_move_pending(
|
||||
UserId, ChannelIdValue, StateWithPending1
|
||||
),
|
||||
ChannelType = maps:get(<<"type">>, Channel, 0),
|
||||
case ChannelType of
|
||||
2 ->
|
||||
check_move_permissions_and_execute(
|
||||
ConnectionsToMove, ChannelIdValue, UserId, ModeratorId, VoiceStates, State
|
||||
ConnectionsToMove,
|
||||
ChannelIdValue,
|
||||
UserId,
|
||||
ModeratorId,
|
||||
VoiceStates,
|
||||
StateWithPending2
|
||||
);
|
||||
_ ->
|
||||
{reply, gateway_errors:error(voice_channel_not_voice), State}
|
||||
end
|
||||
end.
|
||||
|
||||
-spec check_move_permissions_and_execute(
|
||||
voice_state_map(), integer(), integer(), integer(), voice_state_map(), guild_state()
|
||||
) -> {reply, map(), guild_state()}.
|
||||
check_move_permissions_and_execute(
|
||||
ConnectionsToMove, ChannelIdValue, _UserId, ModeratorId, VoiceStates, State
|
||||
ConnectionsToMove, ChannelIdValue, UserId, ModeratorId, VoiceStates, State
|
||||
) ->
|
||||
ViewPerm = constants:view_channel_permission(),
|
||||
ConnectPerm = constants:connect_permission(),
|
||||
ModPerms = guild_permissions:get_member_permissions(ModeratorId, ChannelIdValue, State),
|
||||
ModHasConnect = (ModPerms band ConnectPerm) =:= ConnectPerm,
|
||||
ModHasView = (ModPerms band ViewPerm) =:= ViewPerm,
|
||||
|
||||
case ModHasConnect andalso ModHasView of
|
||||
false ->
|
||||
{reply, gateway_errors:error(voice_moderator_missing_connect), State};
|
||||
true ->
|
||||
execute_move(ConnectionsToMove, VoiceStates, State)
|
||||
execute_move(ConnectionsToMove, ChannelIdValue, UserId, VoiceStates, State)
|
||||
end.
|
||||
|
||||
execute_move(ConnectionsToMove, VoiceStates, State) ->
|
||||
-spec execute_move(voice_state_map(), integer(), integer(), voice_state_map(), guild_state()) ->
|
||||
{reply, map(), guild_state()}.
|
||||
execute_move(ConnectionsToMove, ChannelIdValue, UserId, VoiceStates, State) ->
|
||||
StatePending = guild_virtual_channel_access:mark_pending_join(UserId, ChannelIdValue, State),
|
||||
StatePending2 = guild_virtual_channel_access:mark_preserve(
|
||||
UserId, ChannelIdValue, StatePending
|
||||
),
|
||||
StatePending3 = guild_virtual_channel_access:mark_move_pending(
|
||||
UserId, ChannelIdValue, StatePending2
|
||||
),
|
||||
logger:debug(
|
||||
"Executing voice channel move",
|
||||
#{user_id => UserId, channel_id => ChannelIdValue}
|
||||
),
|
||||
NewVoiceStates = maps:fold(
|
||||
fun(ConnId, _VoiceState, Acc) -> maps:remove(ConnId, Acc) end,
|
||||
VoiceStates,
|
||||
ConnectionsToMove
|
||||
),
|
||||
StateAfterDisconnect = maps:put(voice_states, NewVoiceStates, State),
|
||||
|
||||
maps:foreach(
|
||||
fun(_ConnId, VoiceState) ->
|
||||
OldChannelIdBin = maps:get(<<"channel_id">>, VoiceState, null),
|
||||
DisconnectVoiceState = maps:put(<<"channel_id">>, null, VoiceState),
|
||||
guild_voice_broadcast:broadcast_voice_state_update(
|
||||
DisconnectVoiceState, StateAfterDisconnect, OldChannelIdBin
|
||||
)
|
||||
end,
|
||||
ConnectionsToMove
|
||||
),
|
||||
|
||||
StateAfterDisconnect = maps:put(voice_states, NewVoiceStates, StatePending3),
|
||||
StateWithVirtualAccess = maybe_add_virtual_access(UserId, ChannelIdValue, StateAfterDisconnect),
|
||||
spawn(fun() ->
|
||||
maps:foreach(
|
||||
fun(_ConnId, VoiceState) ->
|
||||
OldChannelIdBin = maps:get(<<"channel_id">>, VoiceState, null),
|
||||
DisconnectVoiceState = maps:put(<<"channel_id">>, null, VoiceState),
|
||||
guild_voice_broadcast:broadcast_voice_state_update(
|
||||
DisconnectVoiceState, StateWithVirtualAccess, OldChannelIdBin
|
||||
)
|
||||
end,
|
||||
ConnectionsToMove
|
||||
)
|
||||
end),
|
||||
SessionData = extract_session_data(ConnectionsToMove),
|
||||
|
||||
{reply,
|
||||
#{
|
||||
success => true,
|
||||
@@ -194,8 +258,9 @@ execute_move(ConnectionsToMove, VoiceStates, State) ->
|
||||
session_data => SessionData,
|
||||
connections_to_move => ConnectionsToMove
|
||||
},
|
||||
StateAfterDisconnect}.
|
||||
StateWithVirtualAccess}.
|
||||
|
||||
-spec extract_session_data(voice_state_map()) -> [map()].
|
||||
extract_session_data(ConnectionsToMove) ->
|
||||
{_ConnectionIds, SessionData} = maps:fold(
|
||||
fun(ConnId, VoiceState, {AccConnIds, AccSessionData}) ->
|
||||
@@ -223,6 +288,159 @@ member_user_id(Member) ->
|
||||
User = map_utils:ensure_map(maps:get(<<"user">>, map_utils:ensure_map(Member), #{})),
|
||||
map_utils:get_integer(User, <<"id">>, undefined).
|
||||
|
||||
-spec send_voice_server_update_for_move(
|
||||
integer(), integer(), integer(), binary() | undefined, pid()
|
||||
) -> ok.
|
||||
send_voice_server_update_for_move(GuildId, ChannelId, UserId, SessionId, GuildPid) ->
|
||||
send_voice_server_update_for_move(GuildId, ChannelId, UserId, SessionId, null, GuildPid).
|
||||
|
||||
-spec send_voice_server_update_for_move(
|
||||
integer(), integer(), integer(), binary() | undefined, binary() | null, pid()
|
||||
) -> ok.
|
||||
send_voice_server_update_for_move(GuildId, ChannelId, UserId, SessionId, OldConnectionId, GuildPid) ->
|
||||
case SessionId of
|
||||
undefined ->
|
||||
ok;
|
||||
_ ->
|
||||
spawn(fun() ->
|
||||
case gen_server:call(GuildPid, {get_sessions}, 10000) of
|
||||
State when is_map(State) ->
|
||||
VoicePermissions = voice_utils:compute_voice_permissions(
|
||||
UserId, ChannelId, State
|
||||
),
|
||||
case
|
||||
guild_voice_connection:request_voice_token(
|
||||
GuildId, ChannelId, UserId, OldConnectionId, VoicePermissions
|
||||
)
|
||||
of
|
||||
{ok, TokenData} ->
|
||||
Token = maps:get(token, TokenData),
|
||||
Endpoint = maps:get(endpoint, TokenData),
|
||||
ConnectionId = maps:get(connection_id, TokenData),
|
||||
guild_voice_broadcast:broadcast_voice_server_update_to_session(
|
||||
GuildId,
|
||||
ChannelId,
|
||||
SessionId,
|
||||
Token,
|
||||
Endpoint,
|
||||
ConnectionId,
|
||||
State
|
||||
);
|
||||
{error, _Reason} ->
|
||||
ok
|
||||
end;
|
||||
_ ->
|
||||
ok
|
||||
end
|
||||
end),
|
||||
ok
|
||||
end.
|
||||
|
||||
-spec maybe_add_virtual_access(integer(), integer(), guild_state()) -> guild_state().
|
||||
maybe_add_virtual_access(UserId, ChannelId, State) ->
|
||||
Member = guild_permissions:find_member_by_user_id(UserId, State),
|
||||
case Member of
|
||||
undefined ->
|
||||
State;
|
||||
_ ->
|
||||
Permissions = guild_permissions:get_member_permissions(UserId, ChannelId, State),
|
||||
ViewPerm = constants:view_channel_permission(),
|
||||
ConnectPerm = constants:connect_permission(),
|
||||
HasView = (Permissions band ViewPerm) =:= ViewPerm,
|
||||
HasConnect = (Permissions band ConnectPerm) =:= ConnectPerm,
|
||||
case HasView andalso HasConnect of
|
||||
true ->
|
||||
State;
|
||||
false ->
|
||||
NewState = guild_virtual_channel_access:add_virtual_access(
|
||||
UserId, ChannelId, State
|
||||
),
|
||||
guild_virtual_channel_access:dispatch_channel_visibility_change(
|
||||
UserId, ChannelId, add, NewState
|
||||
),
|
||||
NewState
|
||||
end
|
||||
end.
|
||||
|
||||
-spec send_voice_server_updates_for_move(integer(), integer(), [map()], pid()) -> ok.
|
||||
send_voice_server_updates_for_move(GuildId, ChannelId, SessionDataList, GuildPid) ->
|
||||
spawn(fun() ->
|
||||
lists:foreach(
|
||||
fun(SessionInfo) ->
|
||||
send_single_voice_server_update(GuildId, ChannelId, SessionInfo, GuildPid)
|
||||
end,
|
||||
SessionDataList
|
||||
)
|
||||
end),
|
||||
ok.
|
||||
|
||||
-spec send_single_voice_server_update(integer(), integer(), map(), pid()) -> ok.
|
||||
send_single_voice_server_update(GuildId, ChannelId, SessionInfo, GuildPid) ->
|
||||
SessionId = maps:get(session_id, SessionInfo),
|
||||
SelfMute = maps:get(self_mute, SessionInfo),
|
||||
SelfDeaf = maps:get(self_deaf, SessionInfo),
|
||||
SelfVideo = maps:get(self_video, SessionInfo),
|
||||
SelfStream = maps:get(self_stream, SessionInfo),
|
||||
IsMobile = maps:get(is_mobile, SessionInfo),
|
||||
OldConnectionId = maps:get(connection_id, SessionInfo, null),
|
||||
Member = maps:get(member, SessionInfo),
|
||||
ServerMute = maps:get(<<"mute">>, Member, false),
|
||||
ServerDeaf = maps:get(<<"deaf">>, Member, false),
|
||||
case member_user_id(Member) of
|
||||
undefined ->
|
||||
ok;
|
||||
UserId ->
|
||||
case gen_server:call(GuildPid, {get_sessions}, 10000) of
|
||||
StateData when is_map(StateData) ->
|
||||
VoicePermissions = voice_utils:compute_voice_permissions(
|
||||
UserId, ChannelId, StateData
|
||||
),
|
||||
case
|
||||
guild_voice_connection:request_voice_token(
|
||||
GuildId, ChannelId, UserId, OldConnectionId, VoicePermissions
|
||||
)
|
||||
of
|
||||
{ok, TokenData} ->
|
||||
Token = maps:get(token, TokenData),
|
||||
Endpoint = maps:get(endpoint, TokenData),
|
||||
NewConnectionId = maps:get(connection_id, TokenData),
|
||||
PendingMetadata = #{
|
||||
<<"user_id">> => UserId,
|
||||
<<"guild_id">> => GuildId,
|
||||
<<"channel_id">> => ChannelId,
|
||||
<<"connection_id">> => NewConnectionId,
|
||||
<<"session_id">> => SessionId,
|
||||
<<"self_mute">> => SelfMute,
|
||||
<<"self_deaf">> => SelfDeaf,
|
||||
<<"self_video">> => SelfVideo,
|
||||
<<"self_stream">> => SelfStream,
|
||||
<<"is_mobile">> => IsMobile,
|
||||
<<"server_mute">> => ServerMute,
|
||||
<<"server_deaf">> => ServerDeaf,
|
||||
<<"member">> => Member
|
||||
},
|
||||
_ = gen_server:call(
|
||||
GuildPid,
|
||||
{store_pending_connection, NewConnectionId, PendingMetadata},
|
||||
10000
|
||||
),
|
||||
guild_voice_broadcast:broadcast_voice_server_update_to_session(
|
||||
GuildId,
|
||||
ChannelId,
|
||||
SessionId,
|
||||
Token,
|
||||
Endpoint,
|
||||
NewConnectionId,
|
||||
StateData
|
||||
);
|
||||
{error, _Reason} ->
|
||||
ok
|
||||
end;
|
||||
_ ->
|
||||
ok
|
||||
end
|
||||
end.
|
||||
|
||||
-ifdef(TEST).
|
||||
|
||||
move_member_user_not_in_voice_test() ->
|
||||
@@ -253,6 +471,12 @@ select_connections_to_move_specific_connection_test() ->
|
||||
?assertEqual(#{<<"conn-b">> => maps:get(<<"conn-b">>, VoiceStates)}, Selected),
|
||||
?assertEqual(#{}, select_connections_to_move(<<"conn-b">>, 10, VoiceStates, #{})).
|
||||
|
||||
normalize_channel_id_test() ->
|
||||
?assertEqual(null, normalize_channel_id(null)),
|
||||
?assertEqual(123, normalize_channel_id(123)),
|
||||
?assertEqual(456, normalize_channel_id(<<"456">>)),
|
||||
?assertEqual(null, normalize_channel_id(undefined)).
|
||||
|
||||
test_state(VoiceStates) ->
|
||||
#{
|
||||
id => 1,
|
||||
@@ -274,105 +498,3 @@ voice_state_fixture(UserId, ChannelId, ConnId) ->
|
||||
}.
|
||||
|
||||
-endif.
|
||||
|
||||
send_voice_server_update_for_move(GuildId, ChannelId, UserId, SessionId, GuildPid) ->
|
||||
case SessionId of
|
||||
undefined ->
|
||||
ok;
|
||||
_ ->
|
||||
case gen_server:call(GuildPid, {get_sessions}, 10000) of
|
||||
State when is_map(State) ->
|
||||
VoicePermissions = voice_utils:compute_voice_permissions(
|
||||
UserId, ChannelId, State
|
||||
),
|
||||
case
|
||||
guild_voice_connection:request_voice_token(
|
||||
GuildId, ChannelId, UserId, VoicePermissions
|
||||
)
|
||||
of
|
||||
{ok, TokenData} ->
|
||||
Token = maps:get(token, TokenData),
|
||||
Endpoint = maps:get(endpoint, TokenData),
|
||||
ConnectionId = maps:get(connection_id, TokenData),
|
||||
guild_voice_broadcast:broadcast_voice_server_update_to_session(
|
||||
GuildId, SessionId, Token, Endpoint, ConnectionId, State
|
||||
);
|
||||
{error, _Reason} ->
|
||||
ok
|
||||
end;
|
||||
_ ->
|
||||
ok
|
||||
end
|
||||
end.
|
||||
|
||||
send_voice_server_updates_for_move(GuildId, ChannelId, SessionDataList, GuildPid) ->
|
||||
lists:foreach(
|
||||
fun(SessionInfo) ->
|
||||
send_single_voice_server_update(GuildId, ChannelId, SessionInfo, GuildPid)
|
||||
end,
|
||||
SessionDataList
|
||||
).
|
||||
|
||||
send_single_voice_server_update(GuildId, ChannelId, SessionInfo, GuildPid) ->
|
||||
SessionId = maps:get(session_id, SessionInfo),
|
||||
SelfMute = maps:get(self_mute, SessionInfo),
|
||||
SelfDeaf = maps:get(self_deaf, SessionInfo),
|
||||
SelfVideo = maps:get(self_video, SessionInfo),
|
||||
SelfStream = maps:get(self_stream, SessionInfo),
|
||||
IsMobile = maps:get(is_mobile, SessionInfo),
|
||||
Member = maps:get(member, SessionInfo),
|
||||
ServerMute = maps:get(<<"mute">>, Member, false),
|
||||
ServerDeaf = maps:get(<<"deaf">>, Member, false),
|
||||
case member_user_id(Member) of
|
||||
undefined ->
|
||||
logger:warning(
|
||||
"[guild_voice_move] Missing user_id in member while sending voice server update: ~p",
|
||||
[SessionInfo]
|
||||
),
|
||||
ok;
|
||||
UserId ->
|
||||
case gen_server:call(GuildPid, {get_sessions}, 10000) of
|
||||
StateData when is_map(StateData) ->
|
||||
VoicePermissions = voice_utils:compute_voice_permissions(
|
||||
UserId, ChannelId, StateData
|
||||
),
|
||||
case
|
||||
guild_voice_connection:request_voice_token(
|
||||
GuildId, ChannelId, UserId, VoicePermissions
|
||||
)
|
||||
of
|
||||
{ok, TokenData} ->
|
||||
Token = maps:get(token, TokenData),
|
||||
Endpoint = maps:get(endpoint, TokenData),
|
||||
NewConnectionId = maps:get(connection_id, TokenData),
|
||||
|
||||
PendingMetadata = #{
|
||||
<<"user_id">> => UserId,
|
||||
<<"guild_id">> => GuildId,
|
||||
<<"channel_id">> => ChannelId,
|
||||
<<"connection_id">> => NewConnectionId,
|
||||
<<"session_id">> => SessionId,
|
||||
<<"self_mute">> => SelfMute,
|
||||
<<"self_deaf">> => SelfDeaf,
|
||||
<<"self_video">> => SelfVideo,
|
||||
<<"self_stream">> => SelfStream,
|
||||
<<"is_mobile">> => IsMobile,
|
||||
<<"server_mute">> => ServerMute,
|
||||
<<"server_deaf">> => ServerDeaf,
|
||||
<<"member">> => Member
|
||||
},
|
||||
gen_server:cast(
|
||||
GuildPid,
|
||||
{store_pending_connection, NewConnectionId, PendingMetadata}
|
||||
),
|
||||
|
||||
guild_voice_broadcast:broadcast_voice_server_update_to_session(
|
||||
GuildId, SessionId, Token, Endpoint, NewConnectionId, StateData
|
||||
);
|
||||
{error, _Reason} ->
|
||||
ok
|
||||
end;
|
||||
_ ->
|
||||
ok
|
||||
end
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user