Skip to content

[qvs]add stopStream and delete check argument #479

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

Merged
merged 12 commits into from
Sep 11, 2020
115 changes: 115 additions & 0 deletions src/main/java/com/qiniu/qvs/DeviceManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package com.qiniu.qvs;

import com.qiniu.common.QiniuException;
import com.qiniu.qvs.model.Device;
import com.qiniu.qvs.model.PatchOperation;
import com.qiniu.http.Client;
import com.qiniu.http.Response;
import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;
import com.qiniu.util.UrlUtils;

public class DeviceManager {

private final String apiServer;
private final Client client;
private final Auth auth;

public DeviceManager(Auth auth) {
this(auth, "http://qvs.qiniuapi.com");
}

public DeviceManager(Auth auth, String apiServer) {
this(auth, apiServer, new Client());
}

public DeviceManager(Auth auth, String apiServer, Client client) {
this.auth = auth;
this.apiServer = apiServer;
this.client = client;
}


/*
* 创建设备
*/
public Response createDevice(String namespaceId, Device device) throws QiniuException {
StringMap params = new StringMap();
params.put("name", device.getName());
params.put("gbId", device.getGbId());
params.putNotNull("username", device.getUsername());
params.putNotNull("password", device.getPassword());
params.put("pullIfRegister", device.isPullIfRegister());
params.put("desc", device.getDesc());

String url = String.format("%s/v1/namespaces/%s/devices", apiServer, namespaceId);
return QvsResponse.post(url, params, client, auth);
}

/*
* 删除设备
*/
public Response deleteDevice(String namespaceId, String gbId) throws QiniuException {
String url = String.format("%s/v1/namespaces/%s/devices/%s", apiServer, namespaceId, gbId);
return QvsResponse.delete(url, client, auth);
}

/*
* 更新设备
*/
public Response updateDevice(String namespaceId, String gbId, PatchOperation[] patchOperation)
throws QiniuException {
StringMap params = new StringMap().put("operations", patchOperation);
String url = String.format("%s/v1/namespaces/%s/devices/%s", apiServer, namespaceId, gbId);
return QvsResponse.patch(url, params, client, auth);
}

/*
* 查询设备
*/
public Response queryDevice(String namespaceId, String gbId) throws QiniuException {
String url = String.format("%s/v1/namespaces/%s/devices/%s", apiServer, namespaceId, gbId);
return QvsResponse.get(url, client, auth);
}

/*
* 获取设备列表
*/
public Response listDevice(String namespaceId, int offset, int line, String prefix, String state, int qtype)
throws QiniuException {
String requestUrl = String.format("%s/v1/namespaces/%s/devices", apiServer, namespaceId);
StringMap map = new StringMap().put("offset", offset).put("line", line).put("qtype", qtype)
.put("prefix", prefix).put("state", state);
requestUrl = UrlUtils.composeUrlWithQueries(requestUrl, map);
return QvsResponse.get(requestUrl, client, auth);
}

/*
* 获取通道列表
*/
public Response listChannels(String namespaceId, String gbId, String prefix) throws QiniuException {
String requestUrl = String.format("%s/v1/namespaces/%s/devices/%s/channels", apiServer, namespaceId, gbId);
StringMap map = new StringMap().put("prefix", prefix);
requestUrl = UrlUtils.composeUrlWithQueries(requestUrl, map);
return QvsResponse.get(requestUrl, client, auth);
}

/*
* 启动设备拉流
*/
public Response startDevice(String namespaceId, String gbId, String[] channels) throws QiniuException {
String url = String.format("%s/v1/namespaces/%s/devices/%s/start", apiServer, namespaceId, gbId);
StringMap params = new StringMap().put("channels", channels);
return QvsResponse.post(url, params, client, auth);
}

/*
* 停止设备拉流
*/
public Response stopDevice(String namespaceId, String gbId, String[] channels) throws QiniuException {
String url = String.format("%s/v1/namespaces/%s/devices/%s/stop", apiServer, namespaceId, gbId);
StringMap params = new StringMap().put("channels", channels);
return QvsResponse.post(url, params, client, auth);
}

}
7 changes: 5 additions & 2 deletions src/main/java/com/qiniu/qvs/NameSpaceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public Response createNameSpace(NameSpace nameSpace) throws QiniuException {
params.putNotNull("snapshotTemplateId", nameSpace.getSnapShotTemplateId());
params.putNotNull("recordTemplateApplyAll", nameSpace.isRecordTemplateApplyAll());
params.putNotNull("snapshotTemplateApplyAll", nameSpace.isSnapTemplateApplyAll());
params.putNotNull("urlMode", nameSpace.getUrlMode());
params.putNotNull("zone", nameSpace.getZone());
params.putNotNull("hlsLowLatency", nameSpace.isHlsLowLatency());

String url = String.format("%s/v1/namespaces", apiServer);
return QvsResponse.post(url, params, client, auth);
Expand Down Expand Up @@ -96,15 +99,15 @@ public Response listNameSpace(int offset, int line, String sortBy) throws QiniuE
*/
public Response disableNameSpace(String namespaceId) throws QiniuException {
String url = String.format("%s/v1/namespaces/%s/disabled", apiServer, namespaceId);
return QvsResponse.post(url, null, client, auth);
return QvsResponse.post(url, new StringMap(), client, auth);
}

/*
启用空间API
*/
public Response enableNameSpace(String namespaceId) throws QiniuException {
String url = String.format("%s/v1/namespaces/%s/enabled", apiServer, namespaceId);
return QvsResponse.post(url, null, client, auth);
return QvsResponse.post(url, new StringMap(), client, auth);
}


Expand Down
102 changes: 98 additions & 4 deletions src/main/java/com/qiniu/qvs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
- [x] 启用流: enableStream(String namespaceId, String streamId)
- [x] 查询推流记录: queryStreamPubHistories(String namespaceId, String streamId, int start, int end, int offset, int line)

- 设备管理
- [x] 创建设备: createDevice(String namespaceId, Device device)
- [x] 删除设备: deleteDevice(String namespaceId, String gbId)
- [x] 更新设备: updateDevice(String namespaceId, String gbId, PatchOperation[] patchOperation)
- [x] 查询设备信息: queryDevice(String namespaceId, String gbId)
- [x] 获取设备列表: listDevice(String namespaceId, int offset, int line, String prefix, String state, int qtype)
- [x] 获取通道列表: listChannels(String namespaceId, String gbId, String prefix)
- [x] 启动设备拉流: startDevice(String namespaceId, String gbId, String channels)
- [x] 停止设备拉流: stopDevice(String namespaceId, String gbId, String channels)

- 模板管理
- [x] 创建模板: createTemplate(Template template)
- [x] 删除模板: deleteTemplate(String templateId)
Expand Down Expand Up @@ -66,20 +76,31 @@
* [启用流](#启用流)
* [删除流](#删除流)

- [设备管理](#设备管理)

- [创建设备](#创建设备)
- [删除设备](#删除设备)
- [查询设备](#查询设备)
- [更新设备](#更新设备)
- [获取设备列表](#获取设备列表)
- [获取通道列表](#获取通道列表)
- [启动设备拉流](#启动设备拉流)
- [停止设备拉流](#停止设备拉流)

- [模板管理](#模板管理)

* [创建模板](#创建模板)
* [查询模板](#查询模板)
* [更新模板](#更新模板)
* [获取模板列表](#获取模板列表)
* [删除模板](#删除模板)

- [录制管理](#录制管理)

- [查询录制记录](#查询录制记录)
- [查询流封面](#查询流封面)
- [获取截图列表](#获取截图列表)



## Usage
Expand Down Expand Up @@ -249,6 +270,79 @@ streamManager.enableStream(namespaceId, stream.getStreamID());
streamManager.deleteStream(namespaceId, stream.getStreamID());
```

### 设备管理

#### 创建设备

```
// 创建设备
DeviceManager deviceManager = new DeviceManager(auth);
Device device = new Device();
device.setUsername("admin");
device.setPassword("QQQNNN111");

String namespaceId = "3nm4x0v0h6vjr";
deviceManager.createDevice(namespaceId, device);
```

#### 删除设备

```
deviceManager.deleteDevice(namespaceId, device.getGbId());
```

#### 查询设备

```
// 查询设备
device.setGbId("31011500991320000056");

deviceManager.queryDevice(namespaceId, device.getGbId());
```

#### 更新设备

```
// 更新设备
PatchOperation[] patchOperation = {new PatchOperation("replace", "name", "GBTEST")};

deviceManager.updateDevice(namespaceId, device.getGbId(), patchOperation);
```

#### 获取设备列表

```
// 获取设备列表
int offset = 0;
int line = 3;
int qtype = 0;
String prefix = "310";
String state = "notReg";

deviceManager.listDevice(namespaceId, offset, line, prefix, state, qtype);
```

#### 获取通道列表

```
// 禁用空间
deviceManager.listChannels(namespaceId, device.getGbId(), prefix);
```

#### 启动设备拉流

```
// 启动设备拉流
deviceManager.startDevice(namespaceId, device.getGbId(), "31011500991320000056");
```

#### 停止设备拉流

```
// 停止设备拉流
deviceManager.stopDevice(namespaceId, device.getGbId(), "31011500991320000056");
```



### 模板管理
Expand Down
25 changes: 11 additions & 14 deletions src/main/java/com/qiniu/qvs/StreamManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,36 +116,30 @@ public Response dynamicPublishPlayURL(String namespaceId, String streamId, Dynam
*/
public Response disableStream(String namespaceId, String streamId) throws QiniuException {
String url = String.format("%s/v1/namespaces/%s/streams/%s/disabled", apiServer, namespaceId, streamId);
return QvsResponse.post(url, null, client, auth);
return QvsResponse.post(url, new StringMap(), client, auth);
}

/*
启用流API
*/
public Response enableStream(String namespaceId, String streamId) throws QiniuException {
String url = String.format("%s/v1/namespaces/%s/streams/%s/enabled", apiServer, namespaceId, streamId);
return QvsResponse.post(url, null, client, auth);
return QvsResponse.post(url, new StringMap(), client, auth);
}

// 查询推流历史记录
public Response queryStreamPubHistories(String namespaceId, String streamId, int start, int end, int offset, int line) throws QiniuException {
if (start <= 0 || end < 0 || (start >= end && end != 0)) {
throw new QiniuException(new IllegalArgumentException("bad argument" + start + "," + end));
}
String requestUrl = String.format("%s/v1/namespaces/%s/streams/%s/pubhistories", apiServer, namespaceId, streamId);
StringMap map = new StringMap().put("start", start).put("end", end).
StringMap map = new StringMap().putNotNull("start", start).putNotNull("end", end).
putNotNull("offset", offset).putNotNull("line", line);
requestUrl = UrlUtils.composeUrlWithQueries(requestUrl, map);
return QvsResponse.get(requestUrl, client, auth);
}

// 查询录制记录
public Response queryStreamRecordHistories(String namespaceId, String streamId, int start, int end, int line, String marker) throws QiniuException {
if (start <= 0 || end < 0 || (start >= end && end != 0)) {
throw new QiniuException(new IllegalArgumentException("bad argument" + start + "," + end));
}
String requestUrl = String.format("%s/v1/namespaces/%s/streams/%s/recordhistories", apiServer, namespaceId, streamId);
StringMap map = new StringMap().put("start", start).put("end", end)
StringMap map = new StringMap().putNotNull("start", start).putNotNull("end", end)
.putNotNull("line", line).putNotEmpty("marker", marker);
requestUrl = UrlUtils.composeUrlWithQueries(requestUrl, map);
return QvsResponse.get(requestUrl, client, auth);
Expand All @@ -159,13 +153,16 @@ public Response queryStreamCover(String namespaceId, String streamId) throws Qin

// 获取截图列表
public Response streamsSnapshots(String namespaceId, String streamId, int start, int end, int type, int line, String marker) throws QiniuException {
if (start <= 0 || end < 0 || (start >= end && end != 0)) {
throw new QiniuException(new IllegalArgumentException("bad argument" + start + "," + end));
}
String requestUrl = String.format("%s/v1/namespaces/%s/streams/%s/snapshots", apiServer, namespaceId, streamId);
StringMap map = new StringMap().put("start", start).put("end", end)
StringMap map = new StringMap().putNotNull("start", start).putNotNull("end", end)
.putNotNull("line", line).putNotEmpty("marker", marker).put("type", type);
requestUrl = UrlUtils.composeUrlWithQueries(requestUrl, map);
return QvsResponse.get(requestUrl, client, auth);
}

// 停用流
public Response stopStream(String namespaceId, String streamId) throws QiniuException {
String url = String.format("%s/v1/namespaces/%s/streams/%s/stop", apiServer, namespaceId, streamId);
return QvsResponse.post(url, new StringMap(), client, auth);
}
}
58 changes: 58 additions & 0 deletions src/main/java/com/qiniu/qvs/model/Device.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.qiniu.qvs.model;

public class Device {
private String name;// 设备名称(可包含 字母、数字、中划线、下划线;1 ~ 100 个字符长)
private String gbId; // 设备国标ID
private String username; // 用户名, 4~40位,可包含大写字母、小写字母、数字、中划线,建议与设备国标ID一致
private String password; // 密码, 4~40位,可包含大写字母、小写字母、数字、中划线
private boolean pullIfRegister; // 注册成功后启动拉流, 默认关闭
private String desc;// 关于设备的描述信息

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getGbId() {
return gbId;
}

public void setGbId(String gbId) {
this.gbId = gbId;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public boolean isPullIfRegister() {
return pullIfRegister;
}

public void setPullIfRegister(boolean pullIfRegister) {
this.pullIfRegister = pullIfRegister;
}

public String getDesc() {
return desc;
}

public void setDesc(String desc) {
this.desc = desc;
}
}
Loading