📃 article shall be produced from the machine and become a family spirit. – Wei Shou
First, demand background
In recent years, the number of online voice chat users continues to rise. The information density of voice is richer than that of text and picture, and simpler than that of video. It can be regarded as an effective way to grasp the new era users and realize traffic realization. In the field of stranger social networking, in order to meet the emotional needs and entertainment needs of users, Xiaoyu company also launched the function of voice room in its own application.
Two, what is the voice room
-
What is social voice room?
Voice room is a one-to-one voice phone, voice chat based on a multi-person chat exchange scene; Voice interaction between multiple people in a room is different from sending voice messages. It is similar to a multi-person voice phone and can be exchanged in real time.
-
What can a social voice room do?
The core purpose of the voice room in social communication must be to promote the communication between users and quickly improve the relationship between users. Voice room can be through the way of simultaneous conversation; It is more emotional than text and voice messages, and more direct for users to communicate emotionally. Can achieve: pure voice chat, game interaction, emotional radio, online KTV and other scenes.
Iii. Function Description
-
Scene change
The function of voice room can fit the KTV scene in life, and it can also realize the online song room in practical application.
- KTV rooms are isolated from each other (don’t drill), different rooms are unable to hear the sound; The voice room is the same, each room isolated from each other, no contact.
- The number of mics in the KTV room is limited, and the number of mics provided in the voice room is limited.
- The number of people in the KTV room can be much larger than the number of people who can get the microphone to sing; The number of people in the voice room is also much larger than the number of people who can speak and sing on the microphone.
- When holding a microphone in a KTV room, you can sing selectively; In the voice room, users can choose not to speak.
- The limited microphones in KTV are mobile, not just a few people can sing; The upper and lower mic of the voice room is the flow of the limited mic, the number of mic remains the same, but the person holding the mic can change.
-
Functional description
-
Create an Audio room
-
First, we need to play the voice room. We need to create a room. To create a room, we need to set some basic information of the room, as shown in the picture below:
When creating a room, you can customize the room name or randomly obtain the room name provided by the system.
-
Create a flow chart for the audio room
After completing the room information, you need the last step to create a successful room; Click Create, the client requests the server interface room to be created. The internal flow of the server is as follows:
In the process of room initialization, the server only stores the data set by the user and initializes the room mic information. And generate the corresponding room and the corresponding RTC channel ID back to the client, the client to create channel information and other operations.
-
Basic Room Information
-- ----------------------------
-- Table structure for room
-- ----------------------------
DROP TABLE IF EXISTS `room`;
CREATE TABLE `room` (
`room_id` bigint(20) NOT NULL,
`app_id` bigint(20) NOT NULL,
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Creation time',
`update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Update Time',
`administrators` varchar(1000) DEFAULT NULL COMMENT 'Roommaster Info',
`last_close_time` bigint(20) DEFAULT NULL COMMENT 'Unix timestamp, last closing time',
`last_open_time` bigint(20) DEFAULT NULL COMMENT 'Unix timestamp, last time of business',
`mic_mode` varchar(255) NOT NULL COMMENT 'Mai On Mode (Free Mai on/Application Mai on Mode)',
`roomIcon` varchar(255) DEFAULT NULL COMMENT 'Show pictures outside the room',
`room_desc` varchar(1000) DEFAULT NULL COMMENT 'Room Bulletin',
`room_layout` int(11) DEFAULT 8 COMMENT 'Number of rooms',
`room_name` varchar(255) DEFAULT NULL COMMENT 'Room Name',
`room_number` int(11) NOT NULL COMMENT 'Room Number (Filter)',
`room_source` varchar(255) NOT NULL COMMENT 'The channel through which the room is created, can also be thought of as the subject of ownership of the room.',
`room_type` varchar(255) NOT NULL COMMENT 'Text room: ROOM_TYPE_TEXT, voice room: ROOM_TYPE_VOICE',
`room_status` varchar(255) NOT NULL COMMENT 'On: ROOM_STATUS_OPEN, off: ROOM_STATUS_CLOSE, banned: ROOM_STATUS_BANNED',
`room_tag` varchar(255) DEFAULT NULL COMMENT 'Room Sign',
`room_owner_user_id` bigint(20) DEFAULT NULL COMMENT 'the owner id',
`room_owner_organization_id` bigint(20) DEFAULT NULL COMMENT 'organization id',
`channel_id` bigint(20) DEFAULT NULL COMMENT 'Room's unique channel information for a third party'.PRIMARY KEY (`room_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;
Copy the code
- The basic room information and the administrator are also placed in the table, resulting in a large number of fields in the table. In addition, when you modify the administrator, the basic room information will be changed. In fact, you can remove the administrator information.
- Mic_mode: controls the mic access mode of a room user. For example, to apply for the mic access mode, the user needs to apply for the mic access mode and the administrator/owner agrees.
- Room_layout: Controls the number of mic slots that can be connected to a room and modifies the number of mic slots within a specified range.
- Room_source: channel for room creation. Each user can create a room in a different channel. The advantage of this is that you can use chat rooms in different scenarios supported by an application.
- Room_number: indicates the number of the room. If you filter out the number of the room, you can operate the number of the room.
- Room_owner_organization_id: Create channel (room_source) If the organization type is room_owner_organization_id, store the organization ID of the user.
- Room_game: New gameplay can be added to the room base, such as auction, wedding, etc.
-
Create a voice room interface
api: /api/room/room-message // Get room information based on the room ID first (if no room information is available, return the default parameter value)
/* Pass the argument (based on the caller ID and the room type to get whether the room was created and the room information, If this type of room has not been created, return the default parameters (the picture is the creator's avatar, the room display type is normal, and the tag is dating and dating room by default)
Long roomId
api: /api/room/operation-room // Create/edit room
/* Pass in the room ID */
Long roomId
/* (RoomTag ROOM_TAG_FRIEND ROOM_TAG_TALK ROOM_TAG_AUCTION) */
String tag
/* Room name */
String name
/* Room announcement */
String announcement
/* Room background */
String coverUrl
/* Queue mode MIC_MODE_FREEDOM MIC_MODE_QUEUE queue */
String mode
/* Room display type SECRET_ROOM GENERAL_ROOM */
String subType
/* the number of slots is in the default 8-bit range [4,12] */
Integer boothSize
Copy the code
-
On wheat
First of all, as shown in the figure below, the mode of loading is divided into free mode loading and queuing mode loading. In the free mode, as the name implies, as long as there is no user in the room, you can click on the wheat; Queuing mode is for ordinary users (except administrators/homeowners), who cannot directly access the mic. After clicking the mic button, they will enter the mic queue and wait for the consent of administrators/homeowners (only administrators/homeowners have the permission in the mic queue) before they can access the mic according to the rules of the mic.
Secondly, the type of wheat is divided into active wheat and passive wheat, which is distinguished from the perspective of development. User active click on the operation is called active on the wheat; The user is invited by the administrator or host to join the mic. The user clicks “yes” to join the mic. Passive mic is shown below:
-
Flow chart of loading
During the process, users’ permissions need to be verified, and they need to be added or queued according to the current room mode and the policy mode selected by the service party (for example, sending the MCS by role position or sending the MCS by position in reverse order). Finally, you need to send the data on the room mic to send RTM to the client for rendering.
-
M a information
-- ----------------------------
-- Table structure for room_booth
-- ----------------------------
DROP TABLE IF EXISTS `room_booth`;
CREATE TABLE `room_booth` (
`room_booth_id` bigint(20) NOT NULL,
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Creation time',
`update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Update Time',
`booth_abilities` varchar(255) NOT NULL COMMENT 'Host mic bit: BOOTH_ABILITIES_HOST, common MIC bit: BOOTH_ABILITIES_NORMAL',
`booth_index` int(11) NOT NULL COMMENT 'Booth position',
`room_id` bigint(20) NOT NULL,
`user_id` bigint(20) DEFAULT NULL COMMENT 'Current user in booth',
`booth_status` varchar(50) DEFAULT NULL COMMENT 'Booth Sound state',
`status` varchar(50) DEFAULT NULL COMMENT 'Data state'.PRIMARY KEY (`room_booth_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;
Copy the code
The mic bit information is based on the room dimension, not the user dimension. When the service party calls to initialize the room, the service party controls how many mics the room initializes.
- Booth_index: indicates the subscript of the current position.
- Booth_abilities: current wheat bit type. The service party controls the data of the wheat bit and the corresponding wheat bit type. Has to do with the strategy of getting on the mic.
-
The wheat interface
api: /api/room/set-seat // Mic/mic (call this interface for mic related items and perform corresponding logical operations according to the current mic mode of the room)
/* Pass the argument voice room ID */
Long roomId
/* By default, if the mic bit is not transmitted, the mic is uploaded in reverse order. The serial number starts from 0. 0 indicates the first position */Integer seatNum API: / API /room/invite-set-seat seatNum API: / API /room/invite-set-seat seatNum API: / API /room/invite-set-seat seatNum API: / API /room/invite-set-seat seatNum API: / API /room/invite-set-seat seatNum API: / API /room/invite-set-seat seatNum API: / API /room/invite-set-seat seatNum API: / API /room/invite-set-seat/* The passed parameter is carried to the mic user ID */
Long userId
/* Voice room ID */
Long roomId
Copy the code
-
Relevant concepts
-
Voice room
Voice communication gameplay that allows single/multi-person voice chat or entertainment within a room channel.
-
RTM message
Through the way similar to typing interaction in the room, the server and the client use an agreed format to realize the communication of corresponding instructions, so as to achieve the corresponding actions of the client according to specific instructions.
-
RTC
It can be understood that a voice room corresponds to an RTC channel. If a voice needs to be heard or emitted in the voice room, it needs to be added to the channel first. It’s like two people calling each other
-
Up/down of wheat
Join chat and quit chat according to the number of mic slots provided in the voice room; Users who are not on the mic cannot transmit their voices to the channel so that other users in the voice room can hear them.
-
Open/close your mic
After logging in to the mic, users are provided with the option to turn on/off their microphone and choose whether to transmit the sound to the channel.
-
Active/passive behavior
Active behavior can be understood as triggering an action, which can be completed by the user himself. For example, in free on/off mode, on/off mode, join/leave channel, and so on.
Passive behavior can be understood as an action that can not be completed by the user, but needs to be notified to the corresponding user and triggered by another user. For example: hold the wheat/hold the wheat, ban the wheat/lift the wheat, etc.
Iv. Technical Scheme
-
purpose
The construction of the voice room function this time is not simply to achieve this capability, but to make the voice room function into a new platform module, which is convenient for the rapid access of new products and zero workload of the server, so as to reduce the cost of launching new products and improve the efficiency of function access.
-
design
-
User roles
-
- Owner: The creator of the voice room, the owner of the room, has the highest privileges; Rooms are bound to users. A user can only create one live broadcast room under one type.
- Administrator: The administrator of a room is controlled by the owner. A room can have multiple administrators, and a user can also be the administrator of multiple rooms.
- MAC user: a user who has joined the RTC channel and is able to talk and communicate in the room.
- Audience: a subscriber who has joined the RTC channel and can only hear the room but cannot speak.
-
interaction
-
Interactive flow chart
-
The architecture process client needs to call the business side first, and then the business side calls the voice room service. The voice room service returns relevant results and sends the RTM notification of the specified template to the client. In the figure, gift-related functions are handled by gold gift-related services.
-
Problems and Solutions
-
Ghost mic problem
Reason: Because the whole logic involves three parties, the client, the server and the audio network, it will involve the data synchronization between the server and the audio network. There are several reasons for the phantom mic problem:
- The server successfully updated user A’s operation on the mic, but something happened when the client called the SDK operation of sonnet. As a result, there was user A’s avatar on the mic, but it was actually a mute mic.
- User A is on the MAC, and the APP process is directly killed. The server does not receive the callback message due to abnormal service or other reasons. As a result, user A is on the MAC, but has actually left the APP and is a ghost MAC.
Scheme: as a whole, there are false user data on the mic; When the room manager or the owner finds that the user is a ghost mic, the host will hold the mic, which will have a frequency-related policy. The server verifies the relationship between the user and the current channel according to the policy and the sound network, and does not clear the current channel.
-
Five, the summary
At present, many social software on the market have the function of multi-person voice chat, which reflects that this function is more capable of allowing strangers to have deeper experience and communication and rapidly warming up in the field of stranger social communication. On the basis of the basic ability of this function, we can continue to improve the gameplay of the audio room, which can be a game or a variety of process-oriented interaction; I believe that in the future for a period of time, multiplayer voice room gameplay will be recognized by more users. In the future, we will continue to introduce voice room gameplay to enrich user experience.