planning-poker/assets/js/app.js

52 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-05-02 21:55:20 +00:00
// We need to import the CSS so that webpack will load it.
// The MiniCssExtractPlugin is used to separate it out into
// its own CSS file.
import "../css/app.scss"
// webpack automatically bundles all modules in your
// entry points. Those entry points can be configured
// in "webpack.config.js".
//
// Import deps with the dep name or local files with a relative path, for example:
//
// import {Socket} from "phoenix"
// import socket from "./socket"
//
import "phoenix_html"
2020-05-06 05:30:43 +00:00
import { Socket, Presence } from "phoenix"
import { Elm } from "../src/Main.elm"
import uuid4 from "uuid4"
var player_id = uuid4()
var socket = new Socket("/socket", {params: {player_id: player_id}})
socket.connect()
2020-05-02 21:55:20 +00:00
var app = Elm.Main.init({
2020-05-06 05:30:43 +00:00
node: document.getElementById("elm-main"),
flags: "player:" + player_id
})
app.ports.joinRoom.subscribe(options => {
let channel = socket.channel(
"room:" + options.room,
{playerName: options.playerName}
)
let presences = {}
channel.join()
.receive("ok", resp => {
console.log("Joined successfully", resp);
app.ports.joinedRoom.send(options.room);
})
.receive("error", resp => { console.log("Unable to join", resp) })
channel.on("presence_state", state => {
presences = Presence.syncState(presences, state)
app.ports.gotPresence.send(presences)
})
channel.on("presence_diff", diff => {
presences = Presence.syncDiff(presences, diff)
app.ports.gotPresence.send(presences)
})
})