forked from baofengcloud/csharp-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Live.cs
109 lines (74 loc) · 3.09 KB
/
Live.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Net;
using System.Collections.Generic;
using System.Text;
namespace Baofeng.Cloud {
public class LiveChannelInfo {
public string channelID;
public string gcid;
public string url;
}
public class Live {
public static LiveChannelInfo CreateChannel(Profile profile, FileType fileType, string channelName) {
String token = Token.LiveCreateToken(profile.accessKey,
profile.secretKey,
fileType,
channelName,
Const.TokenTimeoutSec);
return CreateChannel(token);
}
public static LiveChannelInfo CreateChannel(String token) {
LiveChannelInfo info = new LiveChannelInfo();
try {
String json = "{\"token\":\"" + token + "\"}";
var client = new System.Net.WebClient();
client.Headers.Add("Content-Type", "application/json");
var resp = client.UploadData(Const.LiveCreateUrl, "POST",
System.Text.Encoding.UTF8.GetBytes(json));
var respStr = System.Text.Encoding.UTF8.GetString(resp);
var result = SimpleJsonParser.Parse(respStr); ;
int status = 99;
if (result.ContainsKey("status")) {
status = int.Parse(result["status"]);
if (status == 0) {
info.channelID = result["channelid"];
info.gcid = result["gcid"];
info.url = result["url"];
return info;
}
}
throw new CloudException(status, "");
} catch (WebException e) {
throw new CloudException(99, e.ToString());
}
}
public static void DeleteChannel(Profile profile, string channelID) {
String token = Token.LiveDeleteToken(profile.accessKey,
profile.secretKey,
channelID,
Const.TokenTimeoutSec);
DeleteChannel(token);
}
public static void DeleteChannel(String token) {
try {
String json = "{\"token\":\"" + token + "\"}";
var client = new System.Net.WebClient();
client.Headers.Add("Content-Type", "application/json");
var resp = client.UploadData(Const.LiveDeleteUrl, "POST",
System.Text.Encoding.UTF8.GetBytes(json));
var respStr = System.Text.Encoding.UTF8.GetString(resp);
var result = SimpleJsonParser.Parse(respStr); ;
int status = 99;
if (result.ContainsKey("status")) {
status = int.Parse(result["status"]);
if (status == 0) {
return;
}
}
throw new CloudException(status, "");
} catch (WebException e) {
throw new CloudException(99, e.ToString());
}
}
}
}