lib/orbited_helper.rb
# Connects to the the STOMP server and subscribes to each channel in channels
Connects to the the STOMP server and subscribes to each channel in channels
Connects to the the STOMP server and subscribes to each channel in channels
def stomp_connect(channels, options = {})
    callbacks = options[:callbacks] || {}
    channels = [channels] unless channels.is_a? Array
    subscriptions = channels.map {|channel| "stomp.subscribe('/topic/#{channel}')"}.join(';')
    js = "Element.observe(window, 'load', function(){"
    js += "document.domain = document.domain; "
    js += "stomp = new STOMPClient(); "
    js += "stomp.onmessageframe = function(frame) {eval(frame.body)}; " unless callbacks[:onmessageframe]
    js += "stomp.onconnectedframe = function(frame) {#{subscriptions}}; " unless callbacks[:onconnectedframe]
    callbacks.each do |callback, function|
      js += "stomp.#{callback} = #{function}; "
    end
    user = options[:user] || OrbitedConfig.stomp_user || ''
    password = options[:password] || OrbitedConfig.stomp_password || ''
    host = OrbitedConfig.stomp_host
    port = OrbitedConfig.stomp_port
    stomp_connect = "stomp.connect('#{host}', #{port}, '#{user}', '#{password}'); "
    if options[:delayed_connect]
      js += "stomp.delayedConnect = function() {#{stomp_connect}};"
    else
      js += stomp_connect
    end
    js += "Element.observe(window, 'beforeunload', function(){stomp.reset()});"
    js += "});"
    javascript_tag js
  end
def stomp_connect ( channels , options = { } ) callbacks = options [ :callbacks ] || { } channels = [ channels ] unless channels . is_a? Array subscriptions = channels . map { | channel | "stomp.subscribe('/topic/#{channel}')" } . join ( ';' ) js = "Element.observe(window, 'load', function(){" js += "document.domain = document.domain; " js += "stomp = new STOMPClient(); " js += "stomp.onmessageframe = function(frame) {eval(frame.body)}; " unless callbacks [ :onmessageframe ] js += "stomp.onconnectedframe = function(frame) {#{subscriptions}}; " unless callbacks [ :onconnectedframe ] callbacks . each do | callback , function | js += "stomp.#{callback} = #{function}; " end user = options [ :user ] || OrbitedConfig . stomp_user || '' password = options [ :password ] || OrbitedConfig . stomp_password || '' host = OrbitedConfig . stomp_host port = OrbitedConfig . stomp_port stomp_connect = "stomp.connect('#{host}', #{port}, '#{user}', '#{password}'); " if options [ :delayed_connect ] js += "stomp.delayedConnect = function() {#{stomp_connect}};" else js += stomp_connect end js += "Element.observe(window, 'beforeunload', function(){stomp.reset()});" js += "});" javascript_tag js end
Connects to the the STOMP server and subscribes to each channel in channels
Connects to the the STOMP server and subscribes to each channel in channels
channels
options