easy_onvif 3.0.0+1 copy "easy_onvif: ^3.0.0+1" to clipboard
easy_onvif: ^3.0.0+1 copied to clipboard

A pure Dart library designed primarily for command line automation of Onvif compatible devices, but can be used anywhere Dart is used.

example/example.dart

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);
}
23
likes
0
pub points
85%
popularity

Publisher

verified publishermuayid.com

A pure Dart library designed primarily for command line automation of Onvif compatible devices, but can be used anywhere Dart is used.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

archive, args, cli_spin, convert, crypto, dio, ffi, html_unescape, http, intl, json_annotation, loggy, path, shelf, shelf_router, sprintf, universal_io, uuid, xml, xml2json, yaml

More

Packages that depend on easy_onvif