Smart package for CodersTV' chat. It does not persist messages on Mongo.
To install in a new project:
> meteor add coderstv:chat
You need to configure at least one kind of account. Supported social plataforms now are:
For example, with Google:
meteor add accounts-google
<template name="index">
{{> chatroom}}
{{> loginButtons}}
</template>
Host is the same thing as room. To set a host, just do on your code:
Session.set('chatHost', 'room1');
If that session var is empty, Chat will try to get the current Path
(See Path
definition above).
If you don't want to have a global chat for entire website, you can set a Path so you can have a different chat box for each Path you set.
What's needed to do on javascript part is set a Path. Path is a reactive source of current page path (like window.location.pathname).
So, whenever it changes, it must be updated calling Path.set(path)
Users info will be at the Meteor.users
document.
To get users info, first, you need to manually expose users with the superchat attribute. For example, on your code, publish the users:
// server
Meteor.publish('chatUsers', function () {
return Meteor.users.find({/* add your filter*/}, {fields: {superchat: 1}});
});
Then, subscribe to the publication and turn on the subscripitions ready flag (also on your code):
Meteor.subscribe('chatUsers', function () {
Session.set('chatSubsReady', true);
});
Now you are going to have users information on chat.
Router.map(function () {
this.route('index', {
path: '/',
before: function () {
Path.set(Router.current().location.get().path);
}
});
});
Template.parentTemplate.rendered = function() {
$(window).resize(function () {
var height = $(this).height(); // you can set a value you want here
$('#chat-wrapper').height(height);
});
$(window).resize(); // trigger the resize
}
You will have to set up the Meteor-presence publication and subscription:
/* On Server */
Meteor.publish('superChatUserPresence', function (whereAt) {
var filter = whereAt ? {'state.whereAt': whereAt} : {};
return Meteor.presences.find(filter, {fields: {state: true, userId: true}});
});
/* On Client */
Meteor.Presence.state = function() {
return {
online: true,
whereAt: Path()
};
}
Deps.autorun(function () {
Meteor.subscribe('superChatUserPresence', Path());
});
Just put on the client, on startup (if you override the default object, make sure you put all those params):
Superchat = {
messageLimitOnScreen: 50,
defaultProfilePicture: 'http://i.imgur.com/HKSh9X9.png'
};