Sha256: 76f0caf81f749e377ad3d6f8a23bb98b1a9554dbaf64a4ded4e5b56b818129d8

Contents?: true

Size: 1.66 KB

Versions: 22

Compression:

Stored size: 1.66 KB

Contents

# This file is part of CPEE.
# 
# CPEE is free software: you can redistribute it and/or modify it under the terms
# of the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
# 
# CPEE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.  See the GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along with
# CPEE (file COPYING in the main directory).  If not, see
# <http://www.gnu.org/licenses/>.

class NotificationsHandler < Riddl::Utils::Notifications::Producer::HandlerBase
  def ws_open(socket)
    @data.add_websocket(@key,socket)
  end
  def ws_close
    @data.unserialize_notifications!(:del,@key)
    @data.notify('handler/change', :instance => @data.instance)
  end
  def ws_message(data)
    begin
      doc = XML::Smart::string(data)
      callback = doc.find("string(/vote/@id)")
      result = doc.find("string(/vote)")
      @data.callbacks[callback].callback(result == 'true' ? true : false)
      @data.callbacks.delete(callback)
    rescue
      puts "Invalid message over websocket"
    end
  end

  def create
    @data.unserialize_notifications!(:cre,@key)
    @data.notify('handler/change', :instance => @data.instance)
  end
  def delete
    @data.unserialize_notifications!(:del,@key)
    @data.notify('handler/change', :instance => @data.instance)
  end
  def update
    @data.unserialize_notifications!(:upd,@key)
    @data.notify('handler/change', :instance => @data.instance)
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
cpee-1.3.199 lib/cpee/handler_notifications.rb
cpee-1.3.198 lib/cpee/handler_notifications.rb
cpee-1.3.197 lib/cpee/handler_notifications.rb
cpee-1.3.196 lib/cpee/handler_notifications.rb
cpee-1.3.195 lib/cpee/handler_notifications.rb
cpee-1.3.194 lib/cpee/handler_notifications.rb
cpee-1.3.193 lib/cpee/handler_notifications.rb
cpee-1.3.192 lib/cpee/handler_notifications.rb
cpee-1.3.191 lib/cpee/handler_notifications.rb
cpee-1.3.190 lib/cpee/handler_notifications.rb
cpee-1.3.189 lib/cpee/handler_notifications.rb
cpee-1.3.188 lib/cpee/handler_notifications.rb
cpee-1.3.187 lib/cpee/handler_notifications.rb
cpee-1.3.185 lib/cpee/handler_notifications.rb
cpee-1.3.184 lib/cpee/handler_notifications.rb
cpee-1.3.183 lib/cpee/handler_notifications.rb
cpee-1.3.181 lib/cpee/handler_notifications.rb
cpee-1.3.180 lib/cpee/handler_notifications.rb
cpee-1.3.179 lib/cpee/handler_notifications.rb
cpee-1.3.178 lib/cpee/handler_notifications.rb