onvif
    Preparing search index...

    Class Subscription

    Standalone pull-point subscription (separate from Events.globalSubscription). data - emitted when an event notification is received error - pull / renew failure (triggers resubscribe), or a synchronous throw from a data listener (does not rebuild the pull point)

    import { Onvif, Subscription } from 'onvif';

    const onvif = new Onvif({ hostname: '192.168.1.13', username: 'admin', password: 'admin' });
    await onvif.connect();

    const sub = new Subscription(onvif, 'pullPoint', {
    filter: {
    topicExpression: [
    {
    expression: 'tns1:RuleEngine/PeopleDetector/People',
    dialect: 'http://www.onvif.org/ver10/tev/topicExpression/ConcreteSet',
    },
    ],
    },
    });

    sub.on('data', (msg) => console.log(msg.topic, msg.message));
    sub.on('error', (err) => console.error('subscription', err));
    await sub.subscribe();
    await sub.setSynchronizationPoint();

    // … later
    await sub.unsubscribe();

    Hierarchy

    Index
    eventReconnectMs: number
    subscription?: PullPointSubscription
    • Loop events from the subscription

      Returns Promise<void>

    • Pull messages from the subscription (long-poll).

      Parameters

      • Optionaloptions: Partial<PullMessages> & { signal?: AbortSignal }

        ONVIF PullMessages fields, plus optional signal to cancel the HTTP request before the device Timeout elapses (see innerDocs/events.md).

      Returns Promise<PullMessagesResponse>

      const ac = new AbortController();
      const timer = setTimeout(() => ac.abort(), 5000);
      try {
      const { notificationMessage } = await sub.pullMessages({
      timeout: 'PT1M',
      signal: ac.signal,
      });
      } catch (err) {
      if (!(err instanceof Error) || err.name !== 'AbortError') throw err;
      // cancelled
      } finally {
      clearTimeout(timer);
      }
    • Properties inform a client about property creation, changes and deletion in a uniform way. When a client wants to synchronize its properties with the properties of the device, it can request a synchronization point which repeats the current status of all properties to which a client has subscribed. The PropertyOperation of all produced notifications is set to “Initialized”. The Synchronization Point is requested directly from the SubscriptionManager which was returned in either the SubscriptionResponse or in the CreatePullPointSubscriptionResponse. The property update is transmitted via the notification transportation of the notification interface. This method is mandatory.

      Returns Promise<void>

    • Create a pull-point subscription and start the background eventPull loop.

      Overlapping subscribe/unsubscribe is coordinated with lifecycleGen: a Create that loses the race Unsubscribes its own pull-point by reference (without touching a newer winner's subscription). Unsubscribe stays non-blocking w.r.t. in-flight Create.

      Returns Promise<void>

    • The device shall provide the following Unsubscribe command for all SubscriptionManager endpoints returned by the CreatePullPointSubscription command. This command shall terminate the lifetime of a pull point.

      Parameters

      • resetAgent: boolean = true

        if we want to abort long-pulling connections, default true

      Returns Promise<void>

    connectionError: (error: Error) => void

    Soft network / renew issue; same subscription is retried

    data: (msg: NotificationMessage) => void

    Event received from subscription

    Type Declaration

    error: (error: Error) => void

    Pull/renew failure (resubscribe) or synchronous throw from a data listener (no resubscribe)

    Type Declaration

      • (error: Error): void
      • Parameters

        • error: Error

          Error object (may be OnvifError / SOAP fault / network Error)

        Returns void