onvif
    Preparing search index...

    Class Onvif

    Main ONVIF client. Connect to a device, then use lazy service namespaces (media, ptz, ...).

    import { Onvif } from 'onvif';

    const onvif = new Onvif({
    hostname: '192.168.1.13',
    port: 80,
    username: 'admin',
    password: 'admin',
    });

    onvif.on('warn', (err) => console.warn('warn', err.message));
    onvif.on('event', (msg) => console.log('event', msg.topic));

    await onvif.connect();
    console.log(await onvif.device.getDeviceInformation());
    console.log(onvif.profiles.map((p) => p.name));

    const stream = await onvif.media.getStreamUri({ protocol: 'RTSP' });
    console.log('RTSP', stream.uri);

    if (onvif.uri.ptz) {
    await onvif.ptz.continuousMove({ velocity: { x: 0.2, y: 0, zoom: 0 } });
    await new Promise((r) => setTimeout(r, 500));
    await onvif.ptz.stop();
    }

    // When finished with the device, close the client (see {@link Onvif.close}).
    await onvif.close();

    Hierarchy

    Index
    accessControl: AccessControl

    Lazy AccessControl service namespace.

    accessRules: AccessRules

    Lazy AccessRules service namespace.

    actionEngine: ActionEngine

    Lazy ActionEngine service namespace.

    activeMediaProfile?: ActiveMediaProfile

    Currently selected media pipeline defaults when methods omit tokens.

    activeMediaProfiles: ActiveMediaProfile[] = []

    Token bags for usable media pipelines (typically one per video source after connect).

    advancedSecurity: AdvancedSecurity

    Lazy AdvancedSecurity service namespace.

    agent: boolean | Agent | Agent
    analytics: Analytics

    Lazy Analytics service namespace.

    analyticsDevice: AnalyticsDevice

    Lazy AnalyticsDevice service namespace.

    appManagement: AppManagement

    Lazy AppManagement service namespace.

    capabilities: Capabilities
    closed: boolean = true

    Set by close; cleared by ensureOpen (constructor and connect). While closed, request rejects.

    credential: Credential

    Lazy Credential service namespace.

    defaultMedia: boolean = true

    Default for connects media` option when omitted. Callers (e.g. Discovery for access-only devices) may set OnvifOptions.defaultMedia.

    defaultProfile?: Profile
    defaultProfiles: Profile[] = []
    device: Device

    Lazy Device service namespace.

    deviceInformation?: GetDeviceInformationResponse
    deviceIO: DeviceIO

    Lazy DeviceIO service namespace.

    display: Display

    Lazy Display service namespace.

    doorControl: DoorControl

    Lazy DoorControl service namespace.

    events: Events

    Eager Events service (pull-point / WS-BaseNotification).

    hostname: string

    Hostname of the ONVIF device

    imaging: Imaging

    Lazy Imaging service namespace.

    media: Media

    Lazy Media service namespace.

    media2: Media2

    Lazy Media2 service namespace.

    media2Support: boolean = false

    Set during connect when the device advertises ONVIF Media2 (Profile T).

    password?: string

    Password for the connection

    path: string

    Path for the connection

    port: number

    Port for the connection

    preserveAddress: boolean = false
    profiles: Profile[] = []

    Profiles filled during connect (also copied onto Media when that module loads). Media1 shape; Media2-only devices store profiles mapped from Media2 GetProfiles.

    provisioning: Provisioning

    Lazy Provisioning service namespace.

    ptz: PTZ

    Lazy PTZ service namespace.

    receiver: Receiver

    Lazy Receiver service namespace.

    recording: Recording

    Lazy Recording service namespace.

    replay: Replay

    Lazy Replay service namespace.

    schedule: Schedule

    Lazy Schedule service namespace.

    search: Search

    Lazy Search service namespace.

    secureOptions: ConnectionOptions

    Secure options for the connection

    services: Service[] = []

    Filled by connect Device.getServices without loading the full Device module.

    thermal: Thermal

    Lazy Thermal service namespace.

    timeout: number
    timeShift?: number

    Clock offset between the device and this host (ms), set during time sync.

    uplink: Uplink

    Lazy Uplink service namespace.

    urn?: string
    username?: string

    Username for the connection

    useSecure: boolean

    Indicates if the device is using secure connection

    useWSSecurity: boolean

    Use WS-Security for the connection (this is the default and adds security headers in the SOAP messages)

    videoSources: VideoSource[] = []

    Video sources filled during connect (Media1 GetVideoSources or Media2 configuration fallback).

    xaddrs?: URL[]

    All XAddrs from WS-Discovery when this instance was found via Discovery.

    • Close the client connection to the ONVIF device.

      Call this when you are done talking to the camera and want to release the session: stop the pull-point event subscription (if any) and tear down the HTTP agents. Until then, the default keep-alive agent may keep TCP sockets open so later SOAP calls reuse them - which also keeps a Node process from exiting (common in short scripts and Jest).

      What this method does:

      1. Marks the client closed (further request fail until connect).
      2. Removes auto event subscribe/unsubscribe hooks so later on('event') is a no-op.
      3. Clears WS-BaseNotification push renew timers.
      4. Unsubscribes Events.globalSubscription (stops PullMessages / renew).
      5. Destroys the Events HTTP agent and the main SOAP agent created by this instance.

      Call connect again to reopen via ensureOpen (new agents + hooks). What it does not do: it is not an ONVIF "logout" RPC, and it does not destroy a custom or shared agent passed via OnvifOptions.agent (agent: false / non-Agent values are left alone). Safe to call more than once.

      Returns Promise<void>

      await onvif.connect();
      // ... use services
      await onvif.close();
    • Connect to the camera and fill device information properties. Pass { media: false } to skip profile / video-source discovery after GetServices. When media is omitted, uses defaultMedia (usually true; Discovery may set false for access-only door stations). Explicit { media: true | false } always wins. After close, ensureOpen recreates owned agents and event hooks first.

      Parameters

      Returns Promise<Onvif>

    • Build Digest Authorization header. Prefers SHA-256 when both MD5 and SHA-256 challenges are present. Public for v0.x Cam compatibility (digestAuth).

      Parameters

      • digestHeadersArray: string[]
      • requestOptions: RequestOptions

      Returns string

    • Parameters

      Returns { $: { "xmlns:xsd": string; "xmlns:xsi": string } }

    • Receive only date and time from cam (old behaviour, returns only Date object)

      Returns Promise<Date>

    • Parse a device XAddr into a URL. When OnvifOptions.preserveAddress is set, replace host/port with the constructor values (path and query kept). Used when filling uri and for event subscription Addresses.

      Parameters

      • address: string

      Returns URL

    • Switch the default Media Profile pipeline used when service methods omit tokens. Rebuilds activeMediaProfile (and syncs defaultProfile) from profiles. The profile must exist and reference a known video source when videoSources was loaded at connect.

      Parameters

      • profileToken: string

      Returns Promise<ActiveMediaProfile>

      await onvif.connect();
      await onvif.setActiveMediaProfile(onvif.profiles[1]!.token);
      const stream = await onvif.media.getStreamUri({ protocol: 'RTSP' });
    • Increment Digest auth nonce count and return the padded nc value. Public for v0.x Cam compatibility (updateNC).

      Returns string

    CONNECT: "connect" = 'connect'

    Indicates successfully connection connect

    onvif.on('connect', () => console.log('connected!'));
    
    ERROR: "error" = 'error'

    Indicates any errors except events errors error

    onvif.on('error', console.error);
    
    EVENT: "event" = 'event'

    Indicates any event from Onvif device. event

    onvif.on('event', (msg) => { console.log(new Date().toLocaleTimeString(), 'new event', msg); });
    
    EVENTS_ERROR: "eventsError" = 'eventsError'

    Indicates events errors eventsError

    onvif.on('eventsError', console.error);
    
    RAW_REQUEST: "rawRequest" = 'rawRequest'

    Indicates raw xml request to device. rawRequest

    onvif.on('rawRequest', (xml) => { console.log('-> request was', xml); });
    
    RAW_RESPONSE: "rawResponse" = 'rawResponse'

    Indicates raw xml response from device. rawResponse

    onvif.on('rawResponse', (xml) => { console.log('<- response was', xml); });
    
    REQUEST_BODY: "requestBody" = 'requestBody'

    Shows body of request

    WARN: "warn" = 'warn'

    Indicates any warnings warn

    onvif.on('warn', console.warn);