Phoenix: new Socket() or new Phoenix.Socket()?

Created on 21 May 2015  路  1Comment  路  Source: phoenixframework/phoenix

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

Most helpful comment

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.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings