"Werewolf" & "Mafia" RTC Integration Guide
The games "Werewolf" and "Mafia" allow players to play games using their voices and set different stages based on the game rules: allowing players to speak, muting players, allowing players to listen to other players, and muting players from listening to other players.
This document provides guidance for integrating the App's own RTC with the games "Werewolf" and "Mafia" (referred to as the games below).
I. Background
Taking hello-sud-plus-android and hello-sud-plus-ios as examples, the source code can be found at:
- Android: https://github.com/SudTechnology/hello-sud-plus-android
- iOS: https://github.com/SudTechnology/hello-sud-plus-ios
hello-sud-plus encapsulates the integration of the SudMGP SDK with SudMGPWrapper. We recommend that the App integrates the SDK using SudMGPWrapper. The voice capabilities provided by the App to players come from the RTC SDK integrated by the App. The game determines when players can speak and listen to others:
- Allowing players to speak: Start RTC streaming
- Muting players: Stop RTC streaming
- Allowing players to listen to other players: Start RTC playback
- Muting players from listening to other players: Stop RTC playback
II. Game Sends "Enable/Disable RTC Playback" State to Allow/Prevent Listening to Other Players
state: mg_common_self_headphone
data:
{
"isOn": true // Headphone (earpiece, speaker) switch state true: On (App starts RTC playback); false: Off (App stops RTC playback)
}
- Android:
The client App implements the SudFSMMGListener interface. In the onGameMGCommonSelfHeadphone method, the App decides whether to start or stop RTC playback based on model.isOn.
// Headphone (earpiece, speaker) state @Override public void onGameMGCommonSelfHeadphone(ISudFSMStateHandle handle, SudMGPMGState.MGCommonSelfHeadphone model) { boolean isOn = model != null && model.isOn; If (isOn) { // Start RTC playback } else { // Stop RTC playback } ISudFSMStateHandleUtils.handleSuccess(handle); }
- iOS: The client App implements the SudFSMMGListener protocol. In the onGameMGCommonGameSelfHeadphone method, the App decides whether to start or stop RTC playback based on model.isOn. ```objc /// Game: Headphone (earpiece, speaker) state MG_COMMON_GAME_SELF_HEADEPHONE
- (void)onGameMGCommonGameSelfHeadphone:(nonnull id
)handle model:(MGCommonGameSelfHeadphone *)model { if (model.isOn) {
} else {// Start RTC playback
} [handle success:[self.sudFSMMGDecorator handleMGSuccess]]; }// Stop RTC playback
## III. Game Sends "Enable/Disable RTC Streaming" State to Allow/Prevent Players from Speaking ```javascript state: mg_common_self_microphone data: { "isOn": true // Microphone switch state true: On (App starts RTC streaming); false: Off (App stops RTC streaming) }
- Android:
The client App implements the SudFSMMGListener interface. In the onGameMGCommonSelfMicrophone method, the App decides whether to start or stop RTC streaming based on model.isOn.
// Microphone state @Override public void onGameMGCommonSelfMicrophone(ISudFSMStateHandle handle, SudMGPMGState.MGCommonSelfMicrophone model) { boolean isOn = model != null && model.isOn; If (isOn) { // Start RTC streaming } else { // Stop RTC streaming } ISudFSMStateHandleUtils.handleSuccess(handle); }
- iOS: The client App implements the SudFSMMGListener protocol. In the onGameMGCommonGameSelfMicrophone method, the App decides whether to start or stop RTC streaming based on model.isOn. ```objc /// Game: Microphone state MG_COMMON_GAME_SELF_MICROPHONE
- (void)onGameMGCommonGameSelfMicrophone:(nonnull id
)handle model:(MGCommonGameSelfMicrophone *)model { if (model.isOn) {
} else {// Start RTC streaming
} [handle success:[self.sudFSMMGDecorator handleMGSuccess]]; } ```// Stop RTC streaming
IV. App Enters Background
If the App is currently streaming, it should actively stop streaming. If the App is currently playing back, it should actively stop playback. Additionally, the App does not need to do anything and does not need to record the streaming status at this time.
V. App Returns to Foreground
The game will send the state changes during the background switch to the App. The App responds to mg_common_self_headphone to decide whether to play back and mg_common_self_microphone to decide whether to stream. No other action is required.