Class Channel
Extends
Resource.
Channel Resource
Defined in: channel.js.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
Channel(spire, data)
Represents a channel in the spire api.
|
| Field Attributes | Field Name and Description |
|---|---|
|
Actual data from the spire.io api.
|
|
|
Reference to spire object.
|
| Method Attributes | Method Name and Description |
|---|---|
|
name()
Returns the channel name.
|
|
|
publish(message, cb)
Publishes a message to the channel.
|
|
|
subscription(subName, cb)
Gets a subscription to a channel, creating it if necessary.
|
|
|
subscriptions(cb)
Gets all named subscriptions to a channel, using cached data if available.
|
- Methods borrowed from class Resource:
- authorization, capabilities, capability, get, getIfCapable, mediaType, request, schema, update, url
Class Detail
Channel(spire, data)
Represents a channel in the spire api.
- Parameters:
- {object} spire
- Spire object
- {object} data
- Channel data from the spire api
Field Detail
data
Actual data from the spire.io api.
spire
Reference to spire object.
Method Detail
{string}
name()
Returns the channel name.
- Returns:
- {string} Channel name
publish(message, cb)
Publishes a message to the channel.
The messages can be a string, or any json'able object.
spire.channel('myChannel', function (err, channel) {
channel.publish('hello world', function (err, message) {
if (!err) {
// Message has been published.
}
});
});
- Parameters:
- {string|object} message
- Message to publish
- {function (err|message)} cb
- Callback
subscription(subName, cb)
Gets a subscription to a channel, creating it if necessary.
spire.channel('myChannel', function (err, channel) {
channel.subscription('mySubscription', function (err, subscription) {
if (!err) {
// `subscription` is the new subscription.
}
});
});
- Parameters:
- {string} subName
- Subscription name
- {function (err|subscription)} cb
- Callback
subscriptions(cb)
Gets all named subscriptions to a channel, using cached data if available.
channel.subscriptions(function (err, subscriptions) {
if (!err) {
// `subscriptions` is a hash of subscriptions
}
});
- Parameters:
- {function (err|subscriptions)} cb
- Callback