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

rtc_calculate #471

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion src/main/java/com/qiniu/http/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ public static Response createError(okhttp3.Response response, String address, do
address, duration, error, body);
}


public static Response createInvalidArgument( String error) {
return new Response(null, InvalidArgument, "", "", "",
"", 0, error, null);
}
private static String via(okhttp3.Response response) {
String via;
if (!(via = response.header("X-Via", "")).equals("")) {
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/com/qiniu/rtc/RtcRoomManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;

import java.util.Objects;

public class RtcRoomManager {
private final Auth auth;
private final String host;
Expand Down Expand Up @@ -75,6 +77,46 @@ private String getLink(String appId, String roomName, String param) {
return builder.toString();
}

/**
*
* @param appId
* @param roomName
* @param start 开始时间:20200317000000
* @param end 结束时间:20200317200000
* @param G 查询的粒度,可选(5min, hour, day, month),默认为day
* @param total 表示查询房间的总时⻓ int64
* @param kind 表示类型,Audio/SD/HD/UHD string
* @return Response
* @throws QiniuException
*/
public Response getCalculateForRoom(String appId, String roomName, String start, String end, String G, int total, String kind) throws QiniuException {
if (appId == null || roomName == null || start == null || end == null) {
return Response.createInvalidArgument("some request param is null");
}
StringBuilder builder = new StringBuilder();
builder.append(host);
builder.append("/v3/apps/").append(appId).append("/rooms/").append(roomName).append("/metric?");
if (start != null) {
builder.append("start=").append(start).append("&");
}
if (end != null) {
builder.append("end=").append(end);
}
if (G != null) {
builder.append("&granule=").append(G);
}
if (total > 0) {
builder.append("&total=").append(total);
}
if (kind != null) {
builder.append("&kind=").append(kind);
}
String url = builder.toString();
StringMap headers = auth.authorizationV2(builder.toString());
System.out.println("url:"+url);
return client.get(url, headers);
}

/**
* @param appId 房间所属帐号的 app
* @param roomName 房间名称,需满足规格 ^[a-zA-Z0-9_-]{3,64}$
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/test/com/qiniu/rtc/RtcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.qiniu.rtc.RtcAppManager;
import com.qiniu.rtc.RtcRoomManager;
import com.qiniu.util.Auth;
import org.junit.Test;
import test.com.qiniu.TestConfig;


Expand Down Expand Up @@ -95,6 +96,16 @@ public void getRoomToken() {
}
}

@Test
public void getCalculateForRoom(){
try {
Response response =rmanager.getCalculateForRoom("dix05zn6q", "roomtest", "20200317000000", "20200317193000", null,0,null);
System.out.print(getString(response));
} catch (Exception e) {
e.printStackTrace();
}
}

private String getString(Response response) {
String[] resJson = response.getInfo().split("\n");
return response.statusCode + "\n" + resJson[2];
Expand Down