Skip to content

Commit

Permalink
Add dialog-polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
ezemtsov committed Jun 26, 2019
1 parent 00d0b91 commit b251d35
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 104 deletions.
3 changes: 1 addition & 2 deletions playWithMe.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build-type: Simple
cabal-version: >=1.10
extra-source-files: README.md

executable server
executable playWithMe-server
hs-source-dirs: src
main-is: Main.hs
other-modules: Game
Expand All @@ -31,5 +31,4 @@ executable server
, wai-middleware-static
, containers
, unordered-containers
, hashable
, random
5 changes: 2 additions & 3 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
module Main where

import Control.Concurrent
import Data.Hashable
import Web.Scotty
import Network.Wai.Middleware.Static
import qualified Network.WebSockets as WS
Expand All @@ -14,8 +13,8 @@ import Router
main :: IO ()
main = do
state <- newMVar Router.newRouterState
forkIO (WS.runServer "127.0.0.1" 9160 $ startRouter state)
scotty 8080 $ webApp
forkIO (WS.runServer "0.0.0.0" 8080 $ startRouter state)
scotty 80 $ webApp

webApp = do
middleware $ staticPolicy (noDots >-> addBase "web")
Expand Down
1 change: 0 additions & 1 deletion src/Router.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Control.Exception (finally)
import qualified Network.WebSockets as WS
import Data.ByteString.Lazy (ByteString)
import Data.Aeson (FromJSON, ToJSON, encode, decode)
import Data.Hashable
import GHC.Generics
import System.Random

Expand Down
70 changes: 3 additions & 67 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1,70 +1,6 @@
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# https://docs.haskellstack.org/en/stable/yaml_configuration/

# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
# resolver: ghcjs-0.1.0_ghc-7.10.2
#
# The location of a snapshot can be provided as a file or url. Stack assumes
# a snapshot provided as a file might change, whereas a url resource does not.
#
# resolver: ./custom-snapshot.yaml
# resolver: https://example.com/snapshots/2018-01-01.yaml
resolver: lts-13.19

# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# - location:
# git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# subdirs:
# - auto-update
# - wai
packages:
- .
# Dependency packages to be pulled from upstream that are not in the resolver
# using the same syntax as the packages field.
# (e.g., acme-missiles-0.3)
# extra-deps: []

# Override default flag values for local packages and extra-deps
# flags: {}

# Extra package databases containing global packages
# extra-package-dbs: []

# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=1.7"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor

# Uncomment that to make it work on NixOS
# nix:
# enable: true
# packages: [zlib]
nix:
enable: true
packages: [zlib]
4 changes: 2 additions & 2 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

<!-- Dialog confirmation to create a new session -->
<dialog class="mdl-dialog my-mdl-dialog">
<h4 class="mdl-dialog__title">Enter your name to join the game</h4>
<h4 class="mdl-dialog__title">Enter your name, sir!</h4>
<div class="mdl-dialog__content">
<p>To join an existing session use the session URL</p>
<p>Use session URL to join the existing game</p>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input playerName" type="text">
<label class="mdl-textfield__label" for="playerName">Your name...</label>
Expand Down
4 changes: 3 additions & 1 deletion web/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dialogPolyfill from './node_modules/dialog-polyfill';
//--------------------------------------------------
// Game model
class Game {
Expand Down Expand Up @@ -35,7 +36,7 @@ class Game {
}
connect(name) {
let myGame = this;
let socket = new WebSocket('ws://127.0.0.1:9160');
let socket = new WebSocket('ws://34.68.64.169:8080');

socket.onopen = function(event) {
console.log('Connected to: ' + event.currentTarget.url);
Expand Down Expand Up @@ -202,6 +203,7 @@ function initInterface(game) {
cleanupButton.onclick = () => sendMessage(game.socket, game.session, msgCleanHistory());

let dialog = document.querySelector('dialog');
dialogPolyfill.registerDialog(dialog);
let nameInput = dialog.querySelector('.playerName');
let newGameButton = dialog.querySelector('.newGame');

Expand Down
5 changes: 5 additions & 0 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 0 additions & 28 deletions web/package.json

This file was deleted.

0 comments on commit b251d35

Please sign in to comment.