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
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.
Most helpful comment
If you are using es6 javascript, (which we support by default if using brunch), you can import the
Socketobject, i.e.:If you aren't using es6, or don't want to use imports, you can also do:
That should clear things up. If you still have issues, find me on #elixir-lang irc.