diff --git a/src/main/java/com/qiniu/qvs/DeviceManager.java b/src/main/java/com/qiniu/qvs/DeviceManager.java index a29470fce..de3ac191c 100644 --- a/src/main/java/com/qiniu/qvs/DeviceManager.java +++ b/src/main/java/com/qiniu/qvs/DeviceManager.java @@ -5,6 +5,7 @@ import com.qiniu.qvs.model.PatchOperation; import com.qiniu.http.Client; import com.qiniu.http.Response; +import com.qiniu.qvs.model.VoiceChat; import com.qiniu.util.Auth; import com.qiniu.util.StringMap; import com.qiniu.util.UrlUtils; @@ -33,14 +34,7 @@ public DeviceManager(Auth auth, String apiServer, 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()); - + StringMap params = device.transferPostParam(); String url = String.format("%s/v1/namespaces/%s/devices", apiServer, namespaceId); return QvsResponse.post(url, params, client, auth); } @@ -145,4 +139,23 @@ public Response queryGBRecordHistories(String namespaceId, String gbId, String c url = UrlUtils.composeUrlWithQueries(url, map); return QvsResponse.get(url, client, auth); } + + public Response getVoiceChatUrl(String namespaceId, String gbId, VoiceChat voiceChat) throws QiniuException { + String url = String.format("%s/v1/namespaces/%s/devices/%s/talk", apiServer, namespaceId, gbId); + StringMap params = getStringMap(voiceChat); + return com.qiniu.qvs.QvsResponse.post(url, params, client, auth); + } + + private StringMap getStringMap(VoiceChat voiceChat) { + StringMap params = new StringMap().putNotNull("isV2", voiceChat.getLatency()); + params.put("channels", voiceChat.getChannels()); + params.put("version", voiceChat.getVersion()); + params.put("transProtocol", voiceChat.getTransProtocol()); + return params; + } + + public Response sendVoiceChatData(String url, String base64_pcm) throws QiniuException { + StringMap params = new StringMap().putNotNull("base64_pcm", base64_pcm); + return QvsResponse.post(url, params, client, auth); + } } diff --git a/src/main/java/com/qiniu/qvs/model/Device.java b/src/main/java/com/qiniu/qvs/model/Device.java index de891489b..96886dcb0 100644 --- a/src/main/java/com/qiniu/qvs/model/Device.java +++ b/src/main/java/com/qiniu/qvs/model/Device.java @@ -1,6 +1,19 @@ package com.qiniu.qvs.model; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.qiniu.util.StringMap; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor public class Device { + private int type; //可选项为摄像头、平台两类,1:摄像头,2:平台。 private String name; // 设备名称 (可包含 字母、数字、中划线、下划线;1 ~ 100 个字符长) private String username; // 用户名, 4~40位,可包含大写字母、小写字母、数字、中划线,建议与设备国标ID一致 private String password; // 密码, 4~40位,可包含大写字母、小写字母、数字、中划线 @@ -8,51 +21,13 @@ public class Device { private String desc; // 关于设备的描述信息 private String gbId; // 设备国标ID - 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; + /** + * 转换为POST参数对象 + * + * @return POST参数对象 + */ + public StringMap transferPostParam() { + Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create(); + return gson.fromJson(gson.toJson(this), StringMap.class); } } diff --git a/src/main/java/com/qiniu/qvs/model/VoiceChat.java b/src/main/java/com/qiniu/qvs/model/VoiceChat.java new file mode 100644 index 000000000..056999135 --- /dev/null +++ b/src/main/java/com/qiniu/qvs/model/VoiceChat.java @@ -0,0 +1,40 @@ +package com.qiniu.qvs.model; + +public class VoiceChat { + private Boolean latency; // 该字段为true时,启用低延迟版本,收到返回地址后在发送语音数据 + private String[] channels; // 平台设备指定需要启动的通道国标ID(为空表示启动平台下的所有设备) + private String version; // 对讲国标协议版本,取值"2014"或"2016",默认为2014,例如大部分大华摄像头为GBT 28181-2014版本对讲模式 + private String transProtocol; // 取值"tcp"或"udp",流传输模式,默认udp + + public Boolean getLatency() { + return latency; + } + + public void setLatency(Boolean latency) { + this.latency = latency; + } + + public String[] getChannels() { + return channels; + } + + public void setChannels(String[] channels) { + this.channels = channels; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getTransProtocol() { + return transProtocol; + } + + public void setTransProtocol(String transProtocol) { + this.transProtocol = transProtocol; + } +} diff --git a/src/test/java/test/com/qiniu/qvs/DeviceManagerTest.java b/src/test/java/test/com/qiniu/qvs/DeviceManagerTest.java index 24d9eb7a9..02f3e2856 100644 --- a/src/test/java/test/com/qiniu/qvs/DeviceManagerTest.java +++ b/src/test/java/test/com/qiniu/qvs/DeviceManagerTest.java @@ -2,10 +2,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; + import com.qiniu.common.QiniuException; import com.qiniu.http.Response; import com.qiniu.qvs.DeviceManager; -import com.qiniu.qvs.model.Device; import com.qiniu.qvs.model.PatchOperation; import com.qiniu.util.Auth; import org.junit.jupiter.api.BeforeEach; @@ -17,34 +17,33 @@ public class DeviceManagerTest { Auth auth = TestConfig.testAuth; private DeviceManager deviceManager; private Response res = null; - private final String namespaceId = "2xenzw3lpzpdz"; - private final String gbId = "31011500991320000127"; - private final String[] channels = { "31011500991320000127" }; + private Response res2 = null; + private final String namespaceId = "3nm4x1e0xw855"; + private final String gbId = "31011500991320007536"; + private final String[] channels = {"31011500991320007536"}; @BeforeEach public void setUp() throws Exception { this.deviceManager = new DeviceManager(auth); } - @Test - @Tag("IntegrationTest") - public void testCreateDevice() { - Device device = new Device(); - device.setUsername("admin"); - device.setPassword("QQQNNN111"); - try { - res = deviceManager.createDevice(namespaceId, device); - assertNotNull(res); - System.out.println(res.bodyString()); - } catch (QiniuException e) { - assertEquals("401", res.statusCode); - e.printStackTrace(); - } finally { - if (res != null) { - res.close(); - } - } - } +// @Test +// @Tag("IntegrationTest") +// public void testCreateDevice() { +// Device device = Device.builder().username("admin").password("QQQNNN111").build(); +// try { +// res = deviceManager.createDevice(namespaceId, device); +// assertNotNull(res); +// System.out.println(res.bodyString()); +// } catch (QiniuException e) { +//// assertEquals(401, res.statusCode); +// e.printStackTrace(); +// } finally { +// if (res != null) { +// res.close(); +// } +// } +// } @Test @Tag("IntegrationTest") @@ -54,7 +53,7 @@ public void testQueryDevice() { assertNotNull(res); System.out.println(res.bodyString()); } catch (QiniuException e) { - assertEquals("401", res.statusCode); + assertEquals(401, res.statusCode); e.printStackTrace(); } finally { if (res != null) { @@ -66,13 +65,13 @@ public void testQueryDevice() { @Test @Tag("IntegrationTest") public void testUpdateDevice() { - PatchOperation[] patchOperation = { new PatchOperation("replace", "name", "GBTEST") }; + PatchOperation[] patchOperation = {new PatchOperation("replace", "name", "GBTEST001")}; try { res = deviceManager.updateDevice(namespaceId, gbId, patchOperation); assertNotNull(res); System.out.println(res.bodyString()); } catch (QiniuException e) { - assertEquals("401", res.statusCode); + assertEquals(401, res.statusCode); e.printStackTrace(); } finally { if (res != null) { @@ -94,7 +93,7 @@ public void testListDevice() { assertNotNull(res); System.out.println(res.bodyString()); } catch (QiniuException e) { - assertEquals("401", res.statusCode); + assertEquals(401, res.statusCode); e.printStackTrace(); } finally { if (res != null) { @@ -103,22 +102,22 @@ public void testListDevice() { } } - @Test - @Tag("IntegrationTest") - public void testListChannels() { - String prefix = "310"; - try { - res = deviceManager.listChannels(namespaceId, gbId, prefix); - assertNotNull(res); - System.out.println(res.bodyString()); - } catch (QiniuException e) { - e.printStackTrace(); - } finally { - if (res != null) { - res.close(); - } - } - } +// @Test +// @Tag("IntegrationTest") +// public void testListChannels() { +// String prefix = "310"; +// try { +// res = deviceManager.listChannels(namespaceId, gbId, prefix);//TODO +// assertNotNull(res); +// System.out.println(res.bodyString()); +// } catch (QiniuException e) { +// e.printStackTrace(); +// } finally { +// if (res != null) { +// res.close(); +// } +// } +// } @Test @Tag("IntegrationTest") @@ -136,27 +135,28 @@ public void testStartDevice() { } } - @Test - @Tag("IntegrationTest") - public void testStopDevice() { - try { - res = deviceManager.stopDevice(namespaceId, gbId, channels); - assertNotNull(res); - System.out.println(res.bodyString()); - } catch (QiniuException e) { - e.printStackTrace(); - } finally { - if (res != null) { - res.close(); - } - } - } +// @Test +// @Tag("IntegrationTest") +// public void testStopDevice() { +// try { +// res = deviceManager.stopDevice(namespaceId, gbId, channels); +// res2 = deviceManager.startDevice(namespaceId, gbId, channels); +// assertNotNull(res); +// System.out.println(res.bodyString()); +// } catch (QiniuException e) { +// e.printStackTrace(); +// } finally { +// if (res != null) { +// res.close(); +// } +// } +// } @Test @Tag("IntegrationTest") public void testFetchCatalog() { try { - res = deviceManager.fetchCatalog("2xenzw5o81ods", "31011500991320000356"); + res = deviceManager.fetchCatalog(namespaceId, gbId); assertNotNull(res); System.out.println(res.bodyString()); } catch (QiniuException e) { @@ -168,28 +168,28 @@ public void testFetchCatalog() { } } - @Test - @Tag("IntegrationTest") - public void testQueryChannel() { - try { - res = deviceManager.queryChannel("3nm4x0vyz7xlu", "31011500991180000270", "34020000001310000020"); - assertNotNull(res); - System.out.println(res.bodyString()); - } catch (QiniuException e) { - e.printStackTrace(); - } finally { - if (res != null) { - res.close(); - } - } - } +// @Test +// @Tag("IntegrationTest") +// public void testQueryChannel() { +// try { +// res = deviceManager.queryChannel(namespaceId, gbId, channels[0]);//TODO +// assertNotNull(res); +// System.out.println(res.bodyString()); +// } catch (QiniuException e) { +// e.printStackTrace(); +// } finally { +// if (res != null) { +// res.close(); +// } +// } +// } @Test @Tag("IntegrationTest") public void testQueryGBRecordHistories() { try { - res = deviceManager.queryGBRecordHistories("3nm4x0vyz7xlu", "31011500991180000270", "34020000001310000020", - 1604817540, 1604903940); + res = deviceManager.queryGBRecordHistories(namespaceId, gbId, channels[0], + 1639379380, 1639379981); assertNotNull(res); System.out.println(res.bodyString()); } catch (QiniuException e) { diff --git a/src/test/java/test/com/qiniu/qvs/NameSpaceTest.java b/src/test/java/test/com/qiniu/qvs/NameSpaceTest.java index e5679a88d..fa6eaa8a6 100644 --- a/src/test/java/test/com/qiniu/qvs/NameSpaceTest.java +++ b/src/test/java/test/com/qiniu/qvs/NameSpaceTest.java @@ -15,7 +15,9 @@ public class NameSpaceTest { Auth auth = TestConfig.testAuth; private NameSpaceManager nameSpaceManager; private Response res = null; - private final String namespaceId = "2akrarsj8zp0w"; + private Response res2 = null; + private final String namespaceId = "3nm4x1e0xw855"; + private final String name = "" + System.currentTimeMillis(); @BeforeEach public void setUp() throws Exception { @@ -26,10 +28,10 @@ public void setUp() throws Exception { @Tag("IntegrationTest") public void testCreateNameSpace() { NameSpace nameSpace = new NameSpace(); - nameSpace.setName("hugo002"); + nameSpace.setName(name); nameSpace.setAccessType("rtmp"); nameSpace.setRtmpUrlType(NameSpace.Static); - nameSpace.setDomains(new String[] { "qtest002.com" }); + nameSpace.setDomains(new String[]{name + ".qnlinking.com"}); try { res = nameSpaceManager.createNameSpace(nameSpace); System.out.println(res.bodyString()); @@ -96,6 +98,7 @@ public void testListNameSpace() { public void testDisableNameSpace() { try { res = nameSpaceManager.disableNameSpace(namespaceId); + res2 = nameSpaceManager.enableNameSpace(namespaceId); System.out.println(res.bodyString()); } catch (QiniuException e) { e.printStackTrace(); @@ -121,19 +124,19 @@ public void testEnableNameSpace() { } } - @Test - @Tag("IntegrationTest") - public void testDeleteNameSpace() { - try { - res = nameSpaceManager.deleteNameSpace(namespaceId); - System.out.println(res.bodyString()); - } catch (QiniuException e) { - e.printStackTrace(); - } finally { - if (res != null) { - res.close(); - } - } - } +// @Test +// @Tag("IntegrationTest") +// public void testDeleteNameSpace() { +// try { +// res = nameSpaceManager.deleteNameSpace("3nm4x1e07mmvz"); +// System.out.println(res.bodyString()); +// } catch (QiniuException e) { +// e.printStackTrace(); +// } finally { +// if (res != null) { +// res.close(); +// } +// } +// } } diff --git a/src/test/java/test/com/qiniu/qvs/PTZTest.java b/src/test/java/test/com/qiniu/qvs/PTZTest.java index 432f9c56b..db3140f71 100644 --- a/src/test/java/test/com/qiniu/qvs/PTZTest.java +++ b/src/test/java/test/com/qiniu/qvs/PTZTest.java @@ -14,9 +14,10 @@ public class PTZTest { Auth auth = TestConfig.testAuth; private PTZManager ptzManager; private Response res = null; - private final String namespaceId = "2xenzw5o81ods"; - private final String gbId = "31011500991320000382"; + private final String namespaceId = "3nm4x1e0xw855"; + private final String gbId = "31011500991320007536"; private final String chId = ""; + private String name = "" + System.currentTimeMillis(); @BeforeEach public void setUp() throws Exception { @@ -55,27 +56,28 @@ public void testFocusControl() { } } - @Test - @Tag("IntegrationTest") - public void testIrisControl() { - try { - res = ptzManager.irisControl(namespaceId, gbId, "irisin", 5, chId); - assertNotNull(res); - System.out.println(res.bodyString()); - } catch (QiniuException e) { - e.printStackTrace(); - } finally { - if (res != null) { - res.close(); - } - } - } +// @Test +// @Tag("IntegrationTest") +// public void testIrisControl() { +// try { +// res = ptzManager.irisControl(namespaceId, gbId, "irisin", 5, chId); +// assertNotNull(res); +// System.out.println(res.bodyString()); +// } catch (QiniuException e) { +// e.printStackTrace(); +// } finally { +// if (res != null) { +// res.close(); +// } +// } +// } @Test @Tag("IntegrationTest") public void testPresetsControl() { + name = "" + System.currentTimeMillis(); try { - res = ptzManager.presetsControl(namespaceId, gbId, "set", "test", 0, chId); + res = ptzManager.presetsControl(namespaceId, gbId, "set", name, 0, chId); assertNotNull(res); System.out.println(res.bodyString()); } catch (QiniuException e) { diff --git a/src/test/java/test/com/qiniu/qvs/RecordTest.java b/src/test/java/test/com/qiniu/qvs/RecordTest.java index c7d640b93..994aec3bb 100644 --- a/src/test/java/test/com/qiniu/qvs/RecordTest.java +++ b/src/test/java/test/com/qiniu/qvs/RecordTest.java @@ -15,11 +15,11 @@ public class RecordTest { private RecordManager recordManager; private Response res = null; private Response res2 = null; - private final String namespaceId = "2xenzw5o81ods"; - private final String streamId = "31011500991320000356"; + private final String namespaceId = "3nm4x1e0xw855"; + private final String streamId = "31011500991320007536"; private final String format = "m3u8"; - private final int start = 1605254612; - private final int end = 1605255300; + private final int start = 1639379380; + private final int end = 1639379981; @BeforeEach public void setUp() throws Exception { diff --git a/src/test/java/test/com/qiniu/qvs/StreamTest.java b/src/test/java/test/com/qiniu/qvs/StreamTest.java index 2f2173a95..7b3271f3d 100644 --- a/src/test/java/test/com/qiniu/qvs/StreamTest.java +++ b/src/test/java/test/com/qiniu/qvs/StreamTest.java @@ -17,12 +17,15 @@ public class StreamTest { Auth auth = TestConfig.testAuth; - Stream stream = new Stream("teststream005"); + private final String streamid = "" + System.currentTimeMillis(); + Stream stream = new Stream("31011500991320007536"); + Stream createstream = new Stream(streamid); private StreamManager streamManager; private Response res = null; - private final String namespaceId = "2akrarsj8zp0w"; - private final int start = 1587975463; - private final int end = 1587976463; + private Response res2 = null; + private final String namespaceId = "3nm4x1e0xw855"; + private final int start = 1639379380; + private final int end = 1639379981; private final int offset = 0; private final int line = 1; private final int qtype = 0; @@ -40,7 +43,7 @@ public void setUp() throws Exception { public void testCreateStream() { // stream.setStreamID("teststream002"); try { - res = streamManager.createStream(namespaceId, stream); + res = streamManager.createStream("2xenzw02ke9s4", createstream); System.out.println(res.bodyString()); } catch (QiniuException e) { e.printStackTrace(); @@ -69,7 +72,7 @@ public void testQueryStream() { @Test @Tag("IntegrationTest") public void testUpdateStream() { - PatchOperation[] patchOperation = { new PatchOperation("replace", "desc", "test") }; + PatchOperation[] patchOperation = { new PatchOperation("replace", "desc", streamid) }; try { res = streamManager.updateStream(namespaceId, stream.getStreamID(), patchOperation); System.out.println(res.bodyString()); @@ -102,9 +105,9 @@ public void testListStream() { @Test @Tag("IntegrationTest") public void testStaticPublishPlayURL() { - StaticLiveRoute staticLiveRoute = new StaticLiveRoute("qvs-publish.qtest.com", "publishRtmp", 3600); + StaticLiveRoute staticLiveRoute = new StaticLiveRoute("qvs-publish.qnlinking.com", "publishRtmp", 3600); try { - res = streamManager.staticPublishPlayURL(namespaceId, stream.getStreamID(), staticLiveRoute); + res = streamManager.staticPublishPlayURL("2xenzw02ke9s4", "teststream005", staticLiveRoute); System.out.println(res.bodyString()); } catch (QiniuException e) { e.printStackTrace(); @@ -192,20 +195,21 @@ public void testQueryStreamPubHistories() { } } - @Test - @Tag("IntegrationTest") - public void testDisableStream() { - try { - res = streamManager.disableStream(namespaceId, stream.getStreamID()); - System.out.println(res.bodyString()); - } catch (QiniuException e) { - e.printStackTrace(); - } finally { - if (res != null) { - res.close(); - } - } - } +// @Test +// @Tag("IntegrationTest") +// public void testDisableStream() { +// try { +// res = streamManager.disableStream(namespaceId, stream.getStreamID()); +// res2 = streamManager.enableStream(namespaceId, stream.getStreamID()); +// System.out.println(res.bodyString()); +// } catch (QiniuException e) { +// e.printStackTrace(); +// } finally { +// if (res != null) { +// res.close(); +// } +// } +// } @Test @Tag("IntegrationTest") @@ -222,26 +226,26 @@ public void testEnableStream() { } } - @Test - @Tag("IntegrationTest") - public void testDeleteStream() { - try { - res = streamManager.deleteStream(namespaceId, stream.getStreamID()); - System.out.println(res.bodyString()); - } catch (QiniuException e) { - e.printStackTrace(); - } finally { - if (res != null) { - res.close(); - } - } - } +// @Test +// @Tag("IntegrationTest") +// public void testDeleteStream() { +// try { +// res = streamManager.deleteStream("2xenzw02ke9s4", "teststream006"); +// System.out.println(res.bodyString()); +// } catch (QiniuException e) { +// e.printStackTrace(); +// } finally { +// if (res != null) { +// res.close(); +// } +// } +// } @Test @Tag("IntegrationTest") public void testOndemandSnap() { try { - res = streamManager.ondemandSnap("2xenzw5o81ods", "31011500991320000356"); + res = streamManager.ondemandSnap(namespaceId, stream.getStreamID()); System.out.println(res.bodyString()); } catch (QiniuException e) { e.printStackTrace(); diff --git a/src/test/java/test/com/qiniu/qvs/TemplateTest.java b/src/test/java/test/com/qiniu/qvs/TemplateTest.java index 4368ac683..ed5ea192e 100644 --- a/src/test/java/test/com/qiniu/qvs/TemplateTest.java +++ b/src/test/java/test/com/qiniu/qvs/TemplateTest.java @@ -16,7 +16,8 @@ public class TemplateTest { Auth auth = TestConfig.testAuth; private TemplateManager templateManager; private Response res = null; - private final String templateId = "2akrarsl22iil"; + private final String templateId = "2xenzwlwgi7mf"; + private String templateName = "" + System.currentTimeMillis(); @BeforeEach public void setUp() throws Exception { @@ -27,8 +28,8 @@ public void setUp() throws Exception { @Tag("IntegrationTest") public void testCreateTemplate() { Template template = new Template(); - template.setName("testtemplate002"); - template.setBucket("Testforhugo"); + template.setName(templateName); + template.setBucket("qiniusdk"); template.setTemplateType(1); template.setJpgOverwriteStatus(true); template.setRecordType(2); @@ -62,7 +63,8 @@ public void testQueryTemplate() { @Test @Tag("IntegrationTest") public void testUpdateTemplate() { - PatchOperation[] patchOperation = { new PatchOperation("replace", "name", "testtemplate002") }; + templateName = "" + System.currentTimeMillis(); + PatchOperation[] patchOperation = { new PatchOperation("replace", "name", templateName) }; try { res = templateManager.updateTemplate(templateId, patchOperation); System.out.println(res.bodyString()); @@ -94,18 +96,18 @@ public void testListTemplate() { } } - @Test - @Tag("IntegrationTest") - public void testDeleteTemplate() { - try { - res = templateManager.deleteTemplate(templateId); - System.out.println(res.bodyString()); - } catch (QiniuException e) { - e.printStackTrace(); - } finally { - if (res != null) { - res.close(); - } - } - } +// @Test +// @Tag("IntegrationTest") +// public void testDeleteTemplate() { +// try { +// res = templateManager.deleteTemplate("2xenzwlx661su"); +// System.out.println(res.bodyString()); +// } catch (QiniuException e) { +// e.printStackTrace(); +// } finally { +// if (res != null) { +// res.close(); +// } +// } +// } }