Class: SyncHandler

Inherits:
Handler
  • Object
show all
Defined in:
lib/handler/sync_handler.rb

Instance Method Summary collapse

Instance Method Details

#recv(server, connection, packet) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/handler/sync_handler.rb', line 2

def recv(server,connection,packet)
  case packet.id
    when Protocol::SYNC
      reply = Packet.new
      reply.id = Protocol::SYNC
      reply["x"] = packet["x"]
      reply["y"] = packet["y"]
      reply["oid"] = packet["oid"]
      
      server.pubsub.publish(packet.ch, reply)
    when Protocol::PUSH_OBJECT
      reply = Packet.new
      reply.id = Protocol::OBJECT_ID
      reply["oid"] = $oid
      $oid += 1  

      connection.send reply
      
      reply.id = Protocol::PUSH_OBJECT
      reply["x"] = packet["x"]
      reply["y"] = packet["y"]
      
      server.pubsub.publish(packet.ch, reply)
    when Protocol::DELETE_OBJECT
      reply = Packet.new
      reply.id = Protocol::DELETE_OBJECT
      reply["oid"] = packet["old"]
      
      server.pubsub.publish(packet.ch, reply)
  end
end