onvif 0.0.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 65

ONVIF #

This package is designed to find CCTV cameras that support the ONVIF protocol. The method for finding these cameras is the [WS-Discovery](https://en.wikipedia.org/wiki/WS-Discovery) protocol.

How to use #

import  'package:onvif/Model/OnvifDevice.dart';
import  'package:onvif/onvif.dart';

Create an ONVIF object and call the get Devices method.

List<OnvifDevice> devices = [];
ONVIF onvif = ONVIF();
onvif.getDevices((device){
devices.add(device);
});

To get the streaming link , all you have to do is call the getCameraUri function and send the username and password values of the camera you specified as an argument.

String uri = await onvif.getCameraUri(onvifDev, username, password);

You can play the resulting url with the vlc player. Note that to play the contents of the camera, you must change the resulting url to the following pattern.

uri.substring(0 , 7)+ "$username:$password@"+ url.substring(7 , url.length)

See the example project for a better understanding.

[0.0.6] - TODO: 2020/5/26 #

  • TODO: You can find CCTV cameras that support the ONVIF protocol and get streaming URLs.

example/lib/main.dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:onvif/Model/OnvifDevice.dart';
import 'package:onvif/ONVIF.dart';
import 'VideoPlayer.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  List<OnvifDevice> devices = [];
  StreamController<List<OnvifDevice>> streamDevicesController = StreamController() ;
  List<TextEditingController>usernameController=[];
  List<TextEditingController>passwordController=[];
  List<FocusNode>usernameFocus=[];
  List<FocusNode>passwordFocus=[];
   ONVIF onvif = ONVIF();
@override
  void initState() {
 
  onvif.getDevices((device){
  devices.add(device);
  streamDevicesController.add(devices);
  usernameController.add(TextEditingController());
  passwordController.add(TextEditingController());
  usernameFocus.add(FocusNode());
  passwordFocus.add(FocusNode());
  });
  
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
       body: StreamBuilder(
        stream: streamDevicesController.stream,
        builder: (BuildContext context , AsyncSnapshot<List<OnvifDevice>>snapshot){
          List<OnvifDevice> data = (snapshot.data)??[];
          return GridView.builder(gridDelegate:SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, crossAxisSpacing: 4.0, mainAxisSpacing: 4.0),
           itemCount: data.length,
           itemBuilder: (BuildContext context  , int index){
            return  Card(child: 
                    Column(children: <Widget>[
                      TextField(
                        controller: usernameController[index],
                        decoration: InputDecoration(
                          hintText: "Username"
                        ),
                        focusNode: usernameFocus[index],
                        textInputAction: TextInputAction.next,
                        onSubmitted: (value){
                          _fieldFocusChange(context, usernameFocus[index], passwordFocus[index]);
                        },
                      ), 
                       TextField(
                        controller: passwordController[index],
                        decoration: InputDecoration(
                          hintText: "Password"
                        ),
                        focusNode: passwordFocus[index],
                        textInputAction: TextInputAction.done,
                        onSubmitted: (value){
                          connect(data[index] , usernameController[index].text , passwordController[index].text );
                        },
                      ), 
                      RaisedButton(child: Text("connect"),
                      onPressed: (){
                        connect(data[index] , usernameController[index].text , passwordController[index].text );
                      },), 
                      SizedBox(height: 20,),
                      Text(showIP(data[index])),
                      
                    ],), );
           });
        },
      ),
      );
  }
  void _fieldFocusChange(BuildContext context, FocusNode currentFocus,FocusNode nextFocus) {
    currentFocus.unfocus();
    FocusScope.of(context).requestFocus(nextFocus); 
}
String showIP(OnvifDevice device){
  return device.xAddr.split('/')[2];
}
void connect(OnvifDevice onvifDev  , String username , String password)async{

              String uri = await onvif.getCameraUri(onvifDev, username, password);
               Navigator.push(context,
               MaterialPageRoute(
             builder: (context) => VideoPlayer(uri , username , password),));
    } 
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  onvif: ^0.0.6

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:onvif/BLOC.dart';
import 'package:onvif/Model/NetworkProtocol.dart';
import 'package:onvif/Model/OnvifDevice.dart';
import 'package:onvif/Model/Probe.dart';
import 'package:onvif/Model/ProbeMatch.dart';
import 'package:onvif/Model/WsUsernameToken.dart';
import 'package:onvif/ONVIF.dart';
import 'package:onvif/ONVIF_Library.dart';
import 'package:onvif/Repository/ParseData.dart';
import 'package:onvif/Repository/ProcessResponse.dart';
import 'package:onvif/Repository/SendData.dart';
import 'package:onvif/Repository/Utils.dart';
import 'package:onvif/Repository/buildMessages.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
42
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
65
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • onvif that is a package requiring null.

Package not compatible with runtime flutter-web on web

Because:

  • package:onvif/BLOC.dart that imports:
  • package:onvif/Model/OnvifDevice.dart that imports:
  • package:onvif/Repository/SendData.dart that imports:
  • dart:io

Health suggestions

Format lib/BLOC.dart.

Run flutter format to format lib/BLOC.dart.

Format lib/Model/NetworkProtocol.dart.

Run flutter format to format lib/Model/NetworkProtocol.dart.

Format lib/Model/OnvifDevice.dart.

Run flutter format to format lib/Model/OnvifDevice.dart.

Fix additional 10 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/Model/Probe.dart (Run flutter format to format lib/Model/Probe.dart.)
  • lib/Model/ProbeMatch.dart (Run flutter format to format lib/Model/ProbeMatch.dart.)
  • lib/Model/WsUsernameToken.dart (Run flutter format to format lib/Model/WsUsernameToken.dart.)
  • lib/ONVIF.dart (Run flutter format to format lib/ONVIF.dart.)
  • lib/ONVIF_Library.dart (Run flutter format to format lib/ONVIF_Library.dart.)
  • lib/Repository/ParseData.dart (Run flutter format to format lib/Repository/ParseData.dart.)
  • lib/Repository/ProcessResponse.dart (Run flutter format to format lib/Repository/ProcessResponse.dart.)
  • lib/Repository/SendData.dart (Run flutter format to format lib/Repository/SendData.dart.)
  • lib/Repository/Utils.dart (Run flutter format to format lib/Repository/Utils.dart.)
  • lib/Repository/buildMessages.dart (Run flutter format to format lib/Repository/buildMessages.dart.)

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

exitCode: 255 stdout: Documenting onvif... Initialized dartdoc with 361 libraries in 43.2 seconds Generating docs for library BLOC from package:onvif/BLOC.dart... Generating docs for library NetworkProtocol from package:onvif/Model/NetworkProtocol.dart... Generating docs for library OnvifDevice from package:onvif/Model/OnvifDevice.dart... Generating docs for library ParseData from package:onvif/Repository/ParseData.dart... Generating docs for library Probe from package:onvif/Model/Probe.dart... Generating docs for library ProbeMatch from package:onvif/Model/ProbeMatch.dart... Generating docs for library ProcessResponse from package:onvif/Repository/ProcessResponse.dart... Generating docs for library SendData from package:onvif/Repository/SendData.dart... Generating docs for library Utils from package:onvif/Repository/Utils.dart... Generating docs for library WsUsernameToken from package:onvif/Model/WsUsernameToken.dart... Generating docs for library buildMessages from package:onvif/Repository/buildMessages.dart... Generating docs for library onvif from package:onvif/ONVIF.dart... Generating docs for library onvif from package:onvif/ONVIF_Library.dart... Validating docs... Documented 13 public libraries in 6.8 seconds stderr: warning: onvif has no library level documentation comments, from onvif: (file:///tmp/pub-dartlang-dartdocAADOTN/pkg/lib/ONVIF.dart:1:9) warning: onvif has no library level documentation comments, from onvif: (file:///tmp/pub-dartlang-dartdocAADOTN/pkg/lib/ONVIF_Library.dart:1:9) error: failed to write file at: onvif/onvif-library.html for symbol onvif: (file:///tmp/pub-dartlang-dartdocAADOTN/pkg/lib/ONVIF_Library.dart:1:9) conflicting with file already generated by onvif: (file:///tmp/pub-dartlang-dartdocAADOTN/pkg/lib/ONVIF.dart:1:9) Dartdoc generates a path and filename to write to for each symbol. onvif conflicts with another symbol in the generated path, and therefore can not be written out. Changing the name, library name, or class name (if appropriate) of one of the conflicting items can resolve the conflict. Alternatively, use the @nodoc tag in one symbol's documentation comments to hide it. found 2 warnings and 1 error Unhandled exception: dartdoc encountered 1 errors while processing. #0 Dartdoc.generateDocs (package:dartdoc/dartdoc.dart:225:9)

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (xml).

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
collection ^1.14.11 1.14.12 1.14.13
crypto ^2.1.3 2.1.5
dio ^3.0.9 3.0.9
flutter 0.0.0
nonce ^0.1.0 0.1.0
rxdart ^0.24.0 0.24.1
uuid ^2.0.4 2.2.0
xml ^3.5.0 3.7.0 4.2.0
Transitive dependencies
charcode 1.1.3
convert 2.1.1
http_parser 3.1.4
meta 1.1.8 1.2.1
path 1.7.0
petitparser 3.0.4
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test