Amber: web sockets don't work

Created on 27 Nov 2017  ยท  15Comments  ยท  Source: amberframework/amber

I've tried using web sockets by following the example of the documentation and I get nothing back returned. I've tried using vanilla javascript to connect to the server too but only get "WebSocket is already in CLOSING or CLOSED state." on the console log.

Most helpful comment

I think we need to do some changes on documentation, we have done so many changes to amber core on last month.

Let me try to reproduce this issue ๐Ÿ‘

All 15 comments

I think we need to do some changes on documentation, we have done so many changes to amber core on last month.

Let me try to reproduce this issue ๐Ÿ‘

Any updates on this?

Yeah, I'm trying an new amber app using websockets to be able to reproduce it ๐Ÿ˜…

Currently I'm using

โžœ  ~ amber --version
Amber CLI (amberframework.org) - v0.3.6
โžœ  ~ shards --version
Shards 0.7.2 (2017-11-23)
โžœ  ~ crystal --version
Crystal 0.23.1 (2017-09-10) LLVM 5.0.0

@codingphasedotcom What versions are you using?

BTW, @elorest local shards cache is working excellent! ๐ŸŽ‰

amber --version
Amber CLI (amberframework.org) - v0.3.6
โžœ ~ shards --version
Shards 0.7.1 (2017-10-12)
โžœ ~ crystal --version
Crystal 0.23.1 (2017-10-12) LLVM 4.0.1

can someone upload a working version to github?
as an example app using websockets. It seems we have the same versions don't know why mines just don't work. I tried using kemal and my javascript works so I know its not the frontend. Would really appreciate it

@fridgerator - Could you weigh in on this?

@codingphasedotcom does your socket on_connect return true ?

I'm working in something, give me a minute ๐Ÿš€

Using amber-cli 0.3.6 these steps work for me:

  1. amber new MyApp && cd MyApp && shards install
  2. amber g socket User
  3. amber g channel Chat
  4. added channel "chat:*", ChatChannel to the socket
  5. added a route: websocket "/chat", UserSocket
  6. connect in a browser ws = new WebSocket('ws://localhost:3000/chat')
  7. ws.readyState is 1

Yeah, I'm working in a live example, and your steps work fine.

however I think we need to update guides, I have found some mistakes.

Hi community, say hi to Ambrockets ๐ŸŽ‰

screenshot_20171130_055732

https://ambrockets.herokuapp.com/

Feel free to do PR, I tried to do a minimal WebSocket app, no database nor user management.

@faustinoaq - Thank you for creating the demo app. We still need to update the guides and/or documentation?

@codingphasedotcom - Is this enough for you to get a working app or is anything still holding you up?

Hi,
after downloading @faustinoaq project and running it in my computer his project worked. I'm still lost on whats different from his to mines. @marksiemers I definitely would say you guys need an updated version and more detailed example in the documentation. I've done this in Nodejs, laravel, rails 5, just by following the instructions and everything works. I'm going to upload my project and see if maybe one of you guys can take a look on why I keep getting "amber.js:76 WebSocket is already in CLOSING or CLOSED state."

@fridgerator I started a new project followed everything you wrote and I'm still getting "0" when i console.log(ws.readyState)

Ok I figured it out.
when you create a user socket it tells you on_connect you must return "true"

but when following the documentation I just copied what was there on the documentation and it was return false so it was closing the socket.

all I did was change it back to how it was and it works now
ruby def on_connect # self.session and self.cookies available here # do authentication here # !self.session[:user_id].nil? # !user.blank? true end

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ZeroPointEnergy picture ZeroPointEnergy  ยท  4Comments

blankoworld picture blankoworld  ยท  7Comments

faustinoaq picture faustinoaq  ยท  6Comments

conradwt picture conradwt  ยท  3Comments

netwarp picture netwarp  ยท  6Comments