Session

Session

new Session()

Source:

Automatically created by supplying enableSync: true in ChatEngineCore.create. Access via Me#session.

Used to synchronize ChatEngine sessions between desktop and mobile, duplicate windows, etc. Sessions are the same when identical instance of ChatEngine and Me connects to ChatEngine. Should not be created directly.

Extends

Members

chats :Object

Source:

Stores a map of Chat objects that this Me has joined across all clients.

Type:
  • Object

sync :this

Source:

The Chat that syncs session between instances.

Type:
  • this

Methods

off(event)

Source:
Overrides:

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:
Overrides:

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:
Overrides:

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

Events

$.chat.join

Source:
Properties:
Name Type Description
chat Chat

The chat added to the user session.

Fired when another identical instance of ChatEngine and Me joins a Chat that this instance of ChatEngine is unaware of. Used to synchronize ChatEngine sessions between desktop and mobile, duplicate windows, etc. ChatEngine stores sessions on the server side identified by User#uuid.

Type:
  • object
Example
// Logged in as "Ian" in first window
ChatEngine.me.session.on('$.chat.join', (data) => {
    console.log('I joined a new chat in a second window!', data.chat);
});

// Logged in as "Ian" in second window
new ChatEngine.Chat('another-chat');

$.chat.leave

Source:
Properties:
Name Type Description
chat Chat

The chat removed from the user session.

Fired when another identical instance of ChatEngine with an identical Me leaves a Chat via Chat#leave.

Type:
  • object

$.group.restored

Source:
Properties:
Name Type Description
group string

The Chat#group that has been restored.

Fired when session has been restored at boot. Fired once per session group.

Type:
  • object