/
example.dart
225 lines (157 loc) · 6.33 KB
/
example.dart
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import 'package:easy_onvif/onvif.dart';
import 'package:easy_onvif/soap.dart';
import 'package:loggy/loggy.dart';
import 'package:universal_io/io.dart';
import 'package:yaml/yaml.dart';
void main(List<String> arguments) async {
// get connection information from the config.yaml file
final config = loadYaml(File('example/config.yaml').readAsStringSync());
// configure device connection
final onvif = await Onvif.connect(
host: config['host'],
username: config['username'],
password: config['password'],
logOptions: const LogOptions(
LogLevel.debug,
stackTraceLevel: LogLevel.error,
),
printer: const PrettyPrinter(
showColors: true,
));
// get service capabilities
// var deviceServiceCapabilities =
// await onvif.deviceManagement.getServiceCapabilities();
// print(
// 'max password length: ${deviceServiceCapabilities.security.maxPasswordLength}');
// get service addresses
// var serviceList = await onvif.deviceManagement.getServices();
// for (Service service in serviceList) {
// print('${service.nameSpace} ${service.xAddr}');
// }
// get device info
var deviceInfo = await onvif.deviceManagement.getDeviceInformation();
print('Manufacturer: ${deviceInfo.manufacturer}');
print('Model: ${deviceInfo.model}');
// var ptzConfigs = await onvif.ptz.getConfigurations();
// for (var ptzConfiguration in ptzConfigs) {
// print('${ptzConfiguration.name} ${ptzConfiguration.token}');
// }
// print('xMax: ${ptzConfigs[0].panTiltLimits!.range.xRange.max}');
// print('xMin: ${ptzConfigs[0].panTiltLimits!.range.xRange.min}');
// print('yMax: ${ptzConfigs[0].panTiltLimits!.range.yRange.max}');
// print('yMin: ${ptzConfigs[0].panTiltLimits!.range.yRange.min}');
// determine the media level supported
print(onvif.media.mediaSupportLevel.name);
// get device profiles
var profs = await onvif.media.getProfiles();
for (var profile in profs) {
print(
'name: ${profile.name}, token: ${profile.token}, hasVideoSourceConfig: ${profile.isMedia2 ? profile.configurations?.videoSourceConfiguration?.name : profile.videoSourceConfiguration?.name}');
}
// get snapshot Uri
var snapshotUri = await onvif.media.getSnapshotUri(profs[0].token);
print(snapshotUri);
var streamUri = await onvif.media.getStreamUri(profs[0].token);
print(streamUri);
// await onvif.ptz.moveLeft(profs[0].token);
// var status = await onvif.ptz.getStatus(profs[0].token);
// print(status);
// await onvif.ptz.absoluteMove(
// profs[0].token,
// PtzPosition(
// panTilt: PanTilt(
// x: status.position.panTilt!.x - 0.025,
// y: status.position.panTilt!.y)));
// final uri = await onvif.media.getStreamUri(profs[0].token);
// final rtsp =
// OnvifUtil.authenticatingUri(uri, config['username'], config['password']);
// print('stream uri: $rtsp');
// var ntpInformation = await onvif.deviceManagement.getNtp();
// print(ntpInformation);
// var configurations = await onvif.media.getMetadataConfigurations();
// for (var configuration in configurations) {
// print('${configuration.name} ${configuration.token}');
// }
// get compatible configurations
// var compatibleConfigurations =
// await onvif.ptz.getCompatibleConfigurations(profs[0].token);
// for (var configuration in compatibleConfigurations) {
// print('${configuration.name} ${configuration.token}');
// }
//get capabilities
var capabilities = await onvif.deviceManagement.getCapabilities();
print(capabilities);
//get hostname
var hostname = await onvif.deviceManagement.getHostname();
print(hostname);
//get Network Protocols
var networkProtocols = await onvif.deviceManagement.getNetworkProtocols();
for (var networkProtocol in networkProtocols) {
print('${networkProtocol.name} ${networkProtocol.port}');
}
// get system uris
// var systemUris = await onvif.deviceManagement.getSystemUris();
// print(systemUris);
//create users
// var newUsers = <User>[
// User(username: 'test_1', password: 'onvif.device', userLevel: 'User'),
// User(username: 'test_2', password: 'onvif.device', userLevel: 'User')
// ];
// await onvif.deviceManagement.createUsers(newUsers);
// get users
var users = await onvif.deviceManagement.getUsers();
for (var user in users) {
print('${user.username} ${user.userLevel}');
}
// delete users
// var deleteUsers = ['test_1', 'test_2'];
// await onvif.deviceManagement.deleteUsers(deleteUsers);
// get users
// users = await onvif.deviceManagement.getUsers();
// for (var user in users) {
// print('${user.username} ${user.userLevel}');
// }
//get audio sources
var audioSources = await onvif.media.getAudioSources();
for (var audioSource in audioSources) {
print('${audioSource.token} ${audioSource.channels}');
}
// get video sources
// var videoSources = await onvif.media.getVideoSources();
// for (var videoSource in videoSources) {
// print('${videoSource.token} ${videoSource.resolution}');
// }
// get snapshot Uri
// var snapshotUri =
// await onvif.media.getSnapshotUriType<m1.MediaUri>(profs[0].token);
print(snapshotUri);
// get stream Uri
// var streamUri = await onvif.media.getStreamUri(profs[0].token);
// print(streamUri);
// get get configuration
// var ptzConfig = await onvif.ptz.getConfiguration(ptzConfigs[0].token);
// print(ptzConfig);
// get get presets
// var presets = await onvif.ptz.getPresets(profs[0].token, limit: 5);
// for (var preset in presets) {
// print('${preset.token} ${preset.name}');
// }
// get ptz status
// var status = await onvif.ptz.getStatus(profs[0].token);
// print(status);
// set preset
// var res = await onvif.ptz.setPreset(profs[0].token, 'new test', '20');
// print(res);
// sample low level request
//
// build a xml fragment for the specific Onvif operation
Transport.builder.element('GetAudioOutputs', nest: () {
Transport.builder.namespace(Xmlns.trt);
});
final requestFragment = Transport.builder.buildFragment();
final transport = onvif.transport;
// build the soap request envelope and send the request
final envelope = await transport.sendRequest(
onvif.media.media1.uri, transport.securedEnvelope(requestFragment));
print(envelope.body.response);
}