forked from MissionSung/actionhero
/
say.js
45 lines (40 loc) · 1.27 KB
/
say.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var action = {};
/////////////////////////////////////////////////////////////////////
// metadata
action.name = "say";
action.description = "I will send a message to socket-connected users in the specified room";
action.inputs = {
"required" : ["room", "message"],
"optional" : []
};
action.outputExample = {
roomStatus: {
roomStatus: {
members: [
{ id:"MTI3LjAuMC4xNjQzNDAwLjUyNDU1NTk1MTgyMjU0OTE="},
{ id:"MTI3LjAuMDAwLjasdasgagUyNDU1NTk1MTgyMjU0OTE="}
],
membersCount: 2
}
}
}
/////////////////////////////////////////////////////////////////////
// functional
action.run = function(api, connection, next){
var room = connection.params.room;
var message = connection.params.message;
// extra stuff the socket users have that http users don't
connection.id = new Buffer(Math.random() + connection.remoteIP + Math.random()).toString('base64');
connection.room = room;
connection.messageCount = 0;
connection.public = {id: connection.id };
// say it!
api.chatRoom.socketRoomBroadcast(api, connection, message);
api.chatRoom.socketRoomStatus(api, room, function(status){
connection.response.roomStatus = status;
next(connection, true);
});
};
/////////////////////////////////////////////////////////////////////
// exports
exports.action = action;