Class jabberwerx.PubSubNode
Extends
jabberwerx.Entity.
Represents a publish-subscribe node.
This class provides the following events:
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
jabberwerx.PubSubNode(jid, node, ctrl)
Creates a new PubSubNode for the given JID, node, and PubSubController (or delegate). |
| Field Attributes | Field Name and Description |
|---|---|
|
Flag to determine if items are automatically retrieved from the pubsub node upon subscription. |
- Fields borrowed from class jabberwerx.Entity:
- features, identities, jid, node, properties
| Method Attributes | Method Name and Description |
|---|---|
|
createNode(cb)
Creates the node on the pubsub service. |
|
|
deleteNode(cb)
Deletes the node on the pubsub service. |
|
|
destroy()
Destroys this PubSubNode. |
|
|
getDelegatedFor(jid)
Retrieves the delegated PubSubNode for the given JID. |
|
|
getItems()
Retrieves the current items for this PubSubNode. |
|
|
publish(id, payload, cb)
Publishes an item to this PubSubNode. |
|
|
retract(id, cb)
Retracts an item from this PubSubNode. |
|
|
retrieve(cb)
Retrieves the items for this PubSubNode. |
|
|
subscribe(cb)
Subscribes to this PubSubNode. |
|
|
unsubscribe(cb)
Unsubscribes from this PubSubNode. |
- Methods borrowed from class jabberwerx.Entity:
- apply, getAllPresence, getDisplayName, getGroups, getPrimaryPresence, getResourcePresence, hasFeature, hasIdentity, isActive, matches, remove, setDisplayName, setGroups, toString, update, updatePresence
- Methods borrowed from class jabberwerx.JWModel:
- applyEvent, event, shouldBeSavedWithGraph
- Methods borrowed from class jabberwerx.JWBase:
- extend, getClassName, graphUnserialized, init, intercept, invocation, mixin, shouldBeSerializedInline, wasUnserialized, willBeSerialized
Creates a new PubSubNode for the given JID, node, and PubSubController (or delegate).
If this PubSubNode is created with a delegate, the owning controller is the delegate's controller. A delegated PubSubNode (one that has a delegate) is mostly just a container of published items, relying on the delegate to perform most operations.
NOTE: This type should not be constructed directly. Instead, use jabberwerx.PubSubController#node to obtain an instance.
- Parameters:
- {jabberwerx.JID} jid
- The JID
- {String} node
- The node
- {jabberwerx.PubSubController|jabberwerx.PubSubNode} ctrl
- The owning controller or delegate
- Throws:
- {TypeError}
- If {ctrl} is not valid; or if {node} is not valid
Flag to determine if items are automatically retrieved from the pubsub node upon subscription.
Creates the node on the pubsub service.
The callback, if defined, is expected to match the following:
function callback(err) {
this; // this PubSubNode
err; // the stanza error if create failed
}
- Parameters:
- {Function} cb Optional
- The callback
- Throws:
- {TypeError}
- If {cb} is not valid.
- {jabberwerx.Client.NotConnectedError}
- If the client is not connected
- {jabberwerx.PubSubNode.DelegatedNodeError}
- If this is a delegated node
Deletes the node on the pubsub service.
The callback, if defined, is expected to match the following:
function callback(err) {
this; // this PubSubNode
err; // the stanza error if create failed
}
- Parameters:
- {Function} cb Optional
- The callback
- Throws:
- {TypeError}
- If {cb} is not valid.
- {jabberwerx.Client.NotConnectedError}
- If the client is not connected
- {jabberwerx.PubSubNode.DelegatedNodeError}
- If this is a delegated node
Destroys this PubSubNode. This method unbinds registered callbacks, destroys any delegated PubSubNodes, and then calls the superclass' implementation.
Retrieves the delegated PubSubNode for the given JID. If such a delegated node does not exist, one is created.
- Parameters:
- {String|jabberwerx.JID} jid
- The JID of the delegated node
- Throws:
- {TypeError}
- if {jid} is not a valid JID
- {jabberwerx.PubSubNode.DelegatedNodeError}
- If this PubSubNode is already delegated.
- Returns:
- {jabberwerx.PubSubNode} The delegated node
Retrieves the current items for this PubSubNode. The returned array's items are indexed by both the natural array index (e.g. items[0], items[1]) and by the "item:{item.id}" (e.g. items["item:current"], items["item:some-random-id"]).
- Returns:
- {jabberwerx.PubSubItem[]} The current items
Publishes an item to this PubSubNode.
The callback, if defined, is expected to match the following:
function callback(err) {
this; // this PubSubNode
err; // the stanza error if publish failed
}
- Parameters:
- {String} id Optional
- The item id
- {Element} payload Optional
- The item payload
- {Function} cb Optional
- The callback
- Throws:
- {TypeError}
- If {cb} is not valid; If {paylaod} is defined and not an Element
- {jabberwerx.Client.NotConnectedError}
- If the client is not connected
Retracts an item from this PubSubNode.
The callback, if defined, is expected to match the following:
function callback(err) {
this; // this PubSubNode
err; // the stanza error if retract failed
}
- Parameters:
- {String} id
- The item id
- {Function} cb Optional
- The callback
- Throws:
- {TypeError}
- If {cb} is not valid; if {id} is empty or not a string
- {jabberwerx.Client.NotConnectedError}
- If the client is not connected
Retrieves the items for this PubSubNode. This method updates the list of items returned by #getItems with the current remote state of the node.
The callback, if defined, is expected to match the following:
function callback(err) {
this; // this PubSubNode
err; // the stanza error if retrieve failed
}
- Parameters:
- {Function} cb Optional
- The callback
- Throws:
- {TypeError}
- If {cb} is defined and not a function
- {jabberwerx.Client.NotConnectedError}
- If the client is not connected
- See:
- #getItems
Subscribes to this PubSubNode. This method sends the explicit subscription request to the node, using the connected user's bare JID.
The callback, if defined, is expected to match the following:
function callback(err) {
this; // this PubSubNode
err; // the stanza error if subscribe failed
}
- Parameters:
- {Function} cb Optional
- The callback
- Throws:
- {TypeError}
- If {cb} is defined and not a function
- {jabberwerx.Client.NotConnectedError}
- If the client is not connected
- See:
- #unsubscribe
Unsubscribes from this PubSubNode. This method sends the explicit unsubscription request to the node.
The callback, if defined, is expected to match the following:
function callback(err) {
this; // this PubSubNode
err; // the stanza error if unsubscribe failed
}
- Parameters:
- {Function} cb Optional
- The callback
- Throws:
- {TypeError}
- If {cb} is defined and not a function
- {jabberwerx.Client.NotConnectedError}
- If the client is not connected
- See:
- #subscribe