OmniChat
Description
OmniChat is a framework to easily manage real-time communication across multiple service providers such as Facebook or Skype.
Quickstart
Installation
Install the module from npm: Not available yet.
npm install --save omni-chat
Clone from Github, build it and then link it:
git clone https://github.com/insa-frif/omni-chatcd omni-chatnpm installtypings installgulp project.dist.nodenpm link# And then in you project: npm link omni-chat
In order to connect to a service, you need to install some drivers
npm install --save palantiri-driver-facebook
Note that omni-chat
also exposes its Typescript definition. You can
install them with typings
.
typings install --save npm:omni-chat npm:palantiri-driver-facebook
Creating a connection
This section uses Typescript with ES6 syntax, but this package is fully compatible with Javascript ES5.
Start by importing omni-chat
and your drivers.
;;
The entry point for an omni-chat
application is called App
.
In order to use our Facebook driver, we need to register it on the App
object.
Each driver needs some driver-specific options to establish a connection:
the most common example are credentials for password-protected accounts.
Registering a driver means linking a driver to ConnectionProvider
: a
function that takes care of acquiring the driver-specific options and
return a Connection
.
// App.useDriver(connection, connectionProvider)omniChat.app.useDriver // We provide the registered Connection facebookDriver.Connection, // UserAccount provides data about the account we try to connect to;
Once you registered the driver, you can create a User and add him some accounts.
// Create a user; // Create a facebook account; // Add the account to the user.user.addAccountaccount;
The setup is now finished and you can use omni-chat
:
user.getAccounts .then
Drivers
OmniChat accepts any driver following the Palantiri Interface
.
Here are some officially supported drivers:
API
Structure
App
is the shared context. It contains:
- The list of available drivers/functions to acquire a palantiri connection
- The active palantiri connections
- The active users
User
a user represent a set of accounts owned by the same person. It contains:
- The list of accounts
- The list of active discussions
Account
is the high-level representation of everything you can do with an account
getOrCreateConnection
: internal use, allows to open the connection for this accountsendMessage(msg, discussion)
: sends a message to the discussion
Discussion
is an object representing a group of palantiri-discussions. For each discussion, it knows which local account to use.
Currently it does not support nested Discussions
recursively.
sendMessage(msg)
: sends the message to every sub-discussion
Interfaces
MetaDiscussions (cross-service discussions)
One of the greatest features offered by omni-chat
is the support
for cross-service discussions and messages.
These discussions and messages spanning across multiple services are
called MetaDiscussion
s and MetaMessage
s (as opposed to
single-account/single service SimpleDiscussion
s and SimpleMessage
s).
A MetaDiscussion
is a tree of of sub-discussions (either other
MetaDiscussion
s or SimpleDiscussion
s).
A SimpleDiscussion
is bound to a single UserAccount
, but a
MetaDiscussion
can contain sub-discussions using various accounts.
The restriction is that one User
has to own every UserAccount
involved.
;// ... Bluebird.join alice.getDiscussions
+-----------------------+ | MetaDiscussion | +-----------------------+ |user: Alice | +-----------------------+ |fbBob | |fbCharlie | |skypeDan | +--+-----------------+--+ | | | | v v+-----------------+-----+ +-----+-----------------+| SimpleDiscussion | | SimpleDiscussion || (facebook) | | (skype) |+-----------------------+ +-----------------------+|user: Alice | |user: Alice ||account: fbAlice | |account: skypeAlice |+-----------------------+ +-----------------------+|fbBob | |skypeDan ||fbCharlie | | |+-----------------------+ +-----------------------+
A MetaDiscussion can also link to discussions using the same driver. But beware that contact-accounts are relative to the user-account.
alice.getAccounts .then
+-----------------------+ | MetaDiscussion | +-----------------------+ |user: Alice | +-----------------------+ |fbBoss | |fbBob (fbAliceWork) | |fbMom | |fbBob (fbAlicePrivate) | +--+-----------------+--+ | | | | v v+-----------------+-----+ +-----+-----------------+| SimpleDiscussion | | SimpleDiscussion || (facebook) | | (facebook) |+-----------------------+ +-----------------------+|user: Alice | |user: Alice ||account: fbAliceWork | |account: fbAlicePrivate|+-----------------------+ +-----------------------+|fbBoss | |fbMom ||fbBob | |fbBob |+-----------------------+ +-----------------------+
You can even have multiple discussions using the same driver and the same account! A meta-discussion does not modify its child discussion unless you explicitly asks for it. If you want to reduce any redundancy, you can use the following methods to optimize the tree:
metaDiscussion.flatten()
This will traverse the tree and remove any intermediary MetaDiscussion
(every sub-discussion will be a SimpleDiscussion
).
metaDiscussion.mergeSimpleDiscussions()
This will try to merge every child SimpleDiscussion
linked by the same UserAccount
into a single SimpleDiscussion
. (There will be one SimpleDiscussion
per UserAccount
)
MetaMessages
By offering the possibility to communicate with multiple SimpleDiscussion
s,
a MetaDiscussion
has to also unify the SimpleMessage
s into MetaMessage
s.
A MetaMessage
is a tree of equivalent message. The message equivalence is defined as follow:
- The messages have the same
body
- The difference between the
creationDate
s is lesser than 5 minutes - The authors are equivalent. The authors are equivalent if one of the following is true:
- Both messages are
SimpleMessage
s and bothUserAccount
s are the same. - Both messages are
SimpleMessage
s and bothUserAccount
s are owned by the sameUser
- Both messages are
MetaMessage
s and both have the sameUser
- There is one
MetaMessage
and aSimpleMessage
whoseUserAccount
is owned by the sameUser
- TODO: define the equivalence of messages sent by the contacts...
- Both messages are
Dependency tree
+----------------------------------------------+ | | +--------->+ palantiri-interfaces | | | | | +-----+----------------+----------------+------+ | ^ ^ ^ | | | |+-----+------+ +-----+------+ +-----+------+ +-----+------+| | | palantiri- | | palantiri- | | palantiri- || | | driver- | | driver- | | driver- || | | facebook | | skype | | other || | +-----+------+ +-----+------+ +-----+------+| omni- | ^ ^ ^| chat | | | || | +-----+----------------+----------------+-------+| | | || +<--+ user-package || | | |+------------+ +-----------------------------------------------+