Skip to content

Commit adaa9a6

Browse files
committed
qvs add readme and test
1 parent 70ca4e6 commit adaa9a6

File tree

3 files changed

+260
-15
lines changed

3 files changed

+260
-15
lines changed

src/main/java/com/qiniu/qvs/DeviceManager.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public DeviceManager(Auth auth, String apiServer, Client client) {
2929
this.client = client;
3030
}
3131

32+
33+
/*
34+
* 创建设备
35+
*/
3236
public Response createDevice(String namespaceId, Device device) throws QiniuException {
3337
StringMap params = new StringMap();
3438
params.put("name", device.getName());
@@ -79,24 +83,24 @@ public Response listDevice(String namespaceId, int offset, int line, String pref
7983
requestUrl = UrlUtils.composeUrlWithQueries(requestUrl, map);
8084
return QvsResponse.get(requestUrl, client, auth);
8185
}
82-
86+
8387
/*
84-
* 获取通道列表
85-
*/
86-
public Response listChannels(String namespaceId, String gbId, String prefix) throws QiniuException {
87-
String requestUrl = String.format("%s/v1/namespaces/%s/devices/%s/channels", apiServer, namespaceId, gbId);
88-
StringMap map = new StringMap().put("prefix", prefix);
89-
requestUrl = UrlUtils.composeUrlWithQueries(requestUrl, map);
90-
return QvsResponse.get(requestUrl, client, auth);
91-
}
88+
* 获取通道列表
89+
*/
90+
public Response listChannels(String namespaceId, String gbId, String prefix) throws QiniuException {
91+
String requestUrl = String.format("%s/v1/namespaces/%s/devices/%s/channels", apiServer, namespaceId, gbId);
92+
StringMap map = new StringMap().put("prefix", prefix);
93+
requestUrl = UrlUtils.composeUrlWithQueries(requestUrl, map);
94+
return QvsResponse.get(requestUrl, client, auth);
95+
}
9296

9397
/*
9498
* 启动设备拉流
9599
*/
96100
public Response startDevice(String namespaceId, String gbId, String channels) throws QiniuException {
97101
String url = String.format("%s/v1/namespaces/%s/devices/%s/start", apiServer, namespaceId, gbId);
98102
StringMap params = new StringMap().put("channels", channels);
99-
return QvsResponse.post(url, params, client, auth);
103+
return QvsResponse.post(url, params, client, auth);
100104
}
101105

102106
/*
@@ -105,7 +109,7 @@ public Response startDevice(String namespaceId, String gbId, String channels) th
105109
public Response stopDevice(String namespaceId, String gbId, String channels) throws QiniuException {
106110
String url = String.format("%s/v1/namespaces/%s/devices/%s/stop", apiServer, namespaceId, gbId);
107111
StringMap params = new StringMap().put("channels", channels);
108-
return QvsResponse.post(url, params, client, auth);
112+
return QvsResponse.post(url, params, client, auth);
109113
}
110114

111115
}

src/main/java/com/qiniu/qvs/README.md

Lines changed: 98 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
- [x] 启用流: enableStream(String namespaceId, String streamId)
2525
- [x] 查询推流记录: queryStreamPubHistories(String namespaceId, String streamId, int start, int end, int offset, int line)
2626

27+
- 设备管理
28+
- [x] 创建设备: createDevice(String namespaceId, Device device)
29+
- [x] 删除设备: deleteDevice(String namespaceId, String gbId)
30+
- [x] 更新设备: updateDevice(String namespaceId, String gbId, PatchOperation[] patchOperation)
31+
- [x] 查询设备信息: queryDevice(String namespaceId, String gbId)
32+
- [x] 获取设备列表: listDevice(String namespaceId, int offset, int line, String prefix, String state, int qtype)
33+
- [x] 获取通道列表: listChannels(String namespaceId, String gbId, String prefix)
34+
- [x] 启动设备拉流: startDevice(String namespaceId, String gbId, String channels)
35+
- [x] 停止设备拉流: stopDevice(String namespaceId, String gbId, String channels)
36+
2737
- 模板管理
2838
- [x] 创建模板: createTemplate(Template template)
2939
- [x] 删除模板: deleteTemplate(String templateId)
@@ -66,20 +76,31 @@
6676
* [启用流](#启用流)
6777
* [删除流](#删除流)
6878

79+
- [设备管理](#设备管理)
80+
81+
- [创建设备](#创建设备)
82+
- [删除设备](#删除设备)
83+
- [查询设备](#查询设备)
84+
- [更新设备](#更新设备)
85+
- [获取设备列表](#获取设备列表)
86+
- [获取通道列表](#获取通道列表)
87+
- [启动设备拉流](#启动设备拉流)
88+
- [停止设备拉流](#停止设备拉流)
89+
6990
- [模板管理](#模板管理)
70-
91+
7192
* [创建模板](#创建模板)
7293
* [查询模板](#查询模板)
7394
* [更新模板](#更新模板)
7495
* [获取模板列表](#获取模板列表)
7596
* [删除模板](#删除模板)
76-
97+
7798
- [录制管理](#录制管理)
78-
99+
79100
- [查询录制记录](#查询录制记录)
80101
- [查询流封面](#查询流封面)
81102
- [获取截图列表](#获取截图列表)
82-
103+
83104

84105

85106
## Usage
@@ -249,6 +270,79 @@ streamManager.enableStream(namespaceId, stream.getStreamID());
249270
streamManager.deleteStream(namespaceId, stream.getStreamID());
250271
```
251272

273+
### 设备管理
274+
275+
#### 创建设备
276+
277+
```
278+
// 创建设备
279+
DeviceManager deviceManager = new DeviceManager(auth);
280+
Device device = new Device();
281+
device.setUsername("admin");
282+
device.setPassword("QQQNNN111");
283+
284+
String namespaceId = "3nm4x0v0h6vjr";
285+
deviceManager.createDevice(namespaceId, device);
286+
```
287+
288+
#### 删除设备
289+
290+
```
291+
deviceManager.deleteDevice(namespaceId, device.getGbId());
292+
```
293+
294+
#### 查询设备
295+
296+
```
297+
// 查询设备
298+
device.setGbId("31011500991320000056");
299+
300+
deviceManager.queryDevice(namespaceId, device.getGbId());
301+
```
302+
303+
#### 更新设备
304+
305+
```
306+
// 更新设备
307+
PatchOperation[] patchOperation = {new PatchOperation("replace", "name", "GBTEST")};
308+
309+
deviceManager.updateDevice(namespaceId, device.getGbId(), patchOperation);
310+
```
311+
312+
#### 获取设备列表
313+
314+
```
315+
// 获取设备列表
316+
int offset = 0;
317+
int line = 3;
318+
int qtype = 0;
319+
String prefix = "310";
320+
String state = "notReg";
321+
322+
deviceManager.listDevice(namespaceId, offset, line, prefix, state, qtype);
323+
```
324+
325+
#### 获取通道列表
326+
327+
```
328+
// 禁用空间
329+
deviceManager.listChannels(namespaceId, device.getGbId(), prefix);
330+
```
331+
332+
#### 启动设备拉流
333+
334+
```
335+
// 启动设备拉流
336+
deviceManager.startDevice(namespaceId, device.getGbId(), "31011500991320000056");
337+
```
338+
339+
#### 停止设备拉流
340+
341+
```
342+
// 停止设备拉流
343+
deviceManager.stopDevice(namespaceId, device.getGbId(), "31011500991320000056");
344+
```
345+
252346

253347

254348
### 模板管理
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
package test.com.qiniu.qvs;
2+
3+
import com.qiniu.common.QiniuException;
4+
import com.qiniu.http.Response;
5+
import com.qiniu.qvs.DeviceManager;
6+
import com.qiniu.qvs.model.Device;
7+
import com.qiniu.qvs.model.PatchOperation;
8+
import com.qiniu.util.Auth;
9+
import org.junit.Before;
10+
import org.junit.Test;
11+
import test.com.qiniu.TestConfig;
12+
13+
public class DeviceManagerTest {
14+
Auth auth = TestConfig.testAuth;
15+
private DeviceManager deviceManager;
16+
private Response res = null;
17+
private String namespaceId = "3nm4x0v0h6vjr";
18+
private String gbId = "31011500991320000056";
19+
20+
21+
@Before
22+
public void setUp() throws Exception {
23+
this.deviceManager = new DeviceManager(auth);
24+
}
25+
26+
@Test
27+
public void testCreateDevice() {
28+
Device device = new Device();
29+
device.setUsername("admin");
30+
device.setPassword("QQQNNN111");
31+
try {
32+
res = deviceManager.createDevice(namespaceId, device);
33+
System.out.println(res.bodyString());
34+
} catch (QiniuException e) {
35+
e.printStackTrace();
36+
} finally {
37+
if (res != null) {
38+
res.close();
39+
}
40+
}
41+
}
42+
43+
@Test
44+
public void testQueryDevice() {
45+
try {
46+
res = deviceManager.queryDevice(namespaceId, gbId);
47+
System.out.println(res.bodyString());
48+
} catch (QiniuException e) {
49+
e.printStackTrace();
50+
} finally {
51+
if (res != null) {
52+
res.close();
53+
}
54+
}
55+
}
56+
57+
@Test
58+
public void testUpdateDevice() {
59+
PatchOperation[] patchOperation = {new PatchOperation("replace", "name", "GBTEST")};
60+
try {
61+
res = deviceManager.updateDevice(namespaceId, gbId, patchOperation);
62+
System.out.println(res.bodyString());
63+
} catch (QiniuException e) {
64+
e.printStackTrace();
65+
} finally {
66+
if (res != null) {
67+
res.close();
68+
}
69+
}
70+
}
71+
72+
@Test
73+
public void testListDevice() {
74+
int offset = 0;
75+
int line = 3;
76+
int qtype = 0;
77+
String prefix = "310";
78+
String state = "notReg";
79+
try {
80+
res = deviceManager.listDevice(namespaceId, offset, line, prefix, state, qtype);
81+
System.out.println(res.bodyString());
82+
} catch (QiniuException e) {
83+
e.printStackTrace();
84+
} finally {
85+
if (res != null) {
86+
res.close();
87+
}
88+
}
89+
}
90+
91+
@Test
92+
public void testListChannels() {
93+
String prefix = "310";
94+
try {
95+
res = deviceManager.listChannels(namespaceId, gbId, prefix);
96+
System.out.println(res.bodyString());
97+
} catch (QiniuException e) {
98+
e.printStackTrace();
99+
} finally {
100+
if (res != null) {
101+
res.close();
102+
}
103+
}
104+
}
105+
106+
@Test
107+
public void testStartDevice() {
108+
try {
109+
res = deviceManager.startDevice(namespaceId, gbId, "31011500991320000056");
110+
System.out.println(res.bodyString());
111+
} catch (QiniuException e) {
112+
e.printStackTrace();
113+
} finally {
114+
if (res != null) {
115+
res.close();
116+
}
117+
}
118+
}
119+
120+
@Test
121+
public void testStopDevice() {
122+
try {
123+
res = deviceManager.stopDevice(namespaceId, gbId, "31011500991320000056");
124+
System.out.println(res.bodyString());
125+
} catch (QiniuException e) {
126+
e.printStackTrace();
127+
} finally {
128+
if (res != null) {
129+
res.close();
130+
}
131+
}
132+
}
133+
134+
@Test
135+
public void testDeleteDevice() {
136+
try {
137+
res = deviceManager.deleteDevice(namespaceId, gbId);
138+
System.out.println(res.bodyString());
139+
} catch (QiniuException e) {
140+
e.printStackTrace();
141+
} finally {
142+
if (res != null) {
143+
res.close();
144+
}
145+
}
146+
}
147+
}

0 commit comments

Comments
 (0)