- Client
- new Client([opts])
- instance
- .readCabalSettingsFile() ⇒
object
- .getCabalSettings(key) ⇒
object
- .writeCabalSettings(key, settings)
- .resolveName(name, [cb])
- .createCabal() ⇒
Promise
- .addCabal(key, opts, cb) ⇒
Promise
- .focusCabal(key)
- .removeCabal(key, cb)
- .getDetails() ⇒
CabalDetails
- .getCabalKeys() ⇒
Array.<string>
- .getCurrentCabal() ⇒
CabalDetails
- .addCommand([name], [cmd])
- .removeCommand([name])
- .getCommands()
- .addAlias([longCmd], [shortCmd])
- .cabalToDetails([cabal]) ⇒
CabalDetails
- .addStatusMessage(message, channel, [cabal])
- .clearStatusMessages(channel, [cabal])
- .getUsers([cabal]) ⇒
Array.<Object>
- .getJoinedChannels([cabal]) ⇒
Array.<Object>
- .getChannels([cabal]) ⇒
Array.<Object>
- .subscribe(listener, [cabal])
- .unsubscribe(listener, [cabal])
- .getMessages([opts], [cb], [cabal])
- .searchMessages([searchString], [opts], [cabal]) ⇒
Promise
- .getNumberUnreadMessages(channel, [cabal]) ⇒
number
- .getNumberMentions([channel], [cabal])
- .getMentions([channel], [cabal])
- .focusChannel([channel], [keepUnread], [cabal])
- .unfocusChannel([channel], [newChannel], [cabal])
- .getCurrentChannel() ⇒
string
- .markChannelRead(channel, [cabal])
- .readCabalSettingsFile() ⇒
- static
- .getDatabaseVersion() ⇒
string
- .generateKey() ⇒
string
- .scrubKey(key) ⇒
string
- .getCabalDirectory() ⇒
string
- .getCabalSettingsFile() ⇒
string
- .getDatabaseVersion() ⇒
Create a client instance from which to manage multiple
cabal-core
instances.
Params
- opts
object
- aliases
object
- key/value pairs ofalias
->command name
- commands
object
- key/value pairs ofcommand name
->command object
, which has the following properties:- call
function
- command function with the following signaturecommand.call(cabal, res, arg)
- help
function
- return the help string for this command - category
Array.<string>
- a list of categories this commands belongs to - alias
Array.<string>
- a list of command aliases
- call
- config
object
- temp
boolean
- iftemp
is true no data is persisted to disk. - dbdir
string
- the directory to store the cabal data - preferredPort
string
- the port cabal will listen on for traffic
- temp
- maxFeeds
number
= 1000
- max amount of feeds to sync - persistentCache
object
- specify aread
andwrite
to create a persistent DNS cache- read
function
- async cache lookup function - write
function
- async cache write function
- read
- aliases
Read and parse the contents of the settings.yml file. If the file doesn't exist, return {}.
Returns: object
- the contents of the settings file
Get the settings for a given cabal from the settings.yml file. If the file doesn't exist or the given cabal has no settings, return the default settings.
Returns: object
- the cabal settings
Params
- key
string
- the cabal
Reads the settings from the settings.yml file, updates the settings for the given cabal, then writes the revised settings to the settings.yml file.
Params
- key
string
- the cabal - settings
object
- the cabal settings
Resolve the DNS shortname name
. If name
is already a cabal key, it will
be returned and the DNS lookup is aborted.
If name
is a whisper:// key, a DHT lookup for the passed-in key will occur.
Once a match is found, it is assumed to be a cabal key, which is returned.
Returns the cabal key in cb
. If cb
is null a Promise is returned.
Params
- name
string
- the DNS shortname, or whisper:// shortname - cb
function
- The callback to be called when lookup succeeds
Create a new cabal.
Returns: Promise
- a promise that resolves into a CabalDetails
instance.
Add/load the cabal at key
.
Returns: Promise
- a promise that resolves into a CabalDetails
instance.
Params
- key
string
- opts
object
- cb
function
- a function to be called when the cabal has been initialized.
Focus the cabal at key
, used when you want to switch from one open cabal to another.
Params
- key
string
Remove the cabal key
. Destroys everything related to it
(the data is however still persisted to disk, fret not!).
Params
- key
string
- cb
function
client.getDetails() ⇒ CabalDetails
Returns the details of a cabal for the given key.
Returns a list of cabal keys, one for each open cabal.
client.getCurrentCabal() ⇒ CabalDetails
Get the current cabal.
Add a command to the set of supported commands.
Params
- name
string
- the long-form command name - cmd
object
- the command object- help
function
- function returning help text - alias
array
- array of string aliases - call
function
- implementation of the command receiving (cabal, res, arg) arguments
- help
Remove a command.
Params
- name
string
- the command name
Get an object mapping command names to command objects.
Add an alias shortCmd
for longCmd
Params
- longCmd
string
- command to be aliased - shortCmd
string
- alias
client.cabalToDetails([cabal]) ⇒ CabalDetails
Returns a CabalDetails
instance for the passed in cabal-core
instance.
Params
- cabal
Cabal
= this.currentCabal
Add a status message, displayed client-side only, to the specified channel and cabal. If no cabal is specified, the currently focused cabal is used.
Params
- message
object
- channel
string
- cabal
Cabal
= this.currentCabal
Clear status messages for the specified channel.
Params
- channel
string
- cabal
Cabal
= this.currentCabal
Returns a list of all the users for the specified cabal. If no cabal is specified, the currently focused cabal is used.
Returns: Array.<Object>
- the list of users
Params
- cabal
Cabal
= this.currentCabal
Returns a list of channels the user has joined for the specified cabal. If no cabal is specified, the currently focused cabal is used.
Returns: Array.<Object>
- the list of Channels
Params
- cabal
Cabal
= this.currentCabal
Returns a list of all channels for the specified cabal. If no cabal is specified, the currently focused cabal is used.
Returns: Array.<Object>
- the list of Channels
Params
- cabal
Cabal
= this.currentCabal
Add a new listener for the update
event.
Params
- listener
function
- cabal
Cabal
= this.currentCabal
Remove a previously added listener.
Params
- listener
function
- cabal
Cabal
= this.currentCabal
Returns a list of messages according to opts
. If cb
is null, a Promise is returned.
Params
- opts
Object
- olderThan
number
- timestamp in epoch time. we want to get messages that are older than this ts - newerThan
number
- timestamp in epoch time. we want to get messages that are newer than this ts - amount
number
- amount of messages to get - channel
string
- channel to get messages from. defaults to currently focused channel
- olderThan
- cb
function
- the callback to be called when messages are retreived - cabal
Cabal
= this.currentCabal
Searches for messages that include the search string according to opts
.
Each returned match contains a message string and a matchedIndexes array containing the indexes at which the search string was found in the message
Returns: Promise
- a promise that resolves into a list of matches.
Params
- searchString
string
- string to match messages against - opts
Object
- olderThan
number
- timestamp in epoch time. we want to search through messages that are older than this ts - newerThan
number
- timestamp in epoch time. we want to search through messages that are newer than this ts - amount
number
- amount of messages to be search through - channel
string
- channel to get messages from. defaults to currently focused channel
- olderThan
- cabal
Cabal
= this.currentCabal
Returns the number of unread messages for channel
.
Params
- channel
string
- cabal
Cabal
= this.currentCabal
Returns the number of mentions in channel
.
Params
- channel
string
= "this.getCurrentChannel()"
- cabal
Cabal
= this.currentCabal
Returns a list of messages that triggered a mention in channel.
Params
- channel
string
= "this.getCurrentChannel()"
- cabal
Cabal
= this.currentCabal
View channel
, closing the previously focused channel.
Params
- channel
*
= this.getCurrentChannel()
- keepUnread
boolean
= false
- cabal
Cabal
= this.currentCabal
Close channel
.
Params
- channel
string
= "this.getCurrentChannel()"
- newChannel
string
= null
- cabal
Cabal
= this.currentCabal
Returns the currently focused channel name.
Mark the channel as read.
Params
- channel
string
- cabal
Cabal
= this.currentCabal
Get the current database version.
Returns a 64 character hex string i.e. a newly generated cabal key. Useful if you want to programmatically create a new cabal as part of a shell pipeline.
Removes URI scheme, URI search params (if present), and returns the cabal key as a 64 character hex string
Returns: string
- the scrubbed key
Params
- key
string
- the key to scrub
Example
Client.scrubKey('cabal://12345678...?admin=7331b4b..')
// => '12345678...'
Returns a string path of where all of the cabals are stored on the hard drive.
Returns: string
- the cabal directory
Returns a string path of where the cabal settings are stored on the hard drive.
Returns: string
- the cabal settings file path
Emits: update
, init
, info
, user-updated
, new-channel
, new-message
, private-message
, publish-message
, publish-private-message
, publish-nick
, status-message
, topic
, channel-focus
, channel-join
, channel-leave
, cabal-focus
, started-peering
, stopped-peering
- CabalDetails
- new CabalDetails({, done)
- .processLine([line], [cb])
- .publishMessage(msg, [opts], [cb])
- .publishNick(nick, [cb])
- .publishChannelTopic([channel], topic, cb)
- .getTopic([channel]) ⇒
string
- .getChannelMembers([channel]) ⇒
Array.<object>
- .addStatusMessage(message, [channel])
- .getChannels([opts]) ⇒
Array.<string>
- .getCurrentChannel() ⇒
string
- .getCurrentChannelDetails() ⇒
ChannelDetails
- .clearVirtualMessages([channel])
- .getPrivateMessageList()
- .isChannelPrivate()
- .joinPrivateMessage(channel)
- .leavePrivateMessage(channel)
- .publishPrivateMessage(msg, recipientKey, [cb])
- .getJoinedChannels() ⇒
Array.<string>
- .getLocalUser() ⇒
user
- .getLocalName() ⇒
string
- .joinChannel(channel)
- .leaveChannel(channel)
- .archiveChannel(channel, [reason], cb(err))
- .unarchiveChannel(channel, [reason], cb(err))
- .getUsers() ⇒
object
- ._destroy()
- "update"
- "init"
- "user-updated"
- "new-channel"
- "new-message"
- "private-message"
- "publish-message"
- "publish-private-message"
- "publish-nick"
- "status-message"
- "topic"
- "channel-focus"
- "channel-join"
- "channel-leave"
- "cabal-focus"
- "started-peering"
- "stopped-peering"
- "update"
- "info"
Params
- {
object
- cabal , commands, aliases } - done
function
- the function to be called after the cabal is initialized
Interpret a line of input from the user. This may involve running a command or publishing a message to the current channel.
Params
- line
string
- input from the user - cb
function
- callback called when the input is processed
Publish a message up to consumer. See
cabal-core
for the full list of options.
Params
- msg
object
- the full message object - opts
object
- options passed down to cabal.publish - cb
function
- callback function called when message is published
Example
cabalDetails.publishMessage({
type: 'chat/text',
content: {
text: 'hello world',
channel: 'cabal-dev'
}
})
Announce a new nickname.
Params
- nick
string
- cb
function
- will be called after the nick is published
Publish a new channel topic to channel
.
Params
- channel
string
= "this.chname"
- topic
string
- cb
function
- will be called when publishing has finished.
Returns: string
- The current topic of channel
as a string
Params
- channel
string
= "this.chname"
Return the list of users that have joined channel
.
Note: this can be a subset of all of the users in a cabal.
Params
- channel
string
= "this.chname"
Add a status message, visible locally only.
Params
- message
object
- channel
string
= "this.chname"
Returns: Array.<string>
- a list of all the channels in this cabal. Does not return channels with 0 members.
Params
- opts
object
Properties
Name | Type | Description |
---|---|---|
includeArchived | boolean |
Determines whether to include archived channels or not. Defaults to false. |
includePM | boolean |
Determines whether to include private message channels or not. Defaults to false. |
onlyJoined | boolean |
Determines whether to limit returned channels to only those that are joined or not. Defaults to false. |
Returns: string
- The name of the current channel
Returns: ChannelDetails
- A ChannelDetails object for the current chanel
Remove all of the virtual (i.e. status) messages associated with this channel. Virtual messages are local only.
Params
- channel
string
= "this.chname"
Get the list of currently opened private message channels.
Returns{string[]}: A list of all public keys you have an open PM with (hidden users are removed from list).
Query if the passed in channel name is private or not
Returns{boolean}: true if channel is private, false if not (or if it doesn't exist)
Join a private message channel if it is not already joined.
Params
- channel
string
- the key of the PM to join
Leave a private message channel if it has not already been left.
Params
- channel
string
- the key of the PM to leave
Send a private message to a recipient. Open and focus a new private message channel if one doesn't exist already.
Params
- msg
string
- a message object conforming to any type of chat message (e.g.chat/text
orchat/emote
), see CabalDetails.publishMessage for more information - recipientKey
string
- the public key of the recipient - cb
function
- optional callback triggered after trying to publish (returns err if failed)
Returns: Array.<string>
- A list of all of the channel names the user has joined. Excludes private message channels.
Returns: user
- The local user for this cabal.
Returns: string
- The local user's username (or their truncated public key, if their
username is not set)
Join a channel. This is distinct from focusing a channel, as this actually tracks changes and publishes a message announcing that you have joined the channel
Params
- channel
string
Leave a joined channel. This publishes a message announcing that you have left the channel.
Params
- channel
string
Archive a channel. Publishes a message announcing that you have archived the channel, applying it to the views of others who have you as a moderator/admin.
Params
- channel
string
- reason
string
- cb(err)
function
- callback invoked when the operation has finished, with error as its only parameter
Unarchive a channel. Publishes a message announcing that you have unarchived the channel.
Params
- channel
string
- reason
string
- cb(err)
function
- callback invoked when the operation has finished, with error as its only parameter
Returns: object
- all of the users in this cabal. Each key is the public key of its
corresponding user.
Destroy all of the listeners associated with this details
instance
Kind: event emitted by CabalDetails
Properties
Name | Type | Description |
---|---|---|
local | boolean |
|
online | boolean |
|
name | string |
The user's username |
key | string |
The user's public key |
flags | Map.<string, string> |
The user's array of flags per channel ("@" means cabal-wide"). Possible flags include {"admin", "mod", "normal", "hide", "mute", "block"}. |
Fires when the cabal has finished initialization
Kind: event emitted by CabalDetails
Fires when a user has updated their nickname
Kind: event emitted by CabalDetails
Properties
Name | Type | Description |
---|---|---|
key | string |
Public key of the updated user |
user | object |
Object containing user information |
user.name | string |
Current nickname of the updated user |
Fires when a new channel has been created
Kind: event emitted by CabalDetails
Properties
Name | Type | Description |
---|---|---|
channel | string |
Name of the created channel |
Fires when a new message has been posted
Kind: event emitted by CabalDetails
Properties
Name | Type | Description |
---|---|---|
channel | string |
Name of the channel the message was posted to |
author | object |
Object containing the user that posted the message |
author.name | string |
Nickname of the user |
author.key | string |
Public key of the user |
author.local | boolean |
True if user is the local user (i.e. at the keyboard and not someone else in the cabal) |
author.online | boolean |
True if the user is currently online |
message | object |
The message that was posted. See cabal-core for more complete message documentation. |
message.key | string |
Public key of the user posting the message (again, it's a quirk) |
message.seq | number |
Sequence number of the message in the user's append-only log |
message.value | object |
Message content, see cabal-core documentation for more information. |
Fires when a new private message has been posted
Kind: event emitted by CabalDetails
Properties
Name | Type | Description |
---|---|---|
channel | string |
The public key corresponding to the private message channel |
author | object |
Object containing the user that posted the message |
author.name | string |
Nickname of the user |
author.key | string |
Public key of the user |
author.local | boolean |
True if user is the local user (i.e. at the keyboard and not someone else in the cabal) |
author.online | boolean |
True if the user is currently online |
message | object |
The message that was posted. See cabal-core for more complete message documentation. |
message.key | string |
Public key of the user posting the message (again, it's a quirk) |
message.seq | number |
Sequence number of the message in the user's append-only log |
message.value | object |
Message content, see cabal-core documentation for more information. |
Fires when the local user has published a new message
Kind: event emitted by CabalDetails
Properties
Name | Type | Description |
---|---|---|
message | object |
The message that was posted. See cabal-core for more complete message documentation. |
message.type | string |
Message type that was posted, e.g. chat/text or chat/emote |
message.content | string |
Message contents, e.g. channel and text if chat/text |
message.timestamp | number |
The time the message was published |
Fires when the local user has published a new private message
Kind: event emitted by CabalDetails
Properties
Name | Type | Description |
---|---|---|
message | object |
The message that was posted. See cabal-core for more complete message documentation. |
message.type | string |
Message type that was posted, e.g. chat/text or chat/emote |
message.content | string |
Message contents, e.g. channel and text if chat/text |
message.timestamp | number |
The time the message was published |
Fires when the local user has published a new nickname
Kind: event emitted by CabalDetails
Properties
Name | Type | Description |
---|---|---|
name | string |
The nickname that was published |
Fires when a status message has been created. These are only visible by the local user.
Kind: event emitted by CabalDetails
Properties
Name | Type | Description |
---|---|---|
channel | string |
Name of the channel the message was published to |
message | object |
|
message.timestamp | number |
Publish timestamp |
message.text | string |
The published status message contents |
Fires when a new channel topic has been set
Kind: event emitted by CabalDetails
Properties
Name | Type | Description |
---|---|---|
channel | string |
Name of the channel with the new topic |
topic | string |
Name of the channel with the new topic |
Fires when the user has focused (i.e. switched to) a new channel
Kind: event emitted by CabalDetails
Properties
Name | Type | Description |
---|---|---|
channel | string |
Name of the focused channel |
Fires when a user has joined a channel
Kind: event emitted by CabalDetails
Properties
Name | Type | Description |
---|---|---|
channel | string |
Name of the joined channel |
key | string |
Public key of the user joining the channel |
isLocal | boolean |
True if it was the local user joining a new channel |
Fires when a user has leaveed a channel
Kind: event emitted by CabalDetails
Properties
Name | Type | Description |
---|---|---|
channel | string |
Name of the leaved channel |
key | string |
Public key of the user leaving the channel |
isLocal | boolean |
True if it was the local user leaving a new channel |
Fires when another cabal has been focused
Kind: event emitted by CabalDetails
Properties
Name | Type | Description |
---|---|---|
key | string |
Key of the focused cabal |
Fires when the local user has connected directly with another peer
Kind: event emitted by CabalDetails
Properties
Name | Type | Description |
---|---|---|
key | string |
Public key of the other peer |
name- | string |
Name of the other peer |
Fires when the local user has disconnected with another peer
Kind: event emitted by CabalDetails
Properties
Name | Type | Description |
---|---|---|
key | string |
Public key of the other peer |
name- | string |
Name of the other peer |
Fires when any kind of change has happened to the cabal.
Kind: event emitted by CabalDetails
Fires when a valid slash-command (/) emits output. See src/commands.js for all commands & their payloads.
Kind: event emitted by CabalDetails
Properties
Name | Type | Description |
---|---|---|
command | string |
The command that triggered the event & has emitted output |