@ -70,38 +70,44 @@ public class EOSVoiceChat: IDisposable
var connectArgs = new ChatConnectArgs ( chatLobbyName , maxChatPlayers ) ;
lobbyInterface . CreateLobbySearch ( new CreateLobbySearchOptions { MaxResults = 1 } , out var searchHandle ) ;
searchHandle . SetLobbyId ( new LobbySearchSetLobbyIdOptions { LobbyId = chatLobbyName } ) ;
var createSearchOptions = new CreateLobbySearchOptions { MaxResults = 1 } ;
lobbyInterface . CreateLobbySearch ( ref createSearchOptions , out var searchHandle ) ;
var setLobbyIdOptions = new LobbySearchSetLobbyIdOptions { LobbyId = chatLobbyName } ;
searchHandle . SetLobbyId ( ref setLobbyIdOptions ) ;
var localUserId = localUserProvider . Invoke ( ) ;
if ( localUserId = = null )
return ;
searchHandle . Find ( new LobbySearchFindOptions { LocalUserId = localUserId } , null , findData = >
var searchOptions = new LobbySearchFindOptions { LocalUserId = localUserId } ;
searchHandle . Find ( ref searchOptions , null , LobbySearchOnFindCallback ) ;
void LobbySearchOnFindCallback ( ref LobbySearchFindCallbackInfo findData )
{
switch ( findData . ResultCode )
{
case Result . Success :
searchHandle . CopySearchResultByIndex ( new LobbySearchCopySearchResultByIndexOptions { LobbyIndex = 0 } , out var lobbyDetails ) ;
var copyOptions = new LobbySearchCopySearchResultByIndexOptions { LobbyIndex = 0 } ;
searchHandle . CopySearchResultByIndex ( ref copyOptions , out var lobbyDetails ) ;
Debug . Log ( "Found existing chat lobby, joining..." ) ;
lobbyInterface . JoinLobby
(
new JoinLobbyOptions
var joinLobbyOptions = new JoinLobbyOptions
{
LocalUserId = localUserId ,
LobbyDetailsHandle = lobbyDetails ,
PresenceEnabled = false ,
} ,
} ;
lobbyInterface . JoinLobby
(
ref joinLobbyOptions ,
connectArgs ,
HandleLobbyJoined
) ;
break ;
default :
Debug . Log ( $"Creating new chat lobby..." ) ;
lobbyInterface . CreateLobby
(
new CreateLobbyOptions
var createLobbyOptions = new CreateLobbyOptions
{
LocalUserId = localUserId ,
AllowInvites = false ,
@ -112,16 +118,19 @@ public class EOSVoiceChat: IDisposable
LobbyId = chatLobbyName ,
BucketId = Application . productName , // TODO: do we need anything more specific than this?
EnableRTCRoom = true ,
} ,
} ;
lobbyInterface . CreateLobby
(
ref createLobbyOptions ,
connectArgs ,
HandleLobbyCreated
) ;
break ;
}
} ) ;
}
}
private void HandleLobbyCreated ( CreateLobbyCallbackInfo data )
private void HandleLobbyCreated ( ref CreateLobbyCallbackInfo data )
{
var connectArgs = ( ChatConnectArgs ) data . ClientData ;
switch ( data . ResultCode )
@ -153,9 +162,8 @@ public class EOSVoiceChat: IDisposable
}
}
private void HandleLobbyJoined ( JoinLobbyCallbackInfo data )
private void HandleLobbyJoined ( ref JoinLobbyCallbackInfo data )
{
var connectArgs = ( ChatConnectArgs ) data . ClientData ;
switch ( data . ResultCode )
{
case Result . Success :
@ -181,9 +189,12 @@ public class EOSVoiceChat: IDisposable
{
rtcRoomName = null ;
var result = lobbyInterface . GetRTCRoomName (
new GetRTCRoomNameOptions { LocalUserId = localUserProvider . Invoke ( ) , LobbyId = connectedLobbyId } ,
out string roomName ) ;
var getRoomNameOptions = new GetRTCRoomNameOptions
{
LocalUserId = localUserProvider . Invoke ( ) ,
LobbyId = connectedLobbyId
} ;
var result = lobbyInterface . GetRTCRoomName ( ref getRoomNameOptions , out Utf8String roomName ) ;
if ( result ! = Result . Success )
{
@ -202,16 +213,14 @@ public class EOSVoiceChat: IDisposable
// Unsubscribing first means we don't get a Disconnected notification for intentionally leaving the lobby
UnsubscribeFromRoomNotifications ( ) ;
lobbyInterface . LeaveLobby
(
new LeaveLobbyOptions
void OnLeaveLobbyCallback ( ref LeaveLobbyCallbackInfo data ) { }
var leaveLobbyOptions = new LeaveLobbyOptions
{
LocalUserId = localUserProvider . Invoke ( ) ,
LobbyId = connectedLobbyId ,
} ,
null ,
data = > { }
) ;
} ;
lobbyInterface . LeaveLobby ( ref leaveLobbyOptions , null , OnLeaveLobbyCallback ) ;
connectedLobbyId = null ;
rtcRoomName = null ;
@ -228,12 +237,15 @@ public class EOSVoiceChat: IDisposable
if ( ! IsConnected )
return ;
audioInterface . UpdateSending ( new UpdateSendingOptions
void OnUpdateSendingCallback ( ref UpdateSendingCallbackInfo data ) { }
var updateSendingOptions = new UpdateSendingOptions
{
LocalUserId = localUserProvider . Invoke ( ) ,
RoomName = rtcRoomName ,
AudioStatus = muted ? RTCAudioStatus . Disabled : RTCAudioStatus . Enabled ,
} , null , data = > { } ) ;
} ;
audioInterface . UpdateSending ( ref updateSendingOptions , null , OnUpdateSendingCallback ) ;
}
/// <summary>
@ -245,13 +257,16 @@ public class EOSVoiceChat: IDisposable
if ( ! IsConnected )
return ;
audioInterface . UpdateReceiving ( new UpdateReceivingOptions
void OnUpdateReceivingCallback ( ref UpdateReceivingCallbackInfo data ) { }
var updateReceivingOptions = new UpdateReceivingOptions
{
LocalUserId = localUserProvider . Invoke ( ) ,
ParticipantId = remoteUser ,
RoomName = rtcRoomName ,
AudioEnabled = ! muted ,
} , null , data = > { } ) ;
} ;
audioInterface . UpdateReceiving ( ref updateReceivingOptions , null , OnUpdateReceivingCallback ) ;
}
/// <summary>
@ -263,16 +278,19 @@ public class EOSVoiceChat: IDisposable
if ( ! IsConnected )
return ;
void OnUpdateReceivingCallback ( ref UpdateReceivingCallbackInfo data ) { }
var localUserId = localUserProvider . Invoke ( ) ;
foreach ( var remoteProductUser in chatUsers . Keys )
{
audioInterface . UpdateReceiving ( new UpdateReceivingOptions
var updateReceivingOptions = new UpdateReceivingOptions
{
LocalUserId = localUserId ,
ParticipantId = remoteProductUser ,
RoomName = rtcRoomName ,
AudioEnabled = false ,
} , null , data = > { } ) ;
} ;
audioInterface . UpdateReceiving ( ref updateReceivingOptions , null , OnUpdateReceivingCallback ) ;
}
}
@ -282,12 +300,13 @@ public class EOSVoiceChat: IDisposable
/// </summary>
public void SetOutputVolume ( float volume )
{
audioInterface . SetAudioOutputSettings ( new SetAudioOutputSettingsOptions
var setAudioOptions = new SetAudioOutputSettingsOptions
{
LocalUserId = localUserProvider . Invoke ( ) ,
DeviceId = null , // Default output device
Volume = volume * 5 0f ,
} ) ;
} ;
audioInterface . SetAudioOutputSettings ( ref setAudioOptions ) ;
}
/// <summary>
@ -308,12 +327,13 @@ public class EOSVoiceChat: IDisposable
{
if ( ! onAudioDevicesChangedCallbackId . HasValue )
{
var addNotifyOptions = new AddNotifyAudioDevicesChangedOptions ( ) ;
onAudioDevicesChangedCallbackId = audioInterface . AddNotifyAudioDevicesChanged (
new AddNotifyAudioDevicesChangedOptions ( ) , null ,
HandleAudioDevicesChanged ) ;
ref addNotifyOptions , null , HandleAudioDevicesChanged ) ;
// Call the event handler once to query the audio devices in their initial state
HandleAudioDevicesChanged ( null ) ;
AudioDevicesChangedCallbackInfo callbackInfo ;
HandleAudioDevicesChanged ( ref callbackInfo ) ;
}
}
@ -326,38 +346,40 @@ public class EOSVoiceChat: IDisposable
}
}
private void HandleAudioDevicesChanged ( AudioDevicesChangedCallbackInfo data )
private void HandleAudioDevicesChanged ( ref AudioDevicesChangedCallbackInfo data )
{
defaultInputDeviceId = null ;
var sb = new System . Text . StringBuilder ( ) ;
// Update the default input device, so we know whether we can actually talk or not
uint inputDevicesCount = audioInterface . GetAudioInputDevicesCount ( new GetAudioInputDevicesCountOptions ( ) ) ;
var getInputDevicesOptions = new GetAudioInputDevicesCountOptions ( ) ;
uint inputDevicesCount = audioInterface . GetAudioInputDevicesCount ( ref getInputDevicesOptions ) ;
sb . AppendLine ( $"Found {inputDevicesCount} audio input device(s):" ) ;
for ( uint inputDeviceIndex = 0 ; inputDeviceIndex < inputDevicesCount ; + + inputDeviceIndex )
{
var inputDeviceInfo = audioInterface . GetAudioInputDeviceByIndex (
new GetAudioInputDeviceByIndexOptions { DeviceInfoIndex = inputDeviceIndex } ) ;
var getDeviceOptions = new GetAudioInputDeviceByIndexOptions { DeviceInfoIndex = inputDeviceIndex } ;
var inputDeviceInfo = audioInterface . GetAudioInputDeviceByIndex ( ref getDeviceOptions ) ;
sb . AppendLine ( $"Input device {inputDeviceIndex}: ID = {inputDeviceInfo.DeviceId}, Name = {inputDeviceInfo.DeviceName}, Default = {inputDeviceInfo.DefaultDevice}" ) ;
sb . AppendLine ( $"Input device {inputDeviceIndex}: ID = {inputDeviceInfo? .DeviceId}, Name = {inputDeviceInfo? .DeviceName}, Default = {inputDeviceInfo? .DefaultDevice}" ) ;
if ( inputDeviceInfo . DefaultDevice )
if ( inputDeviceInfo ? . DefaultDevice ? ? fals e )
{
defaultInputDeviceId = inputDeviceInfo . DeviceId ;
defaultInputDeviceId = inputDeviceInfo . Value . DeviceId ;
}
}
uint outputDevicesCount = audioInterface . GetAudioOutputDevicesCount ( new GetAudioOutputDevicesCountOptions ( ) ) ;
var getOutputDevicesOptions = new GetAudioOutputDevicesCountOptions ( ) ;
uint outputDevicesCount = audioInterface . GetAudioOutputDevicesCount ( ref getOutputDevicesOptions ) ;
sb . AppendLine ( $"Found {outputDevicesCount} audio output device(s):" ) ;
for ( uint outputDeviceIndex = 0 ; outputDeviceIndex < outputDevicesCount ; + + outputDeviceIndex )
{
var outputDeviceInfo = audioInterface . GetAudioOutputDeviceByIndex (
new GetAudioOutputDeviceByIndexOptions { DeviceInfoIndex = outputDeviceIndex } ) ;
var getDeviceOptions = new GetAudioOutputDeviceByIndexOptions { DeviceInfoIndex = outputDeviceIndex } ;
var outputDeviceInfo = audioInterface . GetAudioOutputDeviceByIndex ( ref getDeviceOptions ) ;
sb . AppendLine ( $"Output device {outputDeviceIndex}: ID = {outputDeviceInfo.DeviceId}, Name = {outputDeviceInfo.DeviceName}, Default = {outputDeviceInfo.DefaultDevice}" ) ;
sb . AppendLine ( $"Output device {outputDeviceIndex}: ID = {outputDeviceInfo? .DeviceId}, Name = {outputDeviceInfo? .DeviceName}, Default = {outputDeviceInfo? .DefaultDevice}" ) ;
}
Debug . Log ( sb ) ;
@ -369,13 +391,10 @@ public class EOSVoiceChat: IDisposable
if ( ! onConnectionChangedCallbackId . HasValue )
{
var addNotifyOptions = new AddNotifyRTCRoomConnectionChangedOptions ( ) ;
onConnectionChangedCallbackId = lobbyInterface . AddNotifyRTCRoomConnectionChanged
(
new AddNotifyRTCRoomConnectionChangedOptions
{
LocalUserId = localUserId ,
LobbyId = connectedLobbyId ,
} ,
ref addNotifyOptions ,
null ,
HandleConnectionChanged
) ;
@ -383,13 +402,14 @@ public class EOSVoiceChat: IDisposable
if ( ! onParticipantStatusChangedCallbackId . HasValue )
{
onParticipantStatusChangedCallbackId = rtcInterface . AddNotifyParticipantStatusChanged
(
new AddNotifyParticipantStatusChangedOptions
var addNotifyOptions = new AddNotifyParticipantStatusChangedOptions
{
LocalUserId = localUserId ,
RoomName = rtcRoomName ,
} ,
} ;
onParticipantStatusChangedCallbackId = rtcInterface . AddNotifyParticipantStatusChanged
(
ref addNotifyOptions ,
null ,
HandleParticipantStatusChanged
) ;
@ -397,13 +417,14 @@ public class EOSVoiceChat: IDisposable
if ( ! onParticipantUpdatedCallbackId . HasValue )
{
onParticipantUpdatedCallbackId = audioInterface . AddNotifyParticipantUpdated
(
new AddNotifyParticipantUpdatedOptions
var addNotifyOptions = new AddNotifyParticipantUpdatedOptions
{
LocalUserId = localUserId ,
RoomName = rtcRoomName ,
} ,
} ;
onParticipantUpdatedCallbackId = audioInterface . AddNotifyParticipantUpdated
(
ref addNotifyOptions ,
null ,
HandleParticipantUpdated
) ;
@ -431,8 +452,11 @@ public class EOSVoiceChat: IDisposable
}
}
private void HandleConnectionChanged ( RTCRoomConnectionChangedCallbackInfo data )
private void HandleConnectionChanged ( ref RTCRoomConnectionChangedCallbackInfo data )
{
if ( data . LobbyId ! = connectedLobbyId )
return ;
// Note: reconnecting is handled automatically by the RTC lobby system
if ( ! data . IsConnected & &
( data . DisconnectReason = = Result . UserKicked | | data . DisconnectReason = = Result . UserBanned ) )
@ -442,7 +466,7 @@ public class EOSVoiceChat: IDisposable
}
}
private void HandleParticipantStatusChanged ( ParticipantStatusChangedCallbackInfo data )
private void HandleParticipantStatusChanged ( ref ParticipantStatusChangedCallbackInfo data )
{
switch ( data . ParticipantStatus )
{
@ -461,7 +485,7 @@ public class EOSVoiceChat: IDisposable
}
}
private void HandleParticipantUpdated ( ParticipantUpdatedCallbackInfo data )
private void HandleParticipantUpdated ( ref ParticipantUpdatedCallbackInfo data )
{
if ( chatUsers . TryGetValue ( data . ParticipantId , out var chatUser ) )
{