Moving more methods to server side only.

This commit is contained in:
perroned 2014-09-25 11:47:43 -07:00
parent 06b9919afd
commit d141729d89
4 changed files with 67 additions and 65 deletions

View File

@ -1,25 +1,4 @@
Meteor.methods
addChatToCollection: (meetingId, messageObject) ->
# manually convert time from 1.408645053653E12 to 1408645053653 if necessary (this is the time_from that the Flash client outputs)
messageObject.from_time = (messageObject.from_time).toString().split('.').join("").split("E")[0]
entry =
meetingId: meetingId
message:
chat_type: messageObject.chat_type
message: messageObject.message
to_username: messageObject.to_username
from_tz_offset: messageObject.from_tz_offset
from_color: messageObject.from_color
to_userid: messageObject.to_userid
from_userid: messageObject.from_userid
from_time: messageObject.from_time
from_username: messageObject.from_username
from_lang: messageObject.from_lang
id = Meteor.Chat.insert(entry)
console.log "added chat id=[#{id}]:#{messageObject.message}. Chat.size is now
#{Meteor.Chat.find({meetingId: meetingId}).count()}"
sendChatMessagetoServer: (meetingId, chatObject) ->
# check if this is a private or a public chat message
eventName = ->
@ -41,7 +20,7 @@ Meteor.methods
"message" : chatObject
"meeting_id": meetingId
"requester_id": chatObject.from_userid
publish Meteor.config.redis.channels.toBBBApps.chat, message)
publish Meteor.config.redis.channels.toBBBApps.chat, message
# --------------------------------------------------------------------------------------------
# Private methods on server
@ -59,3 +38,23 @@ Meteor.methods
'message.chat_type': 'PRIVATE_CHAT',
$or: [{'message.from_userid': u1._id, 'message.to_userid': u2._id},{'message.from_userid': u2._id, 'message.to_userid': u1._id}]
})
@addChatToCollection = (meetingId, messageObject) ->
# manually convert time from 1.408645053653E12 to 1408645053653 if necessary (this is the time_from that the Flash client outputs)
messageObject.from_time = (messageObject.from_time).toString().split('.').join("").split("E")[0]
entry =
meetingId: meetingId
message:
chat_type: messageObject.chat_type
message: messageObject.message
to_username: messageObject.to_username
from_tz_offset: messageObject.from_tz_offset
from_color: messageObject.from_color
to_userid: messageObject.to_userid
from_userid: messageObject.from_userid
from_time: messageObject.from_time
from_username: messageObject.from_username
from_lang: messageObject.from_lang
id = Meteor.Chat.insert(entry)
console.log "added chat id=[#{id}]:#{messageObject.message}. Chat.size is now #{Meteor.Chat.find({meetingId: meetingId}).count()}"

View File

@ -1,24 +1,24 @@
Meteor.methods
addMeetingToCollection: (meetingId, name, intendedForRecording, voiceConf, duration) ->
#check if the meeting is already in the collection
unless Meteor.Meetings.findOne({meetingId: meetingId})?
currentlyBeingRecorded = false # defaut value
id = Meteor.Meetings.insert(
meetingId: meetingId,
meetingName: name,
intendedForRecording: intendedForRecording,
currentlyBeingRecorded: currentlyBeingRecorded,
voiceConf: voiceConf,
duration: duration)
console.log "added meeting _id=[#{id}]:meetingId=[#{meetingId}]:name=[#{name}]:duration=[#{duration}]:voiceConf=[#{voiceConf}].
Meetings.size is now #{Meteor.Meetings.find().count()}"
# --------------------------------------------------------------------------------------------
# Private methods on server
# --------------------------------------------------------------------------------------------
@addMeetingToCollection = (meetingId, name, intendedForRecording, voiceConf, duration) ->
#check if the meeting is already in the collection
unless Meteor.Meetings.findOne({meetingId: meetingId})?
currentlyBeingRecorded = false # defaut value
id = Meteor.Meetings.insert(
meetingId: meetingId,
meetingName: name,
intendedForRecording: intendedForRecording,
currentlyBeingRecorded: currentlyBeingRecorded,
voiceConf: voiceConf,
duration: duration)
console.log "added meeting _id=[#{id}]:meetingId=[#{meetingId}]:name=[#{name}]:duration=[#{duration}]:voiceConf=[#{voiceConf}].Meetings.size is now #{Meteor.Meetings.find().count()}"
removeMeetingFromCollection: (meetingId) ->
if Meteor.Meetings.findOne({meetingId: meetingId})?
if Meteor.Users.find({meetingId: meetingId}).count() isnt 0
console.log "\n!!!!!removing a meeting which has active users in it!!!!\n"
id = Meteor.Meetings.findOne({meetingId: meetingId})
if id?
Meteor.Meetings.remove(id._id)
console.log "removed from Meetings:#{meetingId} now there are only
#{Meteor.Meetings.find().count()} meetings running"
@removeMeetingFromCollection = (meetingId) ->
if Meteor.Meetings.findOne({meetingId: meetingId})?
if Meteor.Users.find({meetingId: meetingId}).count() isnt 0
console.log "\n!!!!!removing a meeting which has active users in it!!!!\n"
id = Meteor.Meetings.findOne({meetingId: meetingId})
if id?
Meteor.Meetings.remove(id._id)
console.log "removed from Meetings:#{meetingId} now there are only #{Meteor.Meetings.find().count()} meetings running"

View File

@ -21,7 +21,7 @@ Meteor.methods
"name": "mute_user_request"
"version": "0.0.1"
publish Meteor.config.redis.channels.toBBBApps.voice, message)
publish Meteor.config.redis.channels.toBBBApps.voice, message
Meteor.Users.update({_id: mutee._id}, {$set:{'user.voiceUser.talking':false, 'user.voiceUser.muted':true}}, {multi: false})
userShareAudio: (meetingId, userId, user_id) ->
@ -42,7 +42,7 @@ Meteor.methods
"name": "user_left_voice_request"
"version": "0.0.1"
publish Meteor.config.redis.channels.toBBBApps.voice, message)
publish Meteor.config.redis.channels.toBBBApps.voice, message
updateVoiceUser {'user_id': user_id, talking:false, joined: true, muted:false}
else
console.log "did not have enough information to send a mute_user_request"
@ -65,7 +65,7 @@ Meteor.methods
"name": "mute_user_request"
"version": "0.0.1"
publish Meteor.config.redis.channels.toBBBApps.voice, message)
publish Meteor.config.redis.channels.toBBBApps.voice, message
Meteor.Users.update({_id: mutee._id}, {$set:{'user.voiceUser.talking':false, 'user.voiceUser.muted':true}}, {multi: false})
#
else
@ -100,7 +100,7 @@ Meteor.methods
"version": "0.0.1"
#publish to pubsub
publish Meteor.config.redis.channels.toBBBApps.users, message)
publish Meteor.config.redis.channels.toBBBApps.users, message
# meetingId: the meetingId which both users are in
# user_id: the _id of the user to have their hand raised
@ -131,7 +131,7 @@ Meteor.methods
"version": "0.0.1"
#publish to pubsub
publish Meteor.config.redis.channels.toBBBApps.users, message)
publish Meteor.config.redis.channels.toBBBApps.users, message
userLogout: (meetingId, userId, user_id) ->
console.log "a user is logging out:" + userId
@ -173,7 +173,7 @@ Meteor.methods
"version": "0.0.1"
if user.userId? and meetingId?
publish Meteor.config.redis.channels.toBBBApps.users, message)
publish Meteor.config.redis.channels.toBBBApps.users, message
else
console.log "did not have enough information to send a user_leaving_request"
@ -228,4 +228,3 @@ Meteor.methods
id = Meteor.Users.insert(entry)
console.log "added user id=[#{id}]:#{user.name}. Users.size is now #{Meteor.Users.find({meetingId: meetingId}).count()}"

View File

@ -1,4 +1,8 @@
Meteor.methods
#
# I dont know if this is okay to be server side. We need to call it from the router, but I don't know if any harm can be caused
# by the client calling this
#
# Construct and send a message to bbb-web to validate the user
validateAuthToken: (meetingId, userId, authToken) ->
@ -15,7 +19,7 @@ Meteor.methods
"name": "validate_auth_token"
if authToken? and userId? and meetingId?
publish Meteor.config.redis.channels.toBBBApps.meeting, message)
publish Meteor.config.redis.channels.toBBBApps.meeting, message
else
console.log "did not have enough information to send a validate_auth_token message"
@ -43,7 +47,7 @@ class Meteor.RedisPubSub
"header":
"name": "get_all_meetings_request"
"payload": {} # I need this, otherwise bbb-apps won't recognize the message
publish Meteor.config.redis.channels.toBBBApps.meeting, message)
publish Meteor.config.redis.channels.toBBBApps.meeting, message
_onMessage: (pattern, channel, jsonMsg) =>
# TODO: this has to be in a try/catch block, otherwise the server will
@ -67,7 +71,7 @@ class Meteor.RedisPubSub
# handle voice events
if message.header?.name in ['user_left_voice_message', 'user_joined_voice_message', 'user_voice_talking_message', 'user_voice_muted_message']
voiceUser = message.payload?.user?.voiceUser
Meteor.call('updateVoiceUser', meetingId, voiceUser)
updateVoiceUser meetingId, voiceUser
# listen only
if message.header?.name is 'user_listening_only'
@ -80,29 +84,29 @@ class Meteor.RedisPubSub
listOfMeetings = message.payload?.meetings
for meeting in listOfMeetings
# we currently do not have voice_conf or duration in this message.
Meteor.call("addMeetingToCollection", meeting.meetingID, meeting.meetingName, meeting.recorded, meeting.voiceBridge, meeting.duration)
addMeetingToCollection meeting.meetingID, meeting.meetingName, meeting.recorded, meeting.voiceBridge, meeting.duration
if message.header?.name is "get_users_reply" and message.payload?.requester_id is "nodeJSapp"
unless Meteor.Meetings.findOne({MeetingId: message.payload?.meeting_id})?
users = message.payload?.users
for user in users
user.timeOfJoining = message.header?.current_time # TODO this might need to be removed
Meteor.call("addUserToCollection", meetingId, user)
addUserToCollection meetingId, user
if message.header?.name is "user_joined_message"
user = message.payload.user
user.timeOfJoining = message.header?.current_time
Meteor.call("addUserToCollection", meetingId, user)
addUserToCollection meetingId, user
if message.header?.name is "user_left_message"
userId = message.payload?.user?.userid
if userId? and meetingId?
Meteor.call("removeUserFromCollection", meetingId, userId)
removeUserFromMeeting meetingId, userId
if message.header?.name is "get_chat_history_reply" and message.payload?.requester_id is "nodeJSapp"
unless Meteor.Meetings.findOne({MeetingId: message.payload?.meeting_id})?
for chatMessage in message.payload?.chat_history
Meteor.call("addChatToCollection", meetingId, chatMessage)
addChatToCollection meetingId, chatMessage
if message.header?.name is "send_public_chat_message" or message.header?.name is "send_private_chat_message"
messageObject = message.payload?.message
@ -110,14 +114,14 @@ class Meteor.RedisPubSub
# use current_time instead of message.from_time so that the chats from Flash and HTML5 have uniform times
messageObject.from_time = message.header?.current_time
Meteor.call("addChatToCollection", meetingId, messageObject)
addChatToCollection meetingId, messageObject
if message.header?.name is "meeting_created_message"
meetingName = message.payload?.name
intendedForRecording = message.payload?.recorded
voiceConf = message.payload?.voice_conf
duration = message.payload?.duration
Meteor.call("addMeetingToCollection", meetingId, meetingName, intendedForRecording, voiceConf, duration)
addMeetingToCollection meetingId, meetingName, intendedForRecording, voiceConf, duration
if message.header?.name is "presentation_shared_message"
presentationId = message.payload?.presentation?.id
@ -156,7 +160,7 @@ class Meteor.RedisPubSub
"version": "0.0.1"
if whiteboardId? and meetingId?
publish Meteor.config.redis.channels.toBBBApps.whiteboard, message)
publish Meteor.config.redis.channels.toBBBApps.whiteboard, message
else
console.log "did not have enough information to send a user_leaving_request"
@ -226,10 +230,10 @@ class Meteor.RedisPubSub
if Meteor.Meetings.findOne({meetingId: meetingId})?
console.log "there are #{Meteor.Users.find({meetingId: meetingId}).count()} users in the meeting"
for user in Meteor.Users.find({meetingId: meetingId}).fetch()
Meteor.call("removeUserFromCollection", meetingId, user.userId)
removeUserFromMeeting meetingId, user.userId
#TODO should we clear the chat messages for that meeting?!
unless message.header?.name is "disconnect_all_users_message"
Meteor.call("removeMeetingFromCollection", meetingId)
removeMeetingFromCollection meetingId
# --------------------------------------------------------------------------------------------
# Private methods on server