Merging in persistent sorage solution

This commit is contained in:
perroned 2014-07-18 07:30:46 -07:00
commit 2461be4edf
13 changed files with 138 additions and 128 deletions

View File

@ -2,3 +2,5 @@ packages
build/
npm-debug.log
../node_modules/
../node_modules/hiredis/
../node_modules/redis/

View File

@ -12,3 +12,5 @@ less
bootstrap-3
iron-router
bootstrap
underscore
amplify

View File

@ -2,28 +2,40 @@ Handlebars.registerHelper 'equals', (a, b) -> # equals operator was dropped in M
a is b
# Allow access through all templates
Handlebars.registerHelper "setInSession", (k, v) -> Session.set k, v
Handlebars.registerHelper "getInSession", (k) -> Session.get k
Handlebars.registerHelper "setInSession", (k, v) -> SessionAmplify.set k,v #Session.set k, v
Handlebars.registerHelper "getInSession", (k) -> SessionAmplify.get k #Session.get k
# Allow access throughout all coffeescript/js files
@setInSession = (k, v) -> Session.set k, v
@getInSession = (k) -> Session.get k
@setInSession = (k, v) -> SessionAmplify.set k,v #Session.set k, v
@getInSession = (k) -> SessionAmplify.get k
# retrieve account for selected user
@getCurrentUserFromSession = ->
Meteor.Users.findOne("userId": Session.get("userId"))
Meteor.Users.findOne("userId": getInSession("userId"))
# retrieve account for selected user
Handlebars.registerHelper "getCurrentUser", =>
@window.getCurrentUserFromSession()
# toggle state of field in the database
@toggleCam = (context) ->
@toggleCam = (event) ->
# Meteor.Users.update {_id: context._id} , {$set:{"user.sharingVideo": !context.sharingVideo}}
# Meteor.call('userToggleCam', context._id, !context.sharingVideo)
@toggleMic = (context) ->
# Meteor.Users.update {_id: context._id} , {$set:{"user.sharingAudio": !context.sharingAudio}}
# Meteor.call('userToggleMic', context._id, !context.sharingAudio)
@toggleMic = (event) ->
if getInSession "isSharingAudio"
callback = ->
setInSession "isSharingAudio", false # update to no longer sharing
console.log "left voice conference"
webrtc_hangup callback # sign out of call
else
# create voice call params
username = "#{getInSession("userId")}-bbbID-#{getUsersName()}"
voiceBridge = "70827"
server = null
callback = (message) ->
console.log JSON.stringify message
setInSession "isSharingAudio", true
webrtc_call(username, voiceBridge, server, callback) # make the call
# toggle state of session variable
@toggleUsersList = ->
@ -37,30 +49,31 @@ Handlebars.registerHelper "getCurrentUser", =>
Meteor.methods
sendMeetingInfoToClient: (meetingId, userId) ->
Session.set("userId", userId)
Session.set("meetingId", meetingId)
Session.set("currentChatId", meetingId)
Session.set("meetingName", null)
Session.set("bbbServerVersion", "0.90")
Session.set("userName", null)
setInSession("userId", userId)
setInSession("meetingId", meetingId)
setInSession("currentChatId", meetingId)
setInSession("meetingName", null)
setInSession("bbbServerVersion", "0.90")
setInSession("userName", null)
Meteor.validUser = true # got info from server, user is a valid user
@getUsersName = ->
name = Session.get("userName") # check if we actually have one in the session
name = getInSession("userName") # check if we actually have one in the session
if name? then name # great return it, no database query
else # we need it from the database
user = Meteor.Users.findOne({'userId': Session.get("userId")})
user = Meteor.Users.findOne({'userId': getInSession("userId")})
if user?.user?.name
Session.set "userName", user.user.name # store in session for fast access next time
setInSession "userName", user.user.name # store in session for fast access next time
user.user.name
else null
@getMeetingName = ->
meetName = Session.get("meetingName") # check if we actually have one in the session
meetName = getInSession("meetingName") # check if we actually have one in the session
if meetName? then meetName # great return it, no database query
else # we need it from the database
meet = Meteor.Meetings.findOne({})
if meet?.meetingName
Session.set "meetingName", meet?.meetingName # store in session for fast access next time
setInSession "meetingName", meet?.meetingName # store in session for fast access next time
meet?.meetingName
else null
@ -68,13 +81,14 @@ Handlebars.registerHelper "getMeetingName", ->
window.getMeetingName()
Handlebars.registerHelper "isUserSharingAudio", (u) ->
u.voiceUser.talking
# u.voiceUser.talking
getInSession "isSharingAudio"
Handlebars.registerHelper "isUserSharingVideo", (u) ->
u.webcam_stream.length isnt 0
Handlebars.registerHelper "isCurrentUser", (id) ->
id is Session.get "userId"
id is getInSession("userId")
# retrieves all users in the meeting
Handlebars.registerHelper "getUsersInMeeting", ->

View File

@ -1,12 +1,29 @@
# These settings can just be stored locally in session, created at start up
Meteor.startup ->
Session.set "display_usersList", true
Session.set "display_navbar", true
Session.set "display_chatbar", true
Session.set "display_whiteboard", false
Session.set "display_chatPane", true
Session.set 'inChatWith', "PUBLIC_CHAT"
Session.set "joinedAt", getTime()
`this.SessionAmplify = _.extend({}, Session, {
keys: _.object(_.map(amplify.store(), function(value, key) {
return [key, JSON.stringify(value)]
})),
set: function (key, value) {
Session.set.apply(this, arguments);
amplify.store(key, value);
},
});`
SessionAmplify.set "display_usersList", true
SessionAmplify.set "display_navbar", true
SessionAmplify.set "display_chatbar", true
SessionAmplify.set "display_whiteboard", false
SessionAmplify.set "display_chatPane", true
SessionAmplify.set 'inChatWith', "PUBLIC_CHAT"
SessionAmplify.set "joinedAt", getTime()
SessionAmplify.set "isSharingAudio", false
@myTabs = new WatchValue()
@myTabs.updateValue [
{isActive:true, name:"Public", class: "publicChatTab"}
{isActive:false, name:"Options", class: "optionsChatTab"}
]
Template.header.events
"click .usersListIcon": (event) ->
@ -18,9 +35,18 @@ Template.header.events
"click .audioFeedIcon": (event) ->
toggleMic @
"click .signOutIcon": (event) ->
Meteor.call("userLogout", Session.get("meetingId"), Session.get("userId"))
Session.set "display_navbar", false # needed to hide navbar when the layout template renders
Router.go('logout');
Meteor.call("userLogout", getInSession("meetingId"), getInSession("userId"))
setInSession "display_navbar", false # needed to hide navbar when the layout template renders
# wipe session
Session.keys = {}
Session.keyDeps = {}
Session.keyDepsDeps = {}
# # wipe persisted session
SessionAmplify.keys = {}
SessionAmplify.keyDeps = {}
SessionAmplify.keyDepsDeps = {}
Meteor.validUser = false # invalidate user
Router.go('logout'); # navigate to logout
"click .hideNavbarIcon": (event) ->
toggleNavbar()
"click .settingsIcon": (event) ->
@ -29,4 +55,3 @@ Template.header.events
# Gets called last in main template, just an easy place to print stuff out
Handlebars.registerHelper "doFinalStuff", ->
console.log "-----Doing Final Stuff-----"
console.log "session: " + Session.get "joinedAt"

View File

@ -10,6 +10,7 @@
</div>
</body>
{{doFinalStuff}}
<audio id="remote-media" autoplay="autoplay" ></audio>
</template>
<template name="header">

View File

@ -1,74 +1,63 @@
Template.messageBar.helpers
# This method returns all messages for the user. It looks at the session to determine whether the user is in
#private or public chat. If true is passed, messages returned are from before the user joined. Else, the messages are from after the user joined
getMessagesInChat: (beforeJoin=true) ->
friend = chattingWith = Session.get('inChatWith') # the recipient(s) of the messages
friend = chattingWith = getInSession('inChatWith') # the recipient(s) of the messages
if chattingWith is 'PUBLIC_CHAT' # find all public messages
if beforeJoin
Meteor.Chat.find({'message.chat_type': chattingWith, 'message.from_time': {$lt: String(Session.get("joinedAt"))}})
Meteor.Chat.find({'message.chat_type': chattingWith, 'message.from_time': {$lt: String(getInSession("joinedAt"))}})
else
Meteor.Chat.find({'message.chat_type': chattingWith, 'message.from_time': {$gt: String(Session.get("joinedAt"))}})
Meteor.Chat.find({'message.chat_type': chattingWith, 'message.from_time': {$gt: String(getInSession("joinedAt"))}})
else
me = Session.get "userId"
me = getInSession("userId")
Meteor.Chat.find({ # find all messages between current user and recipient
'message.chat_type': 'PRIVATE_CHAT',
$or: [{'message.from_userid': me, 'message.to_userid': friend},{'message.from_userid': friend, 'message.to_userid': me}]
})
isUserInPrivateChat: -> # true if user is in public chat
Session.get('inChatWith') isnt "PUBLIC_CHAT"
# Must be be called when template is finished rendering or will not work
Template.messageBar.rendered = -> # Scroll down the messages box the amount of its height, which places it at the bottom
height = $('#chatScrollWindow').height()
$('#chatScrollWindow').scrollTop(height)
getInSession('inChatWith') isnt "PUBLIC_CHAT"
Template.tabButtons.events
'click .tab': (event) ->
# $('.tab').removeClass('active')
'click .tab': (event) -> ;
'click .publicChatTab': (event) ->
Session.set 'display_chatPane', true
Session.set 'inChatWith', 'PUBLIC_CHAT'
Meteor.call 'invalidateAllTabs', Session.get('userId'), false
toUpdate = Meteor.ChatTabs.findOne({name:"Public"})
Meteor.ChatTabs.update({_id: toUpdate._id}, {$set: 'isActive':true})
setInSession 'display_chatPane', true
setInSession 'inChatWith', 'PUBLIC_CHAT'
'click .optionsChatTab': (event) ->
Session.set 'display_chatPane', false
Meteor.call 'invalidateAllTabs', Session.get('userId'), false
toUpdate = Meteor.ChatTabs.findOne({name:"Options"})
Meteor.ChatTabs.update({_id: toUpdate._id}, {$set: 'isActive':true})
setInSession 'display_chatPane', false
'click .privateChatTab': (event) ->
Session.set 'display_chatPane', true
Session.set 'inChatWith', @userId
Meteor.call 'invalidateAllTabs', Session.get('userId'), false
console.log @name
toUpdate = Meteor.ChatTabs.findOne({name:@name})
if toUpdate? then Meteor.ChatTabs.update({_id: toUpdate._id}, {$set: 'isActive':true})
setInSession 'display_chatPane', true
setInSession 'inChatWith', @userId
'click .close': (event) -> # user closes private chat
toRemove = Meteor.ChatTabs.findOne({name:@name})
if toRemove? then Meteor.ChatTabs.remove({_id: toRemove._id}) # should probably delete chat history here too?
theName = @name
console.log theName
setInSession 'display_chatPane', true
setInSession 'inChatWith', 'PUBLIC_CHAT'
Session.set 'display_chatPane', true
Session.set 'inChatWith', 'PUBLIC_CHAT'
Meteor.call 'invalidateAllTabs', Session.get('userId'), false
toUpdate = Meteor.ChatTabs.findOne({name:"Public"})
Meteor.ChatTabs.update({_id: toUpdate._id}, {$set: 'isActive':true})
event.stopPropogation()
origTabs = myTabs.getValue()
newTabs = []
for x in origTabs
if x.name isnt theName
x.isActive = (x.name is "Public") # set public chat to default
newTabs.push x
myTabs.updateValue newTabs
$(".publicChatTab").addClass('active') # doesn't work when closing the tab that's not currently active :(
Template.chatInput.events
'keypress #newMessageInput': (event) -> # user pressed a button inside the chatbox
if event.which is 13 # Check for pressing enter to submit message
chattingWith = Session.get 'inChatWith'
chattingWith = getInSession('inChatWith')
messageForServer = { # construct message for server
"message": $("#newMessageInput").val()
"chat_type": if chattingWith is "PUBLIC_CHAT" then "PUBLIC_CHAT" else "PRIVATE_CHAT"
"from_userid": Session.get "userId"
"from_userid": getInSession("userId")
"from_username": getUsersName()
"from_tz_offset": "240"
"to_username": if chattingWith is "PUBLIC_CHAT" then "public_chat_username" else chattingWith
@ -77,22 +66,21 @@ Template.chatInput.events
"from_time": getTime()
"from_color": "0"
}
# console.log "time of join was " + Session.get("joinedAt")
# console.log 'Sending message to server:'
# console.log messageForServer
Meteor.call "sendChatMessagetoServer", Session.get("meetingId"), messageForServer
Meteor.call "sendChatMessagetoServer", getInSession("meetingId"), messageForServer
$('#newMessageInput').val '' # Clear message box
Template.optionsBar.events
'click .private-chat-user-entry': (event) -> # clicked a user's name to begin private chat
currUserId = Session.get "userId"
duplicate = Meteor.ChatTabs.findOne({'belongsTo':Session.get("userId"), 'userId': @userId})
currUserId = getInSession("userId")
duplicate = (x for x in myTabs.get() when x.userId is @userId)
if not duplicate and @userId isnt currUserId
if duplicate.length<=0 and @userId isnt currUserId
messageForServer = {
"message": "Hey #{@user.name}, its #{getUsersName()} lets start a private chat."
"chat_type": "PRIVATE_CHAT"
"from_userid": Session.get "userId"
"from_userid": getInSession("userId")
"from_username": getUsersName()
"from_tz_offset": "240"
"to_username": @user.name
@ -104,40 +92,27 @@ Template.optionsBar.events
# console.log 'Sending private message to server:'
# console.log messageForServer
Meteor.call "sendChatMessagetoServer", Session.get("meetingId"), messageForServer
Meteor.call "invalidateAllTabs", currUserId, false
# Give tab to us
Meteor.ChatTabs.insert({belongsTo: currUserId, name: @user.name, isActive: true, class: "privateChatTab", 'userId': @userId})
# Give tab to recipient to notify them
Meteor.ChatTabs.insert({belongsTo: @userId, name: getUsersName(), isActive: false, class: "privateChatTab", 'userId': currUserId})
Session.set 'display_chatPane', true
Session.set "inChatWith", @userId
# $('.tab').removeClass('active')
# Todo:
# just need a way to make the newly created tab active
# don't know how to do that right here since it doesn't get created here
# once that's handled, private chat is essentially done
# $("#tabButtonContainer").append("<li>fsdfdsf| </li>")
Meteor.call "sendChatMessagetoServer", getInSession("meetingId"), messageForServer
t = myTabs.getValue()
t = t.map (x) -> x.isActive = false; return x
t.push {name: @user.name, isActive: true, class: "privateChatTab", 'userId': @userId }
myTabs.updateValue t
$(".optionsChatTab").removeClass('active')
setInSession 'display_chatPane', true
setInSession "inChatWith", @userId
Template.tabButtons.helpers
getChatbarTabs: ->
console.log "displaying tabs"
t = Meteor.ChatTabs.find({}).fetch()
# console.log JSON.stringify t
t
myTabs.getValue()
makeTabButton: -> # create tab button for private chat or other such as options
console.log "#{@name} is " + if @isActive then "active" else "not active"
button = '<li '
button += 'class="'
button += 'active ' if @isActive
button += "#{@class} tab\"><a href=\"#\" data-toggle=\"tab\">#{@name}"
button += '&nbsp;<button class="close closeTab" type="button" >×</button>' if @name isnt 'Public' and @name isnt 'Options'
button += '</a></li>'
console.log "and here it is the button"
console.log button
button

View File

@ -79,7 +79,6 @@
<ul id="tabButtonContainer" class="nav nav-tabs">
{{#each getChatbarTabs}}
{{{makeTabButton}}}
<!-- {{makeTabButton}} -->
{{/each}}
</ul>
</template>

View File

@ -22,10 +22,3 @@ Meteor.methods
sendChatMessagetoServer: (meetingId, messageObject) ->
Meteor.call "publishChatMessage", meetingId, messageObject
invalidateAllTabs: (userId, setFirst=false) -> # make all tabs false
Meteor.ChatTabs.update({'belongsTo':userId}, { $set: { isActive:false} }, {multi:true})
if setFirst # able to specify the first to be active
console.log "setting first tab as active"
firstRecord = Meteor.ChatTabs.findOne({'belongsTo':userId, name:"Public"})
Meteor.ChatTabs.update({_id: firstRecord._id}, {$set: isActive:true})

View File

@ -3,4 +3,3 @@ Meteor.Chat = new Meteor.Collection("bbb_chat")
Meteor.Meetings = new Meteor.Collection("meetings")
Meteor.Shapes = new Meteor.Collection("shapes")
Meteor.Slides = new Meteor.Collection("slides")
Meteor.ChatTabs = new Meteor.Collection("bbb_chatTabs")

26
labs/meteor-client/lib/router.coffee Normal file → Executable file
View File

@ -1,3 +1,4 @@
Meteor.validUser = false # shared non-session variable to determine anywhere whether user is valid
Router.configure layoutTemplate: 'layout'
Router.map ->
@ -5,17 +6,11 @@ Router.map ->
path: "/meeting_id=*"
action: () ->
@redirect('/')
Meteor.subscribe 'users', Session.get('meetingId')
Meteor.subscribe 'chat', Session.get('meetingId')
Meteor.subscribe 'shapes', Session.get('meetingId')
Meteor.subscribe 'slides', Session.get('meetingId')
Meteor.subscribe 'chatTabs', Session.get('userId')
Meteor.subscribe 'meetings', Session.get('meetingId')
# I have no idea where to put this
Meteor.ChatTabs.insert({isActive:true, name:"Public", class: "publicChatTab", 'belongsTo': Session.get("userId")})
Meteor.ChatTabs.insert({isActive:false, name:"Options", class: "optionsChatTab", 'belongsTo': Session.get("userId")})
Meteor.subscribe 'users', getInSession('meetingId')
Meteor.subscribe 'chat', getInSession('meetingId')
Meteor.subscribe 'shapes', getInSession('meetingId')
Meteor.subscribe 'slides', getInSession('meetingId')
Meteor.subscribe 'meetings', getInSession('meetingId')
onBeforeAction: ()->
url = location.href
@ -42,6 +37,15 @@ Router.map ->
console.log "unable to extract the required information for the meeting from the URL"
@route "main",
path: "/"
onBeforeAction: ->
Meteor.subscribe 'users', getInSession('meetingId')
Meteor.subscribe 'chat', getInSession('meetingId')
Meteor.subscribe 'shapes', getInSession('meetingId')
Meteor.subscribe 'slides', getInSession('meetingId')
Meteor.subscribe 'meetings', getInSession('meetingId')
if Meteor.validUser is false # Don't let user in if they are not valid
@redirect("logout")
@route "logout",
path: "logout"

View File

@ -1,3 +1,4 @@
/bootstrap-3
/iron-router
/blaze-layout
/npm

View File

@ -12,8 +12,5 @@ Meteor.publish 'shapes', (meetingId) ->
Meteor.publish 'slides', (meetingId) ->
Meteor.Slides.find({meetingId: meetingId})
Meteor.publish 'chatTabs', (userId) ->
Meteor.ChatTabs.find({'belongsTo': userId})
Meteor.publish 'meetings', (meetingId) ->
Meteor.Meetings.find({meetingId: meetingId})

View File

@ -26,8 +26,6 @@ Meteor.startup ->
console.log "cleared Shapes Collection!"
Meteor.Slides.remove({})
console.log "cleared Slides Collection!"
Meteor.ChatTabs.remove({})
console.log "cleared ChatTabs Collection!"
# create create a PubSub connection, start listening
Meteor.redisPubSub = new Meteor.RedisPubSub(->