Home > sip.js > Subscriber
A subscriber establishes a Subscription (outgoing SUBSCRIBE).
Signature:
export declare class Subscriber extends Subscription
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
// 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();
Constructor | Modifiers | Description |
---|---|---|
(constructor)(userAgent, targetURI, eventType, options) | Constructor. |
Method | Modifiers | Description |
---|---|---|
subscribe(options) | Subscribe to event notifications. | |
unsubscribe(options) | Unsubscribe from event notifications. |