Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LINK-1449 java sdk提供静态接入模式下,rtmp,hls,flv的地址生成 #494

Open
wants to merge 3 commits into
base: hugo
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/main/java/com/qiniu/qvs/model/StaticLiveRoute.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.qiniu.qvs.model;

import com.qiniu.common.Constants;
import com.qiniu.util.Md5;
import com.qiniu.util.UrlSafeBase64;

public class StaticLiveRoute {

private String domain; // 域名
Expand Down Expand Up @@ -40,4 +44,35 @@ public int getUrlExpireSec() {
public void setUrlExpireSec(int urlExpireSec) {
this.urlExpireSec = urlExpireSec;
}

public String genStaticHLSFLVDomain(String nsId, String streamId, String key, boolean useHttps) {
String path = "/" + nsId + "/" + streamId;
String scheme = useHttps ? "https" : "http";
String host = "";
if ("liveHls".equals(domainType)) {
host = domain + ":1370";
path += ".m3u8";
} else {
host = domain + ":1360";
path += ".flv";
}
long expireTime = System.currentTimeMillis() + urlExpireSec * 1000;
String token = signToken(key, path, expireTime);
return String.format("%s://%s%s?e=%d&token=%s", scheme, host, path, expireTime, token);
}

public String genStaticRtmpDomain(String nsId, String streamId, String key) {
String path = "/" + nsId + "/" + streamId;
String scheme = "rtmp";
String host = domain + ":2045";
long expireTime = System.currentTimeMillis() + urlExpireSec * 1000;
String token = signToken(key, path, expireTime);
return String.format("%s://%s%s?e=%d&token=%s", scheme, host, path, expireTime, token);
}

private String signToken(String key, String path, long expireTime) {
String encode_path = UrlSafeBase64.encodeToString(path);
String tempS = key + encode_path + Long.toHexString(expireTime);
return Md5.md5(tempS.getBytes(Constants.UTF_8));
}
}