Pico Unity Platform SDK
Pico.Platform.RtcService Class Reference

Static Public Member Functions

static RtcEngineInitResult InitRtcEngine ()
 Initializes the RTC engine.
Note: You should call this method before using the RTC service. More...
 
static Task< string > GetToken (string roomId, string userId, int ttl, Dictionary< RtcPrivilege, int > privileges)
 Gets the token required by JoinRoom. More...
 
static int JoinRoom (string roomId, string userId, string token, RtcRoomProfileType rtcRoomProfileType, bool isAutoSubscribeAudio)
 Joins a user to a specified room. More...
 
static int LeaveRoom (string roomId)
 Leaves a specified room. More...
 
static void SetAudioPlaybackDevice (RtcAudioPlaybackDevice device)
 Sets the audio playback device. More...
 
static void RoomPauseAllSubscribedStream (string roomId)
 Pauses all subscribed streams of a room. Once paused, the voice of users in the room is blocked so nothing can be heard from this room. More...
 
static void RoomResumeAllSubscribedStream (string roomId)
 Resumes all subscribed streams of a room. Once resumed, the voice of users in the room can be heard again. More...
 
static void EnableAudioPropertiesReport (int interval)
 Enables audio properties report. Once enabled, you will receive audio report data regularly. More...
 
static void PublishRoom (string roomId)
 Publishes the local audio stream to a room, thereby making the voice heard be others in the same room. More...
 
static void UnPublishRoom (string roomId)
 Stops publishing the local audio stream to a room, so others in the same room cannot hear the voice. More...
 
static void DestroyRoom (string roomId)
 Destroys a specified room. The resources occupied by the room will be released after destruction. More...
 
static void StartAudioCapture ()
 Starts audio capture via the microphone. More...
 
static void StopAudioCapture ()
 Stops audio capture. More...
 
static void SetCaptureVolume (int volume)
 Sets the volume of the captured audio. More...
 
static void SetPlaybackVolume (int volume)
 Sets the playback volume. More...
 
static void SetEarMonitorMode (RtcEarMonitorMode mode)
 Switches the in-ear monitoring mode on/off. Once the in-ear monitoring mode is enabled, one can hear their own voice. More...
 
static void SetEarMonitorVolume (int volume)
 Sets the volume for in-ear monitoring. More...
 
static void MuteLocalAudio (RtcMuteState rtcMuteState)
 Mutes local audio to make one's voice unable to be heard be others in the same room. More...
 
static void UpdateToken (string roomId, string token)
 Updates the token.
Note: Once a token's ttl is about to expire, you should update the token if you still want to stay in the room. More...
 
static void SetAudioScenario (RtcAudioScenarioType scenarioType)
 Sets the audio scenario.
Note: Different audio scenarios can impact the voice quality and how the earphones work. More...
 
static void SetOnJoinRoomResultCallback (Message< RtcJoinRoomResult >.Handler handler)
 Sets the callback of JoinRoom to get RtcJoinRoomResult. More...
 
static void SetOnLeaveRoomResultCallback (Message< RtcLeaveRoomResult >.Handler handler)
 Sets the callback of LeaveRoom to get RtcLeaveRoomResult. More...
 
static void SetOnUserJoinRoomResultCallback (Message< RtcUserJoinInfo >.Handler handler)
 Sets the callback to get notified when someone has joined the room. More...
 
static void SetOnUserLeaveRoomResultCallback (Message< RtcUserLeaveInfo >.Handler handler)
 Sets the callback to get notified when someone has left the room. More...
 
static void SetOnRoomStatsCallback (Message< RtcRoomStats >.Handler handler)
 Sets the callback to regularly get room statistics after joining a room. More...
 
static void SetOnWarnCallback (Message< int >.Handler handler)
 Sets the callback to get warning messages from the RTC engine. The warning codes and descriptions are given below. More...
 
static void SetOnErrorCallback (Message< int >.Handler handler)
 Sets the callback to get error messages from the RTC engine. The error codes and descriptions are given below. More...
 
static void SetOnRoomWarnCallback (Message< RtcRoomWarn >.Handler handler)
 Sets the callback to get warning messages from the room. More...
 
static void SetOnRoomErrorCallback (Message< RtcRoomError >.Handler handler)
 Sets the callback to get error messages from the room. More...
 
static void SetOnConnectionStateChangeCallback (Message< RtcConnectionState >.Handler handler)
 Sets the callback to get notified when the state of the connection to the RTC server has changed. More...
 
static void SetOnUserMuteAudio (Message< RtcMuteInfo >.Handler handler)
 Sets the callback to get notified when the user has muted local audio. More...
 
static void SetOnUserStartAudioCapture (Message< string >.Handler handler)
 Sets the callback to get notified when the user has started audio capture. More...
 
static void SetOnUserStopAudioCapture (Message< string >.Handler handler)
 Sets the callback to get notified when the user has stopped audio capture. More...
 
static void SetOnAudioPlaybackDeviceChange (Message< RtcAudioPlaybackDevice >.Handler handler)
 Sets the callback to get notified when the audio playback device has been changed. More...
 
static void SetOnLocalAudioPropertiesReport (Message< RtcLocalAudioPropertiesReport >.Handler handler)
 Sets the callback to receive local audio report. More...
 
static void SetOnRemoteAudioPropertiesReport (Message< RtcRemoteAudioPropertiesReport >.Handler handler)
 Sets the callback to receive remote audio report. More...
 

Member Function Documentation

◆ DestroyRoom()

static void Pico.Platform.RtcService.DestroyRoom ( string  roomId)
static

Destroys a specified room. The resources occupied by the room will be released after destruction.

Parameters
roomIdThe ID of the room to destroy.

◆ EnableAudioPropertiesReport()

static void Pico.Platform.RtcService.EnableAudioPropertiesReport ( int  interval)
static

Enables audio properties report. Once enabled, you will receive audio report data regularly.

Parameters
intervalThe interval (in milliseconds) between one report and the next. You can set this parameter to 0 or any negative integer to stop receiving audio properties report. For any integer between (0, 100), the SDK will regard it as invalid and automatically set this parameter to 100; any integer equal to or greater than 100 is valid.

◆ GetToken()

static Task<string> Pico.Platform.RtcService.GetToken ( string  roomId,
string  userId,
int  ttl,
Dictionary< RtcPrivilege, int >  privileges 
)
static

Gets the token required by JoinRoom.

Parameters
roomIdThe ID of the room that the token is for.
userIdThe ID of the user that the token is for.
ttlThe time-to-live (ttl) of the token.
privilegesThe dictionary that maps privilege to ttl.

◆ InitRtcEngine()

static RtcEngineInitResult Pico.Platform.RtcService.InitRtcEngine ( )
static

Initializes the RTC engine.
Note: You should call this method before using the RTC service.

Returns
The status that indicates whether the initialization is successful.

◆ JoinRoom()

static int Pico.Platform.RtcService.JoinRoom ( string  roomId,
string  userId,
string  token,
RtcRoomProfileType  rtcRoomProfileType,
bool  isAutoSubscribeAudio 
)
static

Joins a user to a specified room.

Parameters
roomIdThe ID of the room to join.
userIdThe ID of user.
tokenThe token required for joining the room. You can get the token by calling GetToken.
roomProfileTypeRoom type:
  • 0: communication room
  • 1: live broadcasting room
  • 2: game room
  • 3: cloud game room
  • 4: low-latency room
isAutoSubscribeAudioWhether to automatically subscribe to the audio in the room:
  • true: subscribe
  • false: do not subscribe
Returns
0 indicates success, and other values indicate failure.
Error Code Description
0 Success.
-1 Invalid roomID or userId.
-2 The user is already in this room.
-3 The RTC engine is null. You should initialize the RTC engine before joining a room.
-4 Creating the room failed.

◆ LeaveRoom()

static int Pico.Platform.RtcService.LeaveRoom ( string  roomId)
static

Leaves a specified room.

Parameters
roomIdThe ID of the room to leave.
Returns

0 indicates success, and other values indicate failure.

Error Code Description
0 Success.
-1 The RTC engine is not initialized.
-2 The user is not in the room.

◆ MuteLocalAudio()

static void Pico.Platform.RtcService.MuteLocalAudio ( RtcMuteState  rtcMuteState)
static

Mutes local audio to make one's voice unable to be heard be others in the same room.

Parameters
rtcMuteStateThe state of local audio:
  • 0: off
  • 1: on

◆ PublishRoom()

static void Pico.Platform.RtcService.PublishRoom ( string  roomId)
static

Publishes the local audio stream to a room, thereby making the voice heard be others in the same room.

Parameters
roomIdThe ID of the room that the local audio stream is published to.

◆ RoomPauseAllSubscribedStream()

static void Pico.Platform.RtcService.RoomPauseAllSubscribedStream ( string  roomId)
static

Pauses all subscribed streams of a room. Once paused, the voice of users in the room is blocked so nothing can be heard from this room.

Parameters
roomIdThe ID of the room to pause subscribed streams for.

◆ RoomResumeAllSubscribedStream()

static void Pico.Platform.RtcService.RoomResumeAllSubscribedStream ( string  roomId)
static

Resumes all subscribed streams of a room. Once resumed, the voice of users in the room can be heard again.

Parameters
roomIdThe ID of the room to resume subscribed streams for.

◆ SetAudioPlaybackDevice()

static void Pico.Platform.RtcService.SetAudioPlaybackDevice ( RtcAudioPlaybackDevice  device)
static

Sets the audio playback device.

Parameters
deviceThe device ID.

◆ SetAudioScenario()

static void Pico.Platform.RtcService.SetAudioScenario ( RtcAudioScenarioType  scenarioType)
static

Sets the audio scenario.
Note: Different audio scenarios can impact the voice quality and how the earphones work.

Parameters
scenarioTypeThe audio scenario type:
  • 0: Music
  • 1: HighQualityCommunication
  • 2: Communication
  • 3: Media
  • 4: GameStreaming

◆ SetCaptureVolume()

static void Pico.Platform.RtcService.SetCaptureVolume ( int  volume)
static

Sets the volume of the captured audio.

Parameters
volumeThe target volume. The valid value ranges from 0 to 400. 100 indicates keeping the original volume.

◆ SetEarMonitorMode()

static void Pico.Platform.RtcService.SetEarMonitorMode ( RtcEarMonitorMode  mode)
static

Switches the in-ear monitoring mode on/off. Once the in-ear monitoring mode is enabled, one can hear their own voice.

Parameters
modeWhether to switch the in-ear monitoring mode on/off:
  • 0: off
  • 1: on

◆ SetEarMonitorVolume()

static void Pico.Platform.RtcService.SetEarMonitorVolume ( int  volume)
static

Sets the volume for in-ear monitoring.

Parameters
volumeThe target volume. The valid value range from 0 to 400.

◆ SetOnAudioPlaybackDeviceChange()

static void Pico.Platform.RtcService.SetOnAudioPlaybackDeviceChange ( Message< RtcAudioPlaybackDevice >.Handler  handler)
static

Sets the callback to get notified when the audio playback device has been changed.

Parameters
handlerThe callback handler.

◆ SetOnConnectionStateChangeCallback()

static void Pico.Platform.RtcService.SetOnConnectionStateChangeCallback ( Message< RtcConnectionState >.Handler  handler)
static

Sets the callback to get notified when the state of the connection to the RTC server has changed.

Parameters
handlerThe callback handler.

◆ SetOnErrorCallback()

static void Pico.Platform.RtcService.SetOnErrorCallback ( Message< int >.Handler  handler)
static

Sets the callback to get error messages from the RTC engine. The error codes and descriptions are given below.

Error Code Description
-1000 Invalid token.
-1001 Unknown error.
-1002 No permission to publish audio stream.
-1004 A user with the same user Id joined this room. You are kicked out of the room.
-1005 Incorrect configuration on the Developer Platform.
-1070 Subscribing to audio stream failed. Perhaps the number of subscribed audio streams has exceeded the limit.
Parameters
handlerThe callback handler.

◆ SetOnJoinRoomResultCallback()

static void Pico.Platform.RtcService.SetOnJoinRoomResultCallback ( Message< RtcJoinRoomResult >.Handler  handler)
static

Sets the callback of JoinRoom to get RtcJoinRoomResult.

Parameters
handlerThe callback handler.

◆ SetOnLeaveRoomResultCallback()

static void Pico.Platform.RtcService.SetOnLeaveRoomResultCallback ( Message< RtcLeaveRoomResult >.Handler  handler)
static

Sets the callback of LeaveRoom to get RtcLeaveRoomResult.

Parameters
handlerThe callback handler.

◆ SetOnLocalAudioPropertiesReport()

static void Pico.Platform.RtcService.SetOnLocalAudioPropertiesReport ( Message< RtcLocalAudioPropertiesReport >.Handler  handler)
static

Sets the callback to receive local audio report.

Parameters
handlerThe callback handler.

◆ SetOnRemoteAudioPropertiesReport()

static void Pico.Platform.RtcService.SetOnRemoteAudioPropertiesReport ( Message< RtcRemoteAudioPropertiesReport >.Handler  handler)
static

Sets the callback to receive remote audio report.

Parameters
handlerThe callback handler.

◆ SetOnRoomErrorCallback()

static void Pico.Platform.RtcService.SetOnRoomErrorCallback ( Message< RtcRoomError >.Handler  handler)
static

Sets the callback to get error messages from the room.

Parameters
handlerThe callback handler.

◆ SetOnRoomStatsCallback()

static void Pico.Platform.RtcService.SetOnRoomStatsCallback ( Message< RtcRoomStats >.Handler  handler)
static

Sets the callback to regularly get room statistics after joining a room.

Parameters
handlerThe callback handler.

◆ SetOnRoomWarnCallback()

static void Pico.Platform.RtcService.SetOnRoomWarnCallback ( Message< RtcRoomWarn >.Handler  handler)
static

Sets the callback to get warning messages from the room.

Parameters
handlerThe callback handler.

◆ SetOnUserJoinRoomResultCallback()

static void Pico.Platform.RtcService.SetOnUserJoinRoomResultCallback ( Message< RtcUserJoinInfo >.Handler  handler)
static

Sets the callback to get notified when someone has joined the room.

Parameters
handlerThe callback handler.

◆ SetOnUserLeaveRoomResultCallback()

static void Pico.Platform.RtcService.SetOnUserLeaveRoomResultCallback ( Message< RtcUserLeaveInfo >.Handler  handler)
static

Sets the callback to get notified when someone has left the room.

Parameters
handlerThe callback handler.

◆ SetOnUserMuteAudio()

static void Pico.Platform.RtcService.SetOnUserMuteAudio ( Message< RtcMuteInfo >.Handler  handler)
static

Sets the callback to get notified when the user has muted local audio.

Parameters
handlerThe callback handler.

◆ SetOnUserStartAudioCapture()

static void Pico.Platform.RtcService.SetOnUserStartAudioCapture ( Message< string >.Handler  handler)
static

Sets the callback to get notified when the user has started audio capture.

Parameters
handlerThe callback handler.

◆ SetOnUserStopAudioCapture()

static void Pico.Platform.RtcService.SetOnUserStopAudioCapture ( Message< string >.Handler  handler)
static

Sets the callback to get notified when the user has stopped audio capture.

Parameters
handlerThe callback handler.

◆ SetOnWarnCallback()

static void Pico.Platform.RtcService.SetOnWarnCallback ( Message< int >.Handler  handler)
static

Sets the callback to get warning messages from the RTC engine. The warning codes and descriptions are given below.

Warning Code Description
-2001 Joining the room failed.
-2002 Publishing audio stream failed.
-2003 Subscribing to the audio stream failed because the stream cannot be found.
-2004 Subscribing to the audio stream failed due to server error.
-2013 When the people count in the room exceeds 500, the client will not be informed of user join and leave info anymore.
-5001 The camera permission is missing.
-5002 The microphone permission is missing.
-5003 Starting the audio capture device failed.
-5004 Starting the audio playback device failed.
-5005 No available audio capture device.
-5006 No available audio playback device.
-5007 The audio capture device failed to capture valid audio data.
-5008 Invalid media device operation.
Parameters
handlerThe callback handler.

◆ SetPlaybackVolume()

static void Pico.Platform.RtcService.SetPlaybackVolume ( int  volume)
static

Sets the playback volume.

Parameters
volumeThe target volume. The valid value ranges from 0 to 400. 100 indicates keeping the original volume.

◆ StartAudioCapture()

static void Pico.Platform.RtcService.StartAudioCapture ( )
static

Starts audio capture via the microphone.

◆ StopAudioCapture()

static void Pico.Platform.RtcService.StopAudioCapture ( )
static

Stops audio capture.

◆ UnPublishRoom()

static void Pico.Platform.RtcService.UnPublishRoom ( string  roomId)
static

Stops publishing the local audio stream to a room, so others in the same room cannot hear the voice.

Parameters
roomIdThe ID of the room to stop publishing the local audio stream to.

◆ UpdateToken()

static void Pico.Platform.RtcService.UpdateToken ( string  roomId,
string  token 
)
static

Updates the token.
Note: Once a token's ttl is about to expire, you should update the token if you still want to stay in the room.

Parameters
roomIdThe ID of the room you are in.
tokenThe token to update.

The documentation for this class was generated from the following file: