2014-06-19 04:11:29 +08:00
|
|
|
Meteor.methods
|
2014-06-27 04:11:18 +08:00
|
|
|
validate: (meetingId, userId, authToken) ->
|
|
|
|
Meteor.redisPubSub.sendValidateToken(meetingId, userId, authToken)
|
2014-06-19 04:11:29 +08:00
|
|
|
|
2014-06-24 01:48:11 +08:00
|
|
|
userLogout: (meetingId, userId) ->
|
2014-06-28 03:16:04 +08:00
|
|
|
console.log "a user is logging out:" + userId
|
2014-06-24 01:48:11 +08:00
|
|
|
#remove from the collection
|
2014-06-28 03:16:04 +08:00
|
|
|
Meteor.call("removeUserFromCollection", meetingId, userId)
|
2014-06-24 01:48:11 +08:00
|
|
|
|
|
|
|
#dispatch a message to redis
|
2014-06-27 04:11:18 +08:00
|
|
|
Meteor.redisPubSub.sendUserLeavingRequest(meetingId, userId)
|
2014-06-24 01:48:11 +08:00
|
|
|
|
2014-07-02 22:47:22 +08:00
|
|
|
publishChatMessage: (meetingId, messageObject) ->
|
|
|
|
Meteor.redisPubSub.publishingChatMessage(meetingId, messageObject)
|
|
|
|
|
2014-06-19 04:11:29 +08:00
|
|
|
|
2014-06-12 03:26:46 +08:00
|
|
|
class Meteor.RedisPubSub
|
2014-06-27 02:09:39 +08:00
|
|
|
constructor: (callback) ->
|
2014-06-14 03:27:26 +08:00
|
|
|
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-27 02:09:39 +08:00
|
|
|
|
|
|
|
console.log("RPC: Subscribing message on channel: #{Meteor.config.redis.channels.fromBBBApps}")
|
2014-06-12 03:26:46 +08:00
|
|
|
|
2014-06-27 02:09:39 +08:00
|
|
|
#log.info
|
|
|
|
@subClient.on "psubscribe", Meteor.bindEnvironment(@_onSubscribe)
|
2014-06-17 23:22:12 +08:00
|
|
|
@subClient.on "pmessage", Meteor.bindEnvironment(@_onMessage)
|
2014-06-12 03:26:46 +08:00
|
|
|
|
2014-06-14 03:27:26 +08:00
|
|
|
@subClient.psubscribe(Meteor.config.redis.channels.fromBBBApps)
|
2014-06-27 02:09:39 +08:00
|
|
|
callback @
|
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
|
|
|
|
2014-06-24 01:48:11 +08:00
|
|
|
sendUserLeavingRequest: (meetingId, userId) ->
|
|
|
|
console.log "\n\n sending a user_leaving_request for #{meetingId}:#{userId}"
|
|
|
|
message = {
|
|
|
|
"payload": {
|
|
|
|
"meeting_id": meetingId
|
|
|
|
"userid": userId
|
|
|
|
},
|
|
|
|
"header": {
|
|
|
|
"timestamp": new Date().getTime()
|
|
|
|
"name": "user_leaving_request"
|
|
|
|
"version": "0.0.1"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if userId? and meetingId?
|
2014-07-02 22:47:22 +08:00
|
|
|
@pubClient.publish(Meteor.config.redis.channels.toBBBApps.users, JSON.stringify(message))
|
2014-06-24 01:48:11 +08:00
|
|
|
else
|
|
|
|
console.log "did not have enough information to send a user_leaving_request"
|
|
|
|
|
2014-06-27 02:09:39 +08:00
|
|
|
_onSubscribe: (channel, count) =>
|
2014-06-17 23:22:12 +08:00
|
|
|
console.log "Subscribed to #{channel}"
|
|
|
|
|
2014-06-27 02:09:39 +08:00
|
|
|
#grab data about all active meetings on the server
|
|
|
|
message = {
|
|
|
|
"header": {
|
|
|
|
"name": "get_all_meetings_request"
|
|
|
|
}
|
|
|
|
"payload": {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@pubClient.publish(Meteor.config.redis.channels.toBBBApps.meeting, JSON.stringify (message))
|
|
|
|
|
2014-06-17 23:22:12 +08:00
|
|
|
_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"
|
2014-06-20 04:25:27 +08:00
|
|
|
#console.log "\nchannel=" + channel
|
|
|
|
#console.log "correlationId=" + correlationId if correlationId?
|
|
|
|
console.log "eventType=" + message.header?.name #+ "\n"
|
2014-06-17 23:22:12 +08:00
|
|
|
#log.debug({ pattern: pattern, channel: channel, message: message}, "Received a message from redis")
|
2014-06-27 03:54:24 +08:00
|
|
|
console.log jsonMsg
|
2014-06-27 02:09:39 +08:00
|
|
|
|
2014-06-27 03:54:24 +08:00
|
|
|
if message.header?.name is "get_all_meetings_reply"
|
|
|
|
console.log "Let's store some data for the running meetings so that
|
|
|
|
when an HTML5 client joins everything is ready!"
|
2014-07-03 23:30:06 +08:00
|
|
|
listOfMeetings = message.payload?.meetings
|
2014-07-03 23:52:43 +08:00
|
|
|
for meeting in listOfMeetings
|
|
|
|
Meteor.call("addMeetingToCollection", meeting.meetingID, meeting.meetingName, meeting.recorded)
|
2014-06-27 02:09:39 +08:00
|
|
|
|
2014-06-27 04:11:18 +08:00
|
|
|
if message.header?.name is "get_users_reply" and message.payload?.requester_id is "nodeJSapp"
|
|
|
|
meetingId = message.payload?.meeting_id
|
|
|
|
users = message.payload?.users
|
|
|
|
for user in users
|
2014-06-27 23:37:33 +08:00
|
|
|
Meteor.call("addUserToCollection", meetingId, user)
|
2014-06-27 04:11:18 +08:00
|
|
|
|
|
|
|
if message.header?.name is "user_joined_message"
|
|
|
|
meetingId = message.payload.meeting_id
|
|
|
|
user = message.payload.user
|
2014-06-27 23:37:33 +08:00
|
|
|
Meteor.call("addUserToCollection", meetingId, user)
|
2014-06-27 04:11:18 +08:00
|
|
|
|
|
|
|
if message.header?.name is "user_left_message"
|
|
|
|
userId = message.payload?.user?.userid
|
|
|
|
meetingId = message.payload?.meeting_id
|
|
|
|
if userId? and meetingId?
|
2014-06-27 23:37:33 +08:00
|
|
|
Meteor.call("removeUserFromCollection", meetingId, userId)
|
2014-06-27 04:11:18 +08:00
|
|
|
|
2014-06-28 00:16:17 +08:00
|
|
|
if message.header?.name is "get_chat_history_reply" and message.payload?.requester_id is "nodeJSapp"
|
|
|
|
meetingId = message.payload?.meeting_id
|
|
|
|
for chatMessage in message.payload?.chat_history
|
|
|
|
Meteor.call("addChatToCollection", meetingId, chatMessage)
|
|
|
|
|
|
|
|
if message.header?.name is "send_public_chat_message"
|
|
|
|
messageObject = message.payload?.message
|
|
|
|
meetingId = message.payload?.meeting_id
|
|
|
|
Meteor.call("addChatToCollection", meetingId, messageObject)
|
2014-06-27 02:09:39 +08:00
|
|
|
|
|
|
|
publish: (channel, message) ->
|
|
|
|
console.log "Publishing channel=#{channel}, message=#{JSON.stringify(message)}"
|
|
|
|
@pubClient.publish(channel, JSON.stringify(message), (err, res) ->
|
|
|
|
console.log "err=" + err
|
|
|
|
console.log "res=" + res
|
|
|
|
)
|
2014-06-28 01:53:31 +08:00
|
|
|
|
2014-07-02 22:47:22 +08:00
|
|
|
publishingChatMessage: (meetingId, chatObject) =>
|
2014-06-28 01:53:31 +08:00
|
|
|
console.log "publishing a chat message to bbb-apps"
|
|
|
|
message = {
|
|
|
|
header : {
|
|
|
|
"timestamp": new Date().getTime()
|
|
|
|
"name": "send_public_chat_message_request"
|
|
|
|
}
|
|
|
|
payload: {
|
|
|
|
"message" : chatObject
|
|
|
|
"meeting_id": meetingId
|
2014-06-28 03:10:11 +08:00
|
|
|
"requester_id": chatObject.from_userid
|
2014-06-28 01:53:31 +08:00
|
|
|
}
|
|
|
|
}
|
2014-07-02 22:47:22 +08:00
|
|
|
console.log "publishing:" + JSON.stringify (message)
|
2014-06-28 02:41:25 +08:00
|
|
|
@pubClient.publish(Meteor.config.redis.channels.toBBBApps.chat, JSON.stringify (message))
|