Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

I dont even remember

  • Loading branch information...
commit ff9ad07d97157c17a5df3802499dbb8d11878b23 1 parent 16e2cda
@azram19 authored
Showing with 15 additions and 12 deletions.
  1. +3 −4 dev/client/views/lobby.coffee
  2. +12 −8 dev/server/communicator.coffee
View
7 dev/client/views/lobby.coffee
@@ -15,12 +15,12 @@ class LobbyView extends Backbone.View
#Listen to the server
@communicator.on 'message:new', @handleServerMessage
- KeyboardJS.bind.key 'enter', @newMessage
+ KeyboardJS.bind.key 'enter', @newMessage, () ->
+ @$el.find( 'textarea:focus' ).val ''
#Add new message to the chat
addMessage: ( model ) =>
console.log "Lobby: New message"
- console.debug msg
msg = @messageTemplate message: model.toJSON()
@$el.find( '.chat ul' ).append msg
@@ -55,8 +55,7 @@ class LobbyView extends Backbone.View
render: =>
msgs = @messagesTemplate messages: @collection.toJSON()
- console.debug msgs
-
+
@$el.find( '.chat ul' ).html msgs
window['LobbyView'] = LobbyView
View
20 dev/server/communicator.coffee
@@ -11,7 +11,9 @@ message passing to and between clients.
class Communicator
constructor: ( @app, @channel ) ->
self = @
- _.extend @, Backbone.Events
+ @com = {}
+
+ _.extend @com, Backbone.Events
@connected = 0
@clients = {}
@@ -51,11 +53,13 @@ class Communicator
@clients[ client.getId() ] = client
socket.on 'message:add', ( data ) ->
- socket.broadcast.to( socket.getChannel() ).emit 'message:new', data
+ socket.broadcast.to( client.getChannel() ).emit 'message:new', data
+ #client want to join a channel
socket.on 'join:channel', ( channel, fn ) ->
data = socket.handshake.session
+ #leave a channel user is currently conencted to
@clientLeaveChannel client
@clientJoinChannel client, channel
@@ -71,6 +75,8 @@ class Communicator
data.currentChannel = null
+ setInterval @ping, 1000
+
clientLeaveChannel: ( client ) ->
channel = client.getChannel()
@@ -90,16 +96,14 @@ class Communicator
clients = @sockets.clients()
ping = ( client ) ->
- data = socket.handshake.session
startTime = new Date()
- client.volatile.emit 'ping', 1, ->
+ client.emit 'ping'
+ client.once 'pong', ->
- #compute the lag, save it
- stopTime = new Data()
+ #compute the lag
+ stopTime = new Date()
lag = ( stopTime - startTime ) / 2
- data.lag = lag
- data.save()
#inform client about the lag
client.emit 'lag', lag
Please sign in to comment.
Something went wrong with that request. Please try again.