export const methods = { /* Creates (predictable) peer-to-peer chan if necessary, or check for lobby existence, then subscribe to it. Request: { "action": "STARTCHAT", "payload": "P" // or "C" => "P" = Peer-to-peer, "C" = (chat) Channel } reply: { "action": "STARTCHAT", "success": true, "payload" : "dynamically created chan" } */ action_STARTCHAT(action, payload, reqid){ if(typeof(payload)!='string'){ this.sendErr(action, 'Invalid payload', reqid); return; }; let recipientId = payload.substring(2); let chan; if(payload[0]=='P') { chan = (this.userId "P" = Peer-to-peer, "C" = (chat) Channel } reply: { "action": "SENDCHAT", "success": true, "payload" : null } */ action_SENDCHAT(action, payload, reqid){ //TODO: prevent unauthorized recipient !! let recipientId = payload.recipient.substring(2); let chan; payload.event = 'CHATMSG' if(payload.recipient[0]=='P') { chan = (this.userId "P" = Peer-to-peer, "C" = (chat) Channel } reply: { "action": "ISONLINE", "success": true, "payload" : } */ // You can only ask the satus of a list of usernames you know (and have the right to) action_ISONLINE(action, payload, reqid){ //TODO: can you really ask about those users ? (but that might cost too much time, because => ML?) if(!Array.isArray(payload)){ this.sendErr(action, 'Invalid payload', reqid); return; }; let onlineUsers = Object.keys(this.wssSrv.getOnlineUsers()); let reply = { 'action': action, 'payload': payload.filter((x) => (onlineUsers.indexOf(x)>-1)), 'success': true, }; if(reqid) reply.reqid = reqid; this.send(JSON.stringify(reply)); }, // Same as ISONLINE, but subscribe to watch changes action_WATCHUSERS(action, payload, reqid){ if(!Array.isArray(payload)){ this.sendErr(action, 'Invalid payload', reqid); return; } //TODO: can you really ask about those users ? (but that might cost too much time, because => ML?) this.usersWatched = payload; let reply = { 'action': action, 'payload': null, 'success': true, }; if(reqid) reply.reqid = reqid; this.send(JSON.stringify(reply)); }, /* Request: { "action": "CHANLST", "payload": { "filter": "ChatRoom*" } } reply: { "action": "CHANLST", "success": true, "payload" : ["ChatRoom1","ChatRoom2","ChatRoom_Experts"] } */ action_CHANLST(action, payload, reqid){ //TODO : Filter based on user rights!! // let reply = { 'action': action, 'payload': [ this.config.redis.basePrefix+"onlineUsers", this.config.redis.basePrefix+"system:chan1", this.config.redis.basePrefix+"proposals:updates" ],//this.config.redis.watchChannels, 'success': true, }; if(reqid) reply.reqid = reqid; this.send(JSON.stringify(reply)); }, }