Independent chat module
npm install chat-module
js
var chat = require('chat');
chat.setup(server);
server : node server.
`
Initialize chat with namespace
`js
var chat = require('chat');
var room = chat.init(namespace);
`
* Init method has one parameters.
1. namespace: namespace for start chat.
-----------------------------------------room instance have following functions-----------------------
Initiate private chat
`js
room.initiateChat(initiatorId,reciverId,callback);
`
* Method has three parameters.
1. initiatorId: id of user who want to chat.
2. reciverId: id of user to whom wants to chat.
3. callback function.
Initiate group chat
`js
room.initiateGroupChat(initiatorId, participants, title, icon, callback);
`
* Method has four parameters.
1. initiatorId: id of user who creates group.
2. participants: array of user ids wants to added in group.
3. title: title for group.
4. icon: url for group image icon.(optional)
5. callback: callback function.
Post message on chat
`js
room.newMessage(chatId,fromUserId,browserId,message,callback);
`
* Method has four parameters.
1. chatId : chat id (mongo id) in which user wants to chat either private or group chat.
2. fromUserId : user id who send message.
3. message : object
ex. message = {
text: 'hi this is new message', // required field
file: 'url of shared file' // optional field
}
4. browserId: unique id of browser.
5. callback function.
Add participants in group chat (any member in group can add new participant)
`js
room.addParticipants(chatId,userId,participants,callback)
`
* Method has four parameters.
1. chatId : chat id (mongo id) in which user wants to add participants.
2. userId : user id who wants to add participants.
3. participants : array of user ids.
4. callback function.
Remove participants from group chat (only admin can remove participant from group)
`js
room.removeParticipants(chatId,userId,participants,callback)
`
* Method has four parameters.
1. chatId : chat id (mongo id) in which user wants to remove participants.
2. userId : id of group admin.
3. participants : array of user ids.
4. callback function.
Get chat by id
`js
room.getChat(chatId,userId,callback);
`
* Method has three parameters.
1. chatId : chat id (mongo id) user wants to get.
2. userId : id of user.
3. callback function.
Get chat messages
`js
room.getChatMessages(chatId,userId,skip,limit,callback);
`
* Method has three parameters.
1. chatId : chat id (mongo id).
2. userId : id of user.
3. skip: skip.
4. limit : limit.
5. callback function.
Update chat
`js
room.updateChat(chatId,userId,title,icon,callback);
`
* Method has five parameters.
1. chatId : chat id (mongo id).
2. userId : id of user exist in group.
3. title : title to be update //required
4. icon : url of group icon image.
5. callback function.
leave chat
`js
room.leaveChat(chatId, userId, callback);
`
* Method has three parameters.
1. chatId : chat id (mongo id).
2. userId : id of user who wants to leave chat.
5. callback function.
get chats
`js
room.getChats(userId, callback);
``