spool.rb 999 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. class Sessions::Event::Spool < Sessions::Event::Base
  2. # get spool messages and send them to new client connection
  3. def run
  4. # error handling
  5. if @payload['timestamp']
  6. log 'notice', "request spool data > '#{Time.at(@payload['timestamp']).utc.iso8601}'"
  7. else
  8. log 'notice', 'request spool with init data'
  9. end
  10. if !@session || !@session['id']
  11. log 'error', "can't send spool, session not authenticated"
  12. return
  13. end
  14. spool = Sessions.spool_list(@payload['timestamp'], @session['id'])
  15. spool.each { |item|
  16. # create new msg to push to client
  17. if item[:type] == 'direct'
  18. log 'notice', "send spool to (user_id=#{@session['id']})"
  19. else
  20. log 'notice', 'send spool'
  21. end
  22. websocket_send(@client_id, item[:message])
  23. }
  24. # send spool:sent event to client
  25. log 'notice', 'send spool:sent event'
  26. {
  27. event: 'spool:sent',
  28. data: {
  29. timestamp: Time.now.utc.to_i,
  30. },
  31. }
  32. end
  33. end