Sha256: d8ca715cd19babe1d57d3e870f25b3372605c317500086defe2bd4165aa50d61

Contents?: true

Size: 1.65 KB

Versions: 82

Compression:

Stored size: 1.65 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

82 entries across 82 versions & 1 rubygems

Version Path
cpee-1.5.27 lib/cpee/handler_notifications.rb
cpee-1.5.26 lib/cpee/handler_notifications.rb
cpee-1.5.25 lib/cpee/handler_notifications.rb
cpee-1.5.24 lib/cpee/handler_notifications.rb
cpee-1.5.23 lib/cpee/handler_notifications.rb
cpee-1.5.22 lib/cpee/handler_notifications.rb
cpee-1.5.21 lib/cpee/handler_notifications.rb
cpee-1.5.20 lib/cpee/handler_notifications.rb
cpee-1.5.19 lib/cpee/handler_notifications.rb
cpee-1.5.18 lib/cpee/handler_notifications.rb
cpee-1.5.17 lib/cpee/handler_notifications.rb
cpee-1.5.16 lib/cpee/handler_notifications.rb
cpee-1.5.15 lib/cpee/handler_notifications.rb
cpee-1.5.13 lib/cpee/handler_notifications.rb
cpee-1.5.12 lib/cpee/handler_notifications.rb
cpee-1.5.11 lib/cpee/handler_notifications.rb
cpee-1.5.10 lib/cpee/handler_notifications.rb
cpee-1.5.9 lib/cpee/handler_notifications.rb
cpee-1.5.8 lib/cpee/handler_notifications.rb
cpee-1.5.7 lib/cpee/handler_notifications.rb