These are chat archives for opal/opal

8th
Apr 2017
Frederic ZINGG
@fzingg
Apr 08 2017 18:41

HI,
i'm trying to run a simple pure JS file example using opal-browser.
i have included those 2 files:

<script src="https://rawgit.com/ruby-hyperloop/hyperloop-js/master/opal-compiler.min.js"></script>
 <script src="http://cdn.opalrb.org/opal/0.10.1/external/opal-browser-0.2.0.js"></script>

And my Opal component is :
```

<script type="text/ruby">
class ChatService
@socket = Browser::Socket.new("wss://echo.websocket.org")
end
</script>

But I always have the console error: uninitialized constant Browser::Socket

Could you help me guys ?

Elia Schito
@elia
Apr 08 2017 22:19
@fzingg try adding a require for it at the top of the script
Frederic ZINGG
@fzingg
Apr 08 2017 22:24
Adding require 'browser/socket' at the top of script do not work for me.
Elia Schito
@elia
Apr 08 2017 22:26
@fzingg try with require 'browser' too
@fzingg nay, browser/socket is just not included in that bundle
Frederic ZINGG
@fzingg
Apr 08 2017 22:31
Even with switching the bundle still no result, maybe I do something wrong:
<script type="text/ruby">

    require 'browser'
    require 'browser/socket'


      class ChatService

        def initialize(&block)
          @block = block
          @messages = []
          @user_id = nil
          @socket = Browser::Socket.new("wss://echo.websocket.org") do |socket|
            socket.on :message do |e|
              data = JSON.parse(`unescape(#{JSON.parse(e.data)[:text]})`)
              @messages << data
              @block.call [data] if id
            end
          end
        end
...
And
<script src="http://cdn.opalrb.org/opal/0.10.1/external/opal-browser-0.2.0.js"></script>
Elia Schito
@elia
Apr 08 2017 22:32
sorry, I just linked the file you were using :)
Frederic ZINGG
@fzingg
Apr 08 2017 22:35
ok, so when you find and have time could you tell me what is the correct bundle ?
Elia Schito
@elia
Apr 08 2017 22:35
if you want to build that file yourself: env RUBYOPT="-ropal-browser" opal -l -rbrowser/socket > browser-socket.js
Frederic ZINGG
@fzingg
Apr 08 2017 22:36
ok, no problem, I will do that. Thanks.
Elia Schito
@elia
Apr 08 2017 22:36
👍🏼
Frederic ZINGG
@fzingg
Apr 08 2017 23:04

in my rails ENV with the GEM opal-browser (0.2.0) I ran 2 commands:

env RUBYOPT="-ropal-browser" opal -l -rbrowser > opal-browser.js
env RUBYOPT="-ropal-browser" opal -l -rbrowser/socket > opal-browser-socket.js

Then include the 2 JS files and add the require 'browser' and require 'browser/socket but I got in the console:

Uncaught $ {name: "inherited", message: "undefined method `inherited' for Native", args: Array(1), stack: "↵    at a [as $new] (https://rawgit.com/ruby-hyper…rloop/hyperloopJS-chatapp/opal-browser.js:7418:8)"}

And:

undefined method `name_for' for Browser::Event

Do you have an idea what i did wrong?