onvif
    Preparing search index...

    Class Subscription

    Standalone pull-point subscription (separate from Events.globalSubscription). data - emitted when an event notification is received error - emitted when a pull / renew error occurs

    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
    connectionError: (error: ErrnoException) => void
    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.

      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>

    data: (msg: NotificationMessage) => void

    Event received from subscription

    Type Declaration

    error: (error: ErrnoException) => void

    Any subscription error

    Type Declaration

      • (error: ErrnoException): void
      • Parameters

        • error: ErrnoException

          Error object

        Returns void