User

User

new User(uuid, state)

Source:

This is our User class which represents a connected client. User's are automatically created and managed by Chats, but you can also instantiate them yourself. If a User has been created but has never been authenticated, you will recieve 403s when connecting to their feed or direct Chats.

Parameters:
Name Type Description
uuid User#uuid

A unique identifier for this user.

state User#state

The User's state object synchronized between all clients of the chat.

Extends

Members

direct :Chat

Source:

Direct is a private channel that anybody can publish to but only the user can subscribe to. Great for pushing notifications or inviting to other chats. Users will not be able to communicate with one another inside of this chat. Check out the Chat#invite method for private chats utilizing User#direct.

Type:
Example
// me
me.direct.on('private-message', (payload) -> {
    console.log(payload.sender.uuid, 'sent your a direct message');
});

// another instance
them.direct.connect();
them.direct.emit('private-message', {secret: 42});

feed :Chat

Source:

Feed is a Chat that only streams things a User does, like 'startTyping' or 'idle' events for example. Anybody can subscribe to a User's feed, but only the User can publish to it. Users will not be able to converse in this channel.

Type:
Example
// me
me.feed.emit('update', 'I may be away from my computer right now');

// another instance
them.feed.connect();
them.feed.on('update', (payload) => {})

state

Source:

Gets the user state. See Me#update for how to assign state values.

Example
// State
let state = user.state;

(readonly) uuid :String

Source:

The User's unique identifier, usually a device uuid. This helps ChatEngine identify the user between events. This is public id exposed to the network. Check out the wikipedia page on UUIDs.

Type:
  • String

Methods

off(event)

Source:
Inherited From:

Stop a callback from listening to an event.

Example
let callback = function(payload;) {
   console.log('something happend!');
};
object.on('event', callback);
// ...
object.off('event', callback);
Parameters:
Name Type Description
event String

The event name

on(event, cb)

Source:
Overrides:

Listen for a specific event and fire a callback when it's emitted. Supports wildcard matching.

Example
// Get notified whenever someone joins the room
object.on('event', (payload) => {
    console.log('event was fired').
})

// Get notified of event.a and event.b
object.on('event.*', (payload) => {
    console.log('event.a or event.b was fired').;
})
Parameters:
Name Type Description
event String

The event name

cb function

The function to run when the event is emitted

onAny(callback)

Source:
Inherited From:

Listen for any event on this object and fire a callback when it's emitted

Example
object.onAny((event, payload) => {
    console.log('All events trigger this.');
});
Parameters:
Name Type Description
callback function

The function to run when any event is emitted. First parameter is the event name and second is the payload.

once(event, callback)

Source:
Inherited From:

Listen for an event and only fire the callback a single time

Example
object.once('message', => (event, payload) {
    console.log('This is only fired once!');
});
Parameters:
Name Type Description
event String

The event name

callback function

The function to run once

plugin(module)

Source:
Inherited From:
Tutorials:
  • Tutorial: using

Binds a plugin to this object

Parameters:
Name Type Description
module Object

The plugin module