Me

Me

new Me(uuid)

Source:

Represents the client connection as a special User with write permissions. Has the ability to update it's state on the network. An instance of Me is returned by the ChatEngine.connect() method.

Parameters:
Name Type Description
uuid String

The uuid of this user

Extends

Members

direct :Chat

Source:
Inherited From:

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:
Inherited From:

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) => {})

session :Boolean

Source:
See:

Link sessions between multiple identical instances of ChatEngine. Returns Session when enableSync: true supplied to ChatEngine.create()..

Type:
  • Boolean

state

Source:
Inherited From:

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

Example
// State
let state = user.state;

(readonly) uuid :String

Source:
Inherited From:

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

update(state, chat)

Source:
Overrides:
  • User#update

Update Me's state in a Chat. All other Users will be notified of this change via $.state. Retrieve state at any time with User#state.

Example
// update state
me.update({value: true});
Parameters:
Name Type Description
state Object

The new state for Me

chat Chat

An instance of the Chat where state will be updated. Defaults to ChatEngine.global.

Fires:
  • $.state

Events

$.invite

Source:
Tutorials:
  • Tutorial: private
Properties:
Name Type Description
chat Chat

The chat the event was emitted on. This is the User's direct chat and NOT the chat invited to.

chatengineSDK string

The ChatEngine client version number.

data object

The message payload data.

Properties
Name Type Description
channel string

The Chat#channel for the invited chat. Use this to create a new Chat.

event string

The event fired.

sender User

The User that sent the invite.

timetoken string

The 17 digit timetoken when the message was sent.

Notifies Me that they've been invited to a new private Chat. Fired by the Chat#invite method.

Type:
  • object
Example
me.direct.on('$.invite', (payload) => {
   let privChat = new ChatEngine.Chat(payload.data.channel));
});