直播禁止推流功能相关问题

什么时候需要禁止推流?

当遇到如下业务场景,例如,对应的鉴权推流地址暴露、客户恶意推流该地址、业务需求禁止该推流URL进行推流等,就可以使用直播的禁止推流功能满足安全需求。

如何实现禁止推流?

  • 直播控制台禁止推流

    • 获取正在推流地址并禁推

      直播推流成功后,您可以在视频直播控制台流管理页面,选择对应的域名,单击查询,查看到正在推流的地址,单击禁推即可。

      002

    • 获取历史推流地址并禁推

      直播推流结束后,您可以在视频直播控制台流管理页面,单击历史流页签,选择对应的域名,单击查询,查看到正在推流的地址,单击禁推即可。

  • SDK实现禁止推流

    视频直播的API是基于阿里云的OpenAPI实现的。因此,SDK的调用也是对OpenAPI封装后调用。下载服务端SDK,请参见服务端SDK。如何使用SDK,请参见SDK使用说明

    Java SDK为例:Java SDK建议使用Maven管理项目依赖,在pom.xml中添加如下的依赖项:

    <dependency>
      <groupId>com.aliyun</groupId>
      <artifactId>alibabacloud-live20161101</artifactId>
      <version>2.0.0</version>
    </dependency>
    说明

    此处SDK版本号仅供参考,获取最新的版本,请参见服务端SDK

    Demo代码主要流程如下:

    1. 初始化Client对象。

      SDK需要通过AsyncClient对象完成对OpenAPI的调用。

    2. 初始化请求Request类。

      SDK对每个接口实现了对应的Request类和Response类,对应的禁止推流Request类需要传入哪些参数。API接口定义请参见禁止推流API

    3. 发起请求获取结果。

    示例代码

    // This file is auto-generated, don't edit it. Thanks.
    package demo;
    
    import com.aliyun.auth.credentials.Credential;
    import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
    import com.aliyun.core.http.HttpClient;
    import com.aliyun.core.http.HttpMethod;
    import com.aliyun.core.http.ProxyOptions;
    import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
    import com.aliyun.sdk.service.live20161101.models.*;
    import com.aliyun.sdk.service.live20161101.*;
    import com.google.gson.Gson;
    import darabonba.core.RequestConfiguration;
    import darabonba.core.client.ClientOverrideConfiguration;
    import darabonba.core.utils.CommonUtil;
    import darabonba.core.TeaPair;
    
    //import javax.net.ssl.KeyManager;
    //import javax.net.ssl.X509TrustManager;
    import java.net.InetSocketAddress;
    import java.time.Duration;
    import java.util.*;
    import java.util.concurrent.CompletableFuture;
    import java.io.*;
    
    public class ForbidLiveStream {
        public static void main(String[] args) throws Exception {
    
            // HttpClient Configuration
            /*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
                    .connectionTimeout(Duration.ofSeconds(10)) // Set the connection timeout time, the default is 10 seconds
                    .responseTimeout(Duration.ofSeconds(10)) // Set the response timeout time, the default is 20 seconds
                    .maxConnections(128) // Set the connection pool size
                    .maxIdleTimeOut(Duration.ofSeconds(50)) // Set the connection pool timeout, the default is 30 seconds
                    // Configure the proxy
                    .proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<YOUR-PROXY-HOSTNAME>", 9001))
                            .setCredentials("<YOUR-PROXY-USERNAME>", "<YOUR-PROXY-PASSWORD>"))
                    // If it is an https connection, you need to configure the certificate, or ignore the certificate(.ignoreSSL(true))
                    .x509TrustManagers(new X509TrustManager[]{})
                    .keyManagers(new KeyManager[]{})
                    .ignoreSSL(false)
                    .build();*/
    
            // Configure Credentials authentication information, including ak, secret, token
            StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                    // Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
                    .accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                    .accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
                    //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // use STS token
                    .build());
    
            // Configure the Client
            AsyncClient client = AsyncClient.builder()
                    .region("<Your ReginId>") // Region ID
                    //.httpClient(httpClient) // Use the configured HttpClient, otherwise use the default HttpClient (Apache HttpClient)
                    .credentialsProvider(provider)
                    //.serviceConfiguration(Configuration.create()) // Service-level configuration
                    // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
                    .overrideConfiguration(
                            ClientOverrideConfiguration.create()
                                      // Endpoint 请参考 https://api.aliyun.com/product/live
                                    .setEndpointOverride("live.aliyuncs.com")
                            //.setConnectTimeout(Duration.ofSeconds(30))
                    )
                    .build();
    
            // Parameter settings for API request
            ForbidLiveStreamRequest forbidLiveStreamRequest = ForbidLiveStreamRequest.builder()
                    .regionId("<Your ReginId>")
                    .domainName("<Your DomainName>")
                    .appName("<Your AppName>")
                    .streamName("<Your StreamName>")
                    // Request-level configuration rewrite, can set Http request parameters, etc.
                    // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
                    .build();
    
            // Asynchronously get the return value of the API request
            CompletableFuture<ForbidLiveStreamResponse> response = client.forbidLiveStream(forbidLiveStreamRequest);
            // Synchronously get the return value of the API request
            ForbidLiveStreamResponse resp = response.get();
            System.out.println(new Gson().toJson(resp));
            // Asynchronous processing of return values
            /*response.thenAccept(resp -> {
                System.out.println(new Gson().toJson(resp));
            }).exceptionally(throwable -> { // Handling exceptions
                System.out.println(throwable.getMessage());
                return null;
            });*/
    
            // Finally, close the client
            client.close();
        }
    
    }

如何查看推流黑名单?

  • 直播控制台查看推流黑名单

    禁推成功后,您可以在视频直播控制台流管理页面,选择对应的域名,单击禁推流页签,单击查询,即可查看被禁推的直播流。

  • SDK获取推流黑名单

    视频直播的API是基于阿里云的OpenAPI实现的。因此,SDK的调用也是对OpenAPI封装后调用。下载服务端SDK,请参见服务端SDK。如何使用SDK,请参见SDK使用说明

    <dependency>
      <groupId>com.aliyun</groupId>
      <artifactId>alibabacloud-live20161101</artifactId>
      <version>2.0.0</version>
    </dependency>
    说明

    此处SDK版本号仅供参考,获取最新的版本,请参见服务端SDK

    Demo代码主要流程如下:

    1. 初始化Client对象。

      SDK需要通过AsyncClient对象完成对OpenAPI的调用。

    2. 初始化请求Request类。

      SDK对每个接口实现了对应的Request类和Response类,对应的禁止推流Request类需要传入哪些参数。API接口定义请参见查询推流黑名单列表API

    3. 发起请求获取结果。

    示例代码

    // This file is auto-generated, don't edit it. Thanks.
    package demo;
    
    import com.aliyun.auth.credentials.Credential;
    import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
    import com.aliyun.core.http.HttpClient;
    import com.aliyun.core.http.HttpMethod;
    import com.aliyun.core.http.ProxyOptions;
    import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
    import com.aliyun.sdk.service.live20161101.models.*;
    import com.aliyun.sdk.service.live20161101.*;
    import com.google.gson.Gson;
    import darabonba.core.RequestConfiguration;
    import darabonba.core.client.ClientOverrideConfiguration;
    import darabonba.core.utils.CommonUtil;
    import darabonba.core.TeaPair;
    
    //import javax.net.ssl.KeyManager;
    //import javax.net.ssl.X509TrustManager;
    import java.net.InetSocketAddress;
    import java.time.Duration;
    import java.util.*;
    import java.util.concurrent.CompletableFuture;
    import java.io.*;
    
    public class DescribeLiveStreamsBlockList {
        public static void main(String[] args) throws Exception {
    
            // HttpClient Configuration
            /*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
                    .connectionTimeout(Duration.ofSeconds(10)) // Set the connection timeout time, the default is 10 seconds
                    .responseTimeout(Duration.ofSeconds(10)) // Set the response timeout time, the default is 20 seconds
                    .maxConnections(128) // Set the connection pool size
                    .maxIdleTimeOut(Duration.ofSeconds(50)) // Set the connection pool timeout, the default is 30 seconds
                    // Configure the proxy
                    .proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<YOUR-PROXY-HOSTNAME>", 9001))
                            .setCredentials("<YOUR-PROXY-USERNAME>", "<YOUR-PROXY-PASSWORD>"))
                    // If it is an https connection, you need to configure the certificate, or ignore the certificate(.ignoreSSL(true))
                    .x509TrustManagers(new X509TrustManager[]{})
                    .keyManagers(new KeyManager[]{})
                    .ignoreSSL(false)
                    .build();*/
    
            // Configure Credentials authentication information, including ak, secret, token
            StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                    // Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
                    .accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                    .accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
                    //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // use STS token
                    .build());
    
            // Configure the Client
            AsyncClient client = AsyncClient.builder()
                    .region("<Your ReginId>") // Region ID
                    //.httpClient(httpClient) // Use the configured HttpClient, otherwise use the default HttpClient (Apache HttpClient)
                    .credentialsProvider(provider)
                    //.serviceConfiguration(Configuration.create()) // Service-level configuration
                    // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
                    .overrideConfiguration(
                            ClientOverrideConfiguration.create()
                                      // Endpoint 请参考 https://api.aliyun.com/product/live
                                    .setEndpointOverride("live.aliyuncs.com")
                            //.setConnectTimeout(Duration.ofSeconds(30))
                    )
                    .build();
    
            // Parameter settings for API request
            DescribeLiveStreamsBlockListRequest describeLiveStreamsBlockListRequest = DescribeLiveStreamsBlockListRequest.builder()
                    .domainName("<Your DomainName>")
                    // Request-level configuration rewrite, can set Http request parameters, etc.
                    // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
                    .build();
    
            // Asynchronously get the return value of the API request
            CompletableFuture<DescribeLiveStreamsBlockListResponse> response = client.describeLiveStreamsBlockList(describeLiveStreamsBlockListRequest);
            // Synchronously get the return value of the API request
            DescribeLiveStreamsBlockListResponse resp = response.get();
            System.out.println(new Gson().toJson(resp));
            // Asynchronous processing of return values
            /*response.thenAccept(resp -> {
                System.out.println(new Gson().toJson(resp));
            }).exceptionally(throwable -> { // Handling exceptions
                System.out.println(throwable.getMessage());
                return null;
            });*/
    
            // Finally, close the client
            client.close();
        }
    
    }

如何恢复黑名单直播流推送地址?

  • 直播控制台恢复

    禁推成功后,您可以在视频直播控制台流管理页面,选择对应的域名,单击禁推流页签,单击恢复,即可恢复被禁推的直播流。

  • SDK恢复

    视频直播的API是基于阿里云的OpenAPI实现的。因此,SDK的调用也是对OpenAPI封装后调用。下载服务端SDK,请参见服务端SDK。如何使用SDK,请参见SDK使用说明

    Java SDK为例:Java SDK建议使用Maven管理项目依赖,在pom.xml中添加如下的依赖项:

    <dependency>
      <groupId>com.aliyun</groupId>
      <artifactId>alibabacloud-live20161101</artifactId>
      <version>2.0.0</version>
    </dependency>
    说明

    此处SDK版本号仅供参考,获取最新的版本,请参见服务端SDK

    Demo代码主要流程如下:

    1. 初始化Client对象。

      SDK需要通过AsyncClient对象完成对OpenAPI的调用。

    2. 初始化请求Request类。

      SDK对每个接口实现了对应的Request类和Response类,对应的恢复推流Request类需要传入哪些参数。API接口定义请参见恢复直播流推送API

    3. 发起请求获取结果。

    示例代码

    // This file is auto-generated, don't edit it. Thanks.
    package demo;
    
    import com.aliyun.auth.credentials.Credential;
    import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
    import com.aliyun.core.http.HttpClient;
    import com.aliyun.core.http.HttpMethod;
    import com.aliyun.core.http.ProxyOptions;
    import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
    import com.aliyun.sdk.service.live20161101.models.*;
    import com.aliyun.sdk.service.live20161101.*;
    import com.google.gson.Gson;
    import darabonba.core.RequestConfiguration;
    import darabonba.core.client.ClientOverrideConfiguration;
    import darabonba.core.utils.CommonUtil;
    import darabonba.core.TeaPair;
    
    //import javax.net.ssl.KeyManager;
    //import javax.net.ssl.X509TrustManager;
    import java.net.InetSocketAddress;
    import java.time.Duration;
    import java.util.*;
    import java.util.concurrent.CompletableFuture;
    import java.io.*;
    
    public class ResumeLiveStream {
        public static void main(String[] args) throws Exception {
    
            // HttpClient Configuration
            /*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
                    .connectionTimeout(Duration.ofSeconds(10)) // Set the connection timeout time, the default is 10 seconds
                    .responseTimeout(Duration.ofSeconds(10)) // Set the response timeout time, the default is 20 seconds
                    .maxConnections(128) // Set the connection pool size
                    .maxIdleTimeOut(Duration.ofSeconds(50)) // Set the connection pool timeout, the default is 30 seconds
                    // Configure the proxy
                    .proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<YOUR-PROXY-HOSTNAME>", 9001))
                            .setCredentials("<YOUR-PROXY-USERNAME>", "<YOUR-PROXY-PASSWORD>"))
                    // If it is an https connection, you need to configure the certificate, or ignore the certificate(.ignoreSSL(true))
                    .x509TrustManagers(new X509TrustManager[]{})
                    .keyManagers(new KeyManager[]{})
                    .ignoreSSL(false)
                    .build();*/
    
            // Configure Credentials authentication information, including ak, secret, token
            StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                    // Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
                    .accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                    .accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
                    //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // use STS token
                    .build());
    
            // Configure the Client
            AsyncClient client = AsyncClient.builder()
                    .region("<Your RegionId>") // Region ID
                    //.httpClient(httpClient) // Use the configured HttpClient, otherwise use the default HttpClient (Apache HttpClient)
                    .credentialsProvider(provider)
                    //.serviceConfiguration(Configuration.create()) // Service-level configuration
                    // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
                    .overrideConfiguration(
                            ClientOverrideConfiguration.create()
                                      // Endpoint 请参考 https://api.aliyun.com/product/live
                                    .setEndpointOverride("live.aliyuncs.com")
                            //.setConnectTimeout(Duration.ofSeconds(30))
                    )
                    .build();
    
            // Parameter settings for API request
            ResumeLiveStreamRequest resumeLiveStreamRequest = ResumeLiveStreamRequest.builder()
                    .domainName("<Your DomainName>")
                    .liveStreamType("<Your LiveStreamType>")
                    .appName("<Your AppName>")
                    .streamName("<Your StreamName>")
                    // Request-level configuration rewrite, can set Http request parameters, etc.
                    // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
                    .build();
    
            // Asynchronously get the return value of the API request
            CompletableFuture<ResumeLiveStreamResponse> response = client.resumeLiveStream(resumeLiveStreamRequest);
            // Synchronously get the return value of the API request
            ResumeLiveStreamResponse resp = response.get();
            System.out.println(new Gson().toJson(resp));
            // Asynchronous processing of return values
            /*response.thenAccept(resp -> {
                System.out.println(new Gson().toJson(resp));
            }).exceptionally(throwable -> { // Handling exceptions
                System.out.println(throwable.getMessage());
                return null;
            });*/
    
            // Finally, close the client
            client.close();
        }
    
    }