Server-side configuration and operation
The AUI Kits interactive stream AppServer provides backend services, such as logon and live channel management. It works with the AUI Kits interactive stream scenario software development kit (SDK) to help you quickly build interactive stream applications and accelerate business innovation.
How it works
Role of the AppServer
When you use the AUI Kits framework to quickly build services such as interactive live streaming, the scenario SDK needs to connect to ApsaraVideo Live (for standard live streaming and co-streaming), ApsaraVideo VOD (for live recording, optional), and IM services (for interactive messages). The AppServer encapsulates the capabilities of these three products and provides a standardized set of HTTP APIs for the scenario SDK. This reduces your development costs.
You are responsible for deploying and maintaining the AppServer.
In addition to encapsulating the capabilities of the preceding products, the AppServer also implements a live channel management service. This service includes common features such as creating, modifying, and deleting live channels, and starting or ending a live stream.
The AppServer does not directly depend on the APIs provided by ApsaraVideo Live. Instead, it generates ingest and streaming URLs by assembling them according to the ApsaraVideo Live stream ingest and stream pulling protocols. The AppServer also listens for stream ingest status callbacks from ApsaraVideo Live. This resolves issues with incorrect live channel statuses when a streamer exits unexpectedly.
Project framework
Built on the Java 8+ and Spring Boot 2 framework.
Uses Mybatis-Plus for the data persistence layer.
Uses Spring Security and JSON Web Token (JWT) for access control.
Project deployment
Prerequisites
You have completed the steps in Console configuration.
Java 8 is installed in your environment.
Create a database
This example uses MySQL. Manually create a database and run the following SQL statement.
CREATE TABLE `room_infos` (
`id` varchar(256) NOT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`title` varchar(256) DEFAULT NULL,
`anchor` varchar(256) DEFAULT NULL,
`extends` mediumtext,
`status` bigint DEFAULT NULL,
`mode` bigint DEFAULT NULL,
`chat_id` varchar(256) DEFAULT NULL,
`pk_id` varchar(256) DEFAULT NULL,
`notice` varchar(256) DEFAULT NULL,
`meeting_id` varchar(256) DEFAULT NULL,
`cover_url` varchar(256) DEFAULT NULL,
`anchor_id` varchar(256) DEFAULT NULL,
`anchor_nick` varchar(256) DEFAULT NULL,
`vod_id` varchar(256) DEFAULT NULL,
`meeting_info` mediumtext,
`started_at` datetime DEFAULT NULL,
`stopped_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_create_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;The table is created as follows.

Deploy from source code
This example shows how to build and deploy the AppServer from the source code. Follow the instructions in the source code to configure and run the AppServer. For more information, see AUI Kits Live AppServer.
When you deploy the server for the first time, you must edit the code/src/main/java/com/aliyuncs/aui/common/utils/JwtUtils.java file and set the `SECRET` property to a random string.
Project parameter settings
Download the interactive stream source code to your server.
Open the
application.ymlfile in theServer\Java\code\src\main\resourcesdirectory of the source code and configure the parameters.Parameter settings
Description
server: port: 8080The default listener port is 8080. You can change it as needed.
# DB connection information, connect to a MySQL database url: jdbc:mysql://******:3306/*****?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai username: "******" password: "******"jdbc:mysql://<Hostname or IP address of the MySQL database server>:3306/<Database name>?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghaiusername: Database username
password: Database password
# POP configuration. You must configure the AccessKey ID and AccessKey secret of your account to call IM and VOD services. openapi: access: key: "*********" secret: "*********" region_id: cn-shanghaiWhen you call Alibaba Cloud IM and ApsaraVideo VOD service APIs, you must use an AccessKey for identity verification. An AccessKey includes an AccessKey ID and an AccessKey secret. Details are as follows:
AccessKey ID: Used to identify the user.
AccessKey secret: The key used to authenticate the user. You must keep your AccessKey secret confidential.
For more information, see Create an AccessKey.
`region_id` is the ApsaraVideo VOD center configuration. In the demo code, the default VOD center is Shanghai. For other regions, see Region IDs.
# Application ID for the IM service new_im: appId: "*********" appKey: "*********" appSign: "*********"For the interactive message AppId, AppKey, and AppSign, see Create an interactive message application.
# Live stream ingest and pulling configuration live_stream: #Ingest domain push_url: push.*****.vip #Stream pulling domain pull_url: pull.*****.vip #The auth key that corresponds to the ingest domain push_auth_key: zJl4****** #The auth key that corresponds to the stream pulling domain pull_auth_key: mDZs******** app_name: live auth_expires: 604800push_url: Ingest domain
pull_url: Stream pulling domain
push_auth_key: The primary authentication KEY for the ingest domain.
pull_auth_key: The primary authentication Primary Key for the streaming domain.
app_name: The AppName in the transcoded live stream URL. The default value is live. You can customize it.
NoteTo attach transcoding, recording, or snapshot templates to the transcoded stream, set this AppName to be the same as the AppName in the template. This ensures the template takes effect.
For more information, see Console configuration.
# Co-streaming application information live_mic: app_id: 7c61******** app_key: c461b*********For the co-streaming Application ID and AppKey, see Create an ApsaraVideo Real-time Communication application.
# authKey for stream ingest status callback live_callback: auth_key: avdsd*******To monitor the ingest status of an ingest URL, configure this parameter. For more information about how to obtain the parameter value, see Callback settings.
# Configure the domain names that are allowed for cross-origin requests http: cors: host: "*"When you use this service on the web, correctly set Cross-Origin Resource Sharing (CORS) to allow cross-origin requests.
Service-oriented authentication configuration
This project requires you to first call the /login API to obtain an authentication token. Then, add the token to the request header before calling other APIs. However, the token generation method in this project is simple and suitable only for testing. When you develop based on the demo, you must adjust the authentication policy. You can implement the authentication configuration based on your business needs. You can also customize the token generation algorithm. Make sure that the same algorithm is used to generate and verify tokens.
The code for the authentication token is located in the code/src/main/java/com/aliyuncs/aui/common/utils/JwtUtils.java file.
For more information about the /login API, see Logon API details.
Package and run the project
Packaging
You can use the built-in Maven in IntelliJ IDEA to package the project. The generated JAR file is located in the target directory.
Navigate to the
Server\Java\codepath and run the following command to package the project.mvn package -DskipTestsCopy the JAR package from the
targetdirectory to the server.scp xxx.jar root@ip:/root
Run the project
Open a terminal in the directory that contains the JAR package.
The application runs in and prints logs to the terminal.
java -jar ***.jarThe process runs in the background and writes the logs to the nohup.out file.
nohup java -jar ***.jar &Verify that the project started successfully.
Access the relevant API. If a response similar to the one in the following figure is returned, the AppServer has started successfully.
{ "success": true, "data": "The deployment is successful and the address can be accessed normally http://xxx.ost" }