Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new Socket() or new Phoenix.Socket()? #906

Closed
stanonyime opened this issue May 21, 2015 · 1 comment
Closed

new Socket() or new Phoenix.Socket()? #906

stanonyime opened this issue May 21, 2015 · 1 comment

Comments

@stanonyime
Copy link

I've been trying to set up a realtime tracker with phoenix but I keep getting this error:
Uncaught ReferenceError: Socket is not defined
The phoenix.js is loaded.
I keep seeing variations of "socket = new Socket("...")" and "socket = new Socket("..")" on online examples.
I'm using React js, Elixir 1.0.2, phoenix v0.13.1 on Windows 8

Also my js files are not served after change and reload unless I rename the file

@chrismccord
Copy link
Member

If you are using es6 javascript, (which we support by default if using brunch), you can import the Socket object, i.e.:

import {Socket} from "phoenix"
let socket = new Socket("/ws")

If you aren't using es6, or don't want to use imports, you can also do:

var socket = new Phoenix.Socket("/ws")

That should clear things up. If you still have issues, find me on #elixir-lang irc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants