2014-06-19 04:11:29 +08:00
|
|
|
Meteor.methods
|
|
|
|
runRedisAndValidate: (meetingId, userId, authToken) ->
|
|
|
|
redisPubSub = new Meteor.RedisPubSub
|
|
|
|
redisPubSub.sendValidateToken(meetingId, userId, authToken)
|
|
|
|
|
|
|
|
|
2014-06-12 03:26:46 +08:00
|
|
|
class Meteor.RedisPubSub
|
2014-06-14 03:27:26 +08:00
|
|
|
constructor: () ->
|
|
|
|
console.log "constructor RedisPubSub"
|
2014-06-12 03:26:46 +08:00
|
|
|
|
2014-06-14 03:27:26 +08:00
|
|
|
@pubClient = redis.createClient()
|
|
|
|
@subClient = redis.createClient()
|
2014-06-12 03:26:46 +08:00
|
|
|
|
2014-06-17 23:22:12 +08:00
|
|
|
@subClient.on "psubscribe", Meteor.bindEnvironment(@_onSubscribe )
|
|
|
|
@subClient.on "pmessage", Meteor.bindEnvironment(@_onMessage)
|
2014-06-12 03:26:46 +08:00
|
|
|
|
|
|
|
#log.info
|
2014-06-14 03:27:26 +08:00
|
|
|
console.log("RPC: Subscribing message on channel: #{Meteor.config.redis.channels.fromBBBApps}")
|
|
|
|
@subClient.psubscribe(Meteor.config.redis.channels.fromBBBApps)
|
2014-06-19 04:11:29 +08:00
|
|
|
@
|
2014-06-12 03:26:46 +08:00
|
|
|
|
2014-06-14 03:27:26 +08:00
|
|
|
# Construct and send a message to bbb-web to validate the user
|
|
|
|
sendValidateToken: (meetingId, userId, authToken) ->
|
|
|
|
console.log "\n\n i am sending a validate_auth_token with " + userId + "" + meetingId
|
2014-06-17 23:22:12 +08:00
|
|
|
|
2014-06-14 02:01:32 +08:00
|
|
|
message = {
|
|
|
|
"payload": {
|
|
|
|
"auth_token": authToken
|
|
|
|
"userid": userId
|
|
|
|
"meeting_id": meetingId
|
|
|
|
},
|
|
|
|
"header": {
|
|
|
|
"timestamp": new Date().getTime()
|
2014-06-14 03:27:26 +08:00
|
|
|
"reply_to": meetingId + "/" + userId
|
2014-06-14 02:01:32 +08:00
|
|
|
"name": "validate_auth_token"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if authToken? and userId? and meetingId?
|
2014-06-14 03:27:26 +08:00
|
|
|
@pubClient.publish(Meteor.config.redis.channels.toBBBApps.meeting, JSON.stringify(message))
|
|
|
|
else
|
|
|
|
console.log "did not have enough information to send a validate_auth_token message"
|
2014-06-17 23:22:12 +08:00
|
|
|
|
|
|
|
_onSubscribe: (channel, count) ->
|
|
|
|
console.log "Subscribed to #{channel}"
|
|
|
|
|
|
|
|
_onMessage: (pattern, channel, jsonMsg) =>
|
|
|
|
# TODO: this has to be in a try/catch block, otherwise the server will
|
|
|
|
# crash if the message has a bad format
|
2014-06-18 01:04:58 +08:00
|
|
|
|
2014-06-17 23:22:12 +08:00
|
|
|
message = JSON.parse(jsonMsg)
|
|
|
|
correlationId = message.payload?.reply_to or message.header?.reply_to
|
2014-06-18 01:04:58 +08:00
|
|
|
|
2014-06-17 23:22:12 +08:00
|
|
|
unless message.header?.name is "keep_alive_reply"
|
|
|
|
console.log "\nchannel=" + channel
|
|
|
|
console.log "correlationId=" + correlationId if correlationId?
|
|
|
|
console.log "eventType=" + message.header?.name + "\n"
|
|
|
|
#log.debug({ pattern: pattern, channel: channel, message: message}, "Received a message from redis")
|
2014-06-18 01:04:58 +08:00
|
|
|
console.log jsonMsg
|
2014-06-17 23:22:12 +08:00
|
|
|
|
|
|
|
if message.header?.name is "user_joined_message"
|
|
|
|
Meteor.call("addToCollection", message.payload.user.userid, message.payload.meeting_id);
|