weixin_39981093
weixin_39981093
2020-11-30 06:15

Firefox/Streaming HTTP

I'm trying to get it to work with either websockets or streaming http. This is the error I'm getting on the server:


Application Exception: #<nomethoderror: undefined method for nil:nilclass>
</nomethoderror:>
on the client i'm getting an 'invalid' response, but I suspect it's because of the server. It happens when I first try to send a message from the client to the server. Specifically a 'hello' message from the client to the server. All of this works fine in Chrome, but does not in Firefox or Safari. I'm not sure if I'm doing something wrong or if this is a genuine bug. Here's a bunch of code to help: ## EventMap
 ruby
WebsocketRails::EventMap.describe do
  subscribe :client_connected, to: ClientController, with_method: :client_connected
  subscribe :hello, to: ClientController, with_method: :on_hello_message
  subscribe :move, to: ClientController, with_method: :on_player_move
  #subscribe :new_user, to: ClientController, with_method: :new_user
  #subscribe :change_username, to: ClientController, with_method: :change_username
  subscribe :client_disconnected, to: ClientController, with_method: :client_disconnected
end

Controller

 ruby
class ClientController < WebsocketRails::BaseController

  def client_connected
    Rails.logger.debug 'client connected'
  end

  def on_hello_message
    Rails.logger.debug message

    facebook_id = message["facebook_id"]
    user = User.find_by_facebook_id("#{facebook_id}")
    if(user.nil?)
      user = User.new({:facebook_id => facebook_id.to_i})
    end

    send_message :welcome, {:player_id => "#{user.facebook_id}"}
    data_store[client_id] = user
    broadcast_message :spawn, {:player_id => "#{user.facebook_id}", :x => user.position_x, :y => user.position_y}
  end

  def on_player_move
    user = data_store[client_id]
    x = message["x"]
    y = message["y"]
    user.position_x = x
    user.position_y = y
    broadcast_message :move, {:player_id => "#{user.facebook_id}", :x => x, :y => y}
  end

  def client_disconnected
    user = data_store[client_id]
    Rails.logger.debug "client disconnected #{user.facebook_id}"
    [user.facebook_id] = nil
  end

end

Client JS

 javascript

    connected_callback: function(){
        // TODO: Get the Player Facebook ID from the browser via the browser login
        console.log('TODO: get facebook id from browser')
        jsApp.gameClient.player_info = {'facebook_id': '9287477388887'};
        jsApp.gameClient.sendHello(jsApp.gameClient.player_info);
    },


    sendHello: function(player) {
        this.sendMessage('hello',
                {'facebook_id':player.facebook_id});
    },

    sendMessage: function(event_name, json) {
        this.dispatcher.trigger(event_name, json);
    },




GIT
  remote: https://github.com/DanKnox/websocket-rails.git
  revision: dc7d375ff65be8f2c9f095e97331f970157a4be9
  specs:
    websocket-rails (0.1.5)
      faye-websocket
      rack
      rails
      thin

PATH
  remote: ~/lib/neology
  specs:
    neology (0.0.1)
      activesupport
      neography (~> 0.0.22)

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (3.2.0)
      actionpack (= 3.2.0)
      mail (~> 2.4.0)
    actionpack (3.2.0)
      activemodel (= 3.2.0)
      activesupport (= 3.2.0)
      builder (~> 3.0.0)
      erubis (~> 2.7.0)
      journey (~> 1.0.0)
      rack (~> 1.4.0)
      rack-cache (~> 1.1)
      rack-test (~> 0.6.1)
      sprockets (~> 2.1.2)
    activemodel (3.2.0)
      activesupport (= 3.2.0)
      builder (~> 3.0.0)
    activerecord (3.2.0)
      activemodel (= 3.2.0)
      activesupport (= 3.2.0)
      arel (~> 3.0.0)
      tzinfo (~> 0.3.29)
    activeresource (3.2.0)
      activemodel (= 3.2.0)
      activesupport (= 3.2.0)
    activesupport (3.2.0)
      i18n (~> 0.6)
      multi_json (~> 1.0)
    addressable (2.2.8)
    arel (3.0.2)
    builder (3.0.0)
    coffee-rails (3.2.2)
      coffee-script (>= 2.2.0)
      railties (~> 3.2.0)
    coffee-script (2.2.0)
      coffee-script-source
      execjs
    coffee-script-source (1.3.3)
    cookiejar (0.3.0)
    daemons (1.1.8)
    diff-lcs (1.1.3)
    em-http-request (0.3.0)
      addressable (>= 2.0.0)
      escape_utils
      eventmachine (>= 0.12.9)
    erubis (2.7.0)
    escape_utils (0.2.4)
    eventmachine (0.12.10)
    execjs (1.4.0)
      multi_json (~> 1.0)
    faye (0.8.3)
      cookiejar (>= 0.3.0)
      em-http-request (>= 0.3.0)
      eventmachine (>= 0.12.0)
      faye-websocket (>= 0.4.0)
      rack (>= 1.0.0)
      yajl-ruby (>= 1.0.0)
    faye-websocket (0.4.6)
      eventmachine (>= 0.12.0)
    hike (1.2.1)
    httparty (0.8.3)
      multi_json (~> 1.0)
      multi_xml
    i18n (0.6.0)
    journey (1.0.4)
    jquery-rails (2.0.2)
      railties (>= 3.2.0, < 5.0)
      thor (~> 0.14)
    json (1.7.3)
    libv8 (3.3.10.4)
    mail (2.4.4)
      i18n (>= 0.4.0)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    mime-types (1.19)
    multi_json (1.3.6)
    multi_xml (0.5.1)
    neography (0.0.27)
      httparty (>= 0.8.1)
      json
      oj
      os
      rake (>= 0.8.7)
      rubyzip
    oj (1.3.0)
    os (0.9.6)
    polyglot (0.3.3)
    rack (1.4.1)
    rack-cache (1.2)
      rack (>= 0.4)
    rack-ssl (1.3.2)
      rack
    rack-test (0.6.1)
      rack (>= 1.0)
    rails (3.2.0)
      actionmailer (= 3.2.0)
      actionpack (= 3.2.0)
      activerecord (= 3.2.0)
      activeresource (= 3.2.0)
      activesupport (= 3.2.0)
      bundler (~> 1.0)
      railties (= 3.2.0)
    railties (3.2.0)
      actionpack (= 3.2.0)
      activesupport (= 3.2.0)
      rack-ssl (~> 1.3.2)
      rake (>= 0.8.7)
      rdoc (~> 3.4)
      thor (~> 0.14.6)
    rake (0.9.2.2)
    rdoc (3.12)
      json (~> 1.4)
    rspec (2.11.0)
      rspec-core (~> 2.11.0)
      rspec-expectations (~> 2.11.0)
      rspec-mocks (~> 2.11.0)
    rspec-core (2.11.0)
    rspec-expectations (2.11.1)
      diff-lcs (~> 1.1.3)
    rspec-mocks (2.11.1)
    rspec-rails (2.11.0)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec (~> 2.11.0)
    rubyzip (0.9.9)
    sass (3.1.20)
    sass-rails (3.2.5)
      railties (~> 3.2.0)
      sass (>= 3.1.10)
      tilt (~> 1.3)
    sprockets (2.1.3)
      hike (~> 1.2)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    therubyracer (0.10.1)
      libv8 (~> 3.3.10)
    thin (1.4.1)
      daemons (>= 1.0.9)
      eventmachine (>= 0.12.6)
      rack (>= 1.0.0)
    thor (0.14.6)
    tilt (1.3.3)
    treetop (1.4.10)
      polyglot
      polyglot (>= 0.3.1)
    tzinfo (0.3.33)
    uglifier (1.2.6)
      execjs (>= 0.3.0)
      multi_json (~> 1.3)
    yajl-ruby (1.1.0)

PLATFORMS
  ruby

DEPENDENCIES
  coffee-rails (~> 3.2.1)
  faye
  jquery-rails
  json
  neography
  neology!
  rails (= 3.2.0)
  rspec-rails (~> 2.0)
  sass-rails (~> 3.2.3)
  therubyracer
  thin
  uglifier (>= 1.0.3)
  websocket-rails!

该提问来源于开源项目:websocket-rails/websocket-rails

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

6条回答

  • weixin_39981093 weixin_39981093 5月前

    Upgraded Firefox and it worked.

    点赞 评论 复制链接分享
  • weixin_39892019 weixin_39892019 5月前

    The new version is also much more stable as far as the HTTP streaming is concerned and adds a lot of useful functionality in general. I recommend upgrading after I release. Just not positive I will finish updating all of the documentation tonight.

    Thank you for using this gem.

    点赞 评论 复制链接分享
  • weixin_39892019 weixin_39892019 5月前

    I'm also working towards 100% cross browser compatibility. After I finish implementing the long polling transport, older firefox versions and IE all the way back to version 6 will be compatible out of the box.

    点赞 评论 复制链接分享
  • weixin_39981093 weixin_39981093 5月前

    That's all good stuff. Thanks for the work.

    点赞 评论 复制链接分享
  • weixin_39892019 weixin_39892019 5月前

    For some reason rubygems messed up the packaging of version 0.1.6 last night. It should be equivalent to the current master branch of this repository but if you use the version from rubygems it is broken right now. I am working on sorting this out right now.

    If you wish to use the current version right now just add the :git => "git://github.com/DanKnox/websocket-rails.git" after the gem in your Gemfile.

    Hopefully this is resolved soon.

    点赞 评论 复制链接分享
  • weixin_39892019 weixin_39892019 5月前

    The problem with the package has been resolved. Version 0.1.7 has been released and works well. It is definitely worth the upgrade. Hopefully I can get all the new functionality documented soon.

    点赞 评论 复制链接分享

相关推荐