Skip to content

digimondo/phoenix-websocket-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

phoenix-websocket-js

Helpful libraries to connect to a Phoenix-based Websocket (with Channels).

phoenix-common.js

This file is a ES5-compatible version of the JavaScript supplied with the Phoenix Framework. You can compile that for yourself from the original source at phoenixframework/phoenix when needed.

Here is how to use it:

var phoenix = require("./phoenix-common.js")
var socket = new phoenix.Socket("wss://url.to.your.websocket.api", {
  transport: require("websocket").w3cwebsocket,
  params: {auth: "your-means-of-authentication"
}})

socket.connect()
socket.onError(function(err) {console.log("error:", err)})

var channel = socket.channel("your-topic", {
  some_param: true
})

channel.join()
	.receive("ok", function() {console.log("joined")})
	.receive("error", function(reason) {console.log("error:", reason)})

channel.on("message", function(message) {console.log("message", message)})

About

Helpful libraries to connect to a Phoenix-based Websocket (with Channels).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published