Skip to content

Latest commit

 

History

History
62 lines (42 loc) · 1.81 KB

sip.js.subscriber.md

File metadata and controls

62 lines (42 loc) · 1.81 KB

Home > sip.js > Subscriber

Subscriber class

A subscriber establishes a Subscription (outgoing SUBSCRIBE).

Signature:

export declare class Subscriber extends Subscription 

Remarks

This is (more or less) an implementation of a "subscriber" as defined in RFC 6665 "SIP-Specific Event Notifications". https://tools.ietf.org/html/rfc6665

Example

// Create a new subscriber.
const targetURI = new URI("sip", "alice", "example.com");
const eventType = "example-name"; // https://www.iana.org/assignments/sip-events/sip-events.xhtml
const subscriber = new Subscriber(userAgent, targetURI, eventType);

// Add delegate to handle event notifications.
subscriber.delegate = {
  onNotify: (notification: Notification) => {
    // handle notification here
  }
};

// Monitor subscription state changes.
subscriber.stateChange.addListener((newState: SubscriptionState) => {
  if (newState === SubscriptionState.Terminated) {
    // handle state change here
  }
});

// Attempt to establish the subscription
subscriber.subscribe();

// Sometime later when done with subscription
subscriber.unsubscribe();

Constructors

Constructor Modifiers Description
(constructor)(userAgent, targetURI, eventType, options) Constructor.

Methods

Method Modifiers Description
subscribe(options) Subscribe to event notifications.
unsubscribe(options) Unsubscribe from event notifications.