RVS_ONVIF

@objc
open class RVS_ONVIF : NSObject, SOAPEngineDelegate

This is an ONVIF Swift Framework driver.

The driver is designed to be usable for MacOS, iOS and tvOS.

This was initially inspired by the ONVIFCamera library, by Rémy Virin, but has gone far past his implementation.

It uses SOAPEngine, by Danilo Priore to handle the stuff below the session layer.

If you want to use this on a device (as opposed to the simulator), you need to purchase a SOAPEngine license from the Priore Group (see URI, above).

This relies on a delegate pattern, as opposed to the closure pattern that Rémy Virin’s library used.

HOW THE FRAMEWORK OPERATES

The RVS_ONVIF Framework is a “hub and spokes” framework, in a similar pattern to the ONVIF specification.

There is a “core,” and a bunch of “profiles,” as defined by the ONVIF specification.

The profiles (including the core) are the “spokes” of the framework, and are instantiated as needed to address the needs of the device to which the framework instance is dedicated.

You instantiate one RVS_ONVIF instance to connect to one device. You can have as many instances as you want, for multiple devices, but each instance corresponds to only one device.

This framework does not handle device discovery. You are expected to give it an IP number and TCP port. It will handle both IPv4 and IPv6.

DELEGATE

Each delegate call is optional. This is done by extending the delegate protocol with “do nothing” default methods.

There can only be one Delegate.

All Delegate methods are called in the main thread. There are only a couple of methods for errors, successful connection, and successful disconnection.

DISPATCHER

We use “smart dispatchers” to manage the conversation with the driver. The client instantiates profile dispatchers, and registers them with the driver.

The driver then uses these to deliver responses, and the client uses them to send requests.

View the README file for more comprehensive documentation.

Initializers

  • Blank initializer (Public).

    Declaration

    Swift

    public override init()

Public Class Methods

  • This is a factory method for creating instances of the camera handler. It will not create an instance if there is a problem with the submitted data.

    Declaration

    Swift

    public class func makeONVIFInstance(ipAddressAndPort inIPAddressAndPort: String,
                                        loginCredentials inCredentials: LoginCredentialTuple,
                                        soapEngineLicenseKey inSoapEngineLicenseKey: String? = nil,
                                        authMethod inAuthMethod: SOAPAuthMethod = .both,
                                        delegate: RVS_ONVIFDelegate? = nil) -> RVS_ONVIF?

    Parameters

    ipAddressAndPort

    This is a String, containing a standard IPV4 address and port (123.123.123.123:1234)

    loginCredentials

    This is a tuple, containing the login ID and password (Strings) for the camera. It cannot have either field empty (login: String, password: String)

    soapEngineLicenseKey

    This is a String, with the SOAPEngine license key. It is optional (defaults to blank). If not provided, SOAPEngine will only work in the simulator.

    authMethod

    This is an optional parameter, indicating the authorization method. Default is both.

    delegate

    This is an optional (default is nil) parameter that allows you to specify a delegate up front. If specified, the instance will immediately attempt a connection.

    Return Value

    A new instance of this class. Nil, if the provided parameters are not correct.

Public Typealiases

  • This simply contains our login credentials, as Strings.

    Declaration

    Swift

    public typealias LoginCredentialTuple = (login: String, password: String)

    Parameters

    login

    The login ID.

    password

    The password.

Public Enums

  • This is the authorization method to be used for SOAP connections.

    See more

    Declaration

    Swift

    public enum SOAPAuthMethod

Public Calculated Instance Properties

  • These are our profile handlers, returned in an Array. The first element is always the Core handler.

    -returns: an Array of profile handler instances. The first element is always the Core handler. This ensures consistent order.

    Declaration

    Swift

    public var profilesAsArray: [ProfileHandlerProtocol] { get }
  • Declaration

    Swift

    public var hasWiFi: Bool { get }

    Return Value

    true, if this device has WiFi capabilities.

Public Stored Instance Properties

  • This is a String, with our IP address and TCP port.

    Declaration

    Swift

    public var ipAddressAndPort: String
  • These are our login credentials.

    Declaration

    Swift

    public var loginCredentials: RVS_ONVIF.LoginCredentialTuple!
  • These are our various profile handlers. They should be read-only for users of the framework.

    Declaration

    Swift

    public var profiles: [String : ProfileHandlerProtocol] { get }
  • This is our delegate object.

    Declaration

    Swift

    weak public var delegate: RVS_ONVIFDelegate! { get set }
  • This is the SOAP authorization method to use. Default is both, but it can be set to Basic, or Digest; which forces the method.

    Declaration

    Swift

    public var authMethod: RVS_ONVIF.SOAPAuthMethod
  • This contains our dispatchers. These are strong references.

    Dispatchers are how we communicate with the ONVIF devices.

    Declaration

    Swift

    public var dispatchers: [RVS_ONVIF_Dispatcher] { get set }

Public Calculated Instance Properties

  • Shortcut to access the core profile, as it will always be there.

    Declaration

    Swift

    public var core: RVS_ONVIF_Core! { get }

    Return Value

    the core object. nil if there was an error.

  • Shortcut to access the device information.

    Declaration

    Swift

    public var deviceInformation: [String : Any]! { get }

    Return Value

    the device information Dictionary. nil if there was an error.

  • Shortcut to access the services.

    Declaration

    Swift

    public var services: [String : RVS_ONVIF_Core.Service]! { get }

    Return Value

    the services Array. nil if there was an error.

  • Shortcut to access the scopes.

    Declaration

    Swift

    public var scopes: [RVS_ONVIF_Core.Scope]! { get }

    Return Value

    the scopes Array. nil if there was an error.

  • Shortcut to access the capabilities.

    Declaration

    Swift

    public var capabilities: RVS_ONVIF_Core.Capabilities! { get }

    Return Value

    the capability instance. nil if there was an error.

  • Shortcut to access the default service capabilities.

    Declaration

    Swift

    public var serviceCapabilities: RVS_ONVIF_Core.ServiceCapabilities! { get }

    Return Value

    the service capability instance. nil if there was an error.

  • Shortcut to access the device network interface information.

    Declaration

    Swift

    public var networkInterfaces: [RVS_ONVIF_Core.NetworkInterface]! { get }

    Return Value

    The cached device network interface Array.

Public Instance Methods

  • This is called to initialize the connection.

    Declaration

    Swift

    public func initializeConnection()
  • This is called to deinitialize the connection. It removes any non-core profile handlers, and clears the caches.

    Declaration

    Swift

    public func deinitializeConnection()
  • This is a generic request mechanism.

    The request is sent in as a device request protocol instance, and optional parameters may be supplied.

    Declaration

    Swift

    public func performRequest(_ inRequest: RVS_ONVIF_DeviceRequestProtocol, params inParams: [String : Any] = [:], path inPath: String = "")

    Parameters

    inRequest

    The request, usually an enum.

    params

    An optional parameter Dictionary. Default is empty.

    path

    An optional (default is empty string) path. If provided, it will trump the one in the request.

Public Structs and Classes

  • This is a struct that describes an error/issue.

    The enclosed enums are the standard ONVIF error codes and subcodes. They use ONVIF TitleCase, as opposed to the standard camelCase, in order to help correlate.

    See more

    Declaration

    Swift

    public struct RVS_Fault : Error

Public SOAPEngineDelegate Instance Methods

  • This may be called in non-main threads.

    This is called before sending out a request. It has the request formed by SOAPEngine. We use this method to form our own Digest Auth.

    Declaration

    Swift

    public func soapEngine(_ soapEngine: SOAPEngine!, didBeforeSendingURLRequest inRequest: NSMutableURLRequest!) -> NSMutableURLRequest!

    Parameters

    inSOAPEngine

    The SOAPEngine instance calling this method. It may be nil.

    didBeforeSendingURLRequest

    This is a URL Request that will be sent. You can modify this.

  • This may be called in non-main threads.

    This is called if there was a SOAPEngine failure.

    Declaration

    Swift

    public func soapEngine(_ inSOAPEngine: SOAPEngine!, didFailWithError inError: Error!)

    Parameters

    inSOAPEngine

    The SOAPEngine instance calling this method. It may be nil.

    didFailWithError

    The actual error object from the SOAPEngine. It may be nil.

  • This may be called in non-main threads.

    This is called when the SOAPEngine has finished parsing the input data.

    Declaration

    Swift

    public func soapEngine(_ inSOAPEngine: SOAPEngine!, didFinishLoadingWith inDict: [AnyHashable : Any]!, data inData: Data!)

    Parameters

    inSOAPEngine

    The SOAPEngine instance calling this method. It may be nil.

    didFinishLoadingWith

    The data, parsed into a Dictionary.

    data

    The data, unseasoned and uncooked.