Skip to content

Instantly share code, notes, and snippets.

@marcgg

marcgg/notes.rb

Last active Nov 20, 2016
Embed
What would you like to do?
class Note
def self.add(player_id, x, y)
key = "note_#{SecureRandom.hex}"
REDIS.set(key, {
x: x, y: y, player_id: player_id
}.to_json)
REDIS.expire(key, 5)
broadcast_note(player_id, x, y)
REDIS.incr("count_notes")
end
private
def self.broadcast_note(player_id, x, y)
puts "Broadcasting note by #{player_id}"
ActionCable.server.broadcast(
"game", {
type: "note",
player_id: player_id,
x: x, y: y
}
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment