diff --git a/client.html~ b/client.html~ deleted file mode 100755 index 71e2dd0..0000000 --- a/client.html~ +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - -
-
- -
-
- - diff --git a/index.html~ b/index.html~ deleted file mode 100644 index 6a8ed14..0000000 --- a/index.html~ +++ /dev/null @@ -1,37 +0,0 @@ - - - - intoro kuso chat - - - - - -

kuso chat

- - - - - - -
- -
- - diff --git a/index.js~ b/index.js~ deleted file mode 100644 index 3850bb2..0000000 --- a/index.js~ +++ /dev/null @@ -1,51 +0,0 @@ -var firewall = require('node-firewall'); - -var fw = new firewall.Firewall('fw.main', '^/'); - -// allow non authenticated users to access the login page -fw.add('^/login', null); - -// secure admin area -fw.add('^/admin', ['role', 'admin']); - -// all other urls require user role -fw.add('^/', ['role', 'user']); - -// add our new firewall to the map -firewall.map.add(fw); - -'use strict'; - -const app = require('express')(); -const http = require('http').Server(app); -const io = require('socket.io')(http); -const PORT = process.env.PORT || 4946; - - -// var socket = io.connect('http://0.0.0.0:4946'); -// socket.on('connect', function(msg) { -// // hogehoge -// }); - -app.get('/', function(req, res){ - res.sendFile(__dirname + '/index.html'); - // res.send('

Hello world

'); -}); - -io.emit('some event', {for: 'everyone'}); -io.on('connection', function(socket){ - socket.on('chat message', function(msg){ - io.emit('chat message', msg); - console.log('message: ' + msg); - // console.log('uwaaaaa'); - // console.log('a user connected'); - }); - socket.on('disconnection', function(){ - console.log('user disconnected'); - }); -}); - - -http.listen(PORT, function(){ - console.log('listening on :${PORT}'); -}); diff --git a/intro.js~ b/intro.js~ deleted file mode 100755 index 5cfb356..0000000 --- a/intro.js~ +++ /dev/null @@ -1,47 +0,0 @@ -function intro() { - var team = document.getElementById("tm"), - button = document.getElementById("push"), - warn = document.getElementById("warn"), - info = document.getElementById("info"); - var conn, PORT=4946, server = location.hostname; - function initConn() { - try { - conn = new WebSocket('ws://' + server + ':' + PORT + '/'); - conn.onopen = function() {}; // Nothing special - conn.onerror = function(err) { - info.textContent = 'WebSocket failure: ' + err - }; - warn.textContent = null; - conn.onmessage = function(ev) { - if (ev.data) { - var j = JSON.parse(ev.data); - info.textContent = j.info; - warn.textContent = j.warn; - if (j.rank == 1) - button.setAttribute("class", "win"); - else - button.setAttribute("class", null); - } - }; - conn.onclose = function(ev) { - info.textContent = "接続断: PUSHで参加"; - conn = null; - }; - info.textContent = "Ready..."; - } catch (err) { - alert("Socket Creation Error\n\ -Firefoxですか? URLウィンドウに about:config と入れて\n\ -Search: 窓に websocket と入れて、\n\ -network..websocket.allowInsecureFromHTTP\n\ -の行をダブルクリックして true に変えてください。\n" + err); - } - } - function push(ev) { - if (!conn) initConn(); - conn.send(team.value); - } - button.addEventListener("mousedown", push, false); - initConn(); -} -document.addEventListener("DOMContentLoaded", intro, false); - diff --git a/intro.rb~ b/intro.rb~ deleted file mode 100755 index d6766f4..0000000 --- a/intro.rb~ +++ /dev/null @@ -1,184 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: utf-8 -*- -require 'em-websocket' -require 'set' -require 'open3' -require 'json' -mydir=File.dirname($0) -require(File.expand_path(ENV['IQIF'] || 'mpg123.rb', mydir)) -PORT = 4946 - -class MP3Player - def initialize(file) - mklist(file) - @index = 0 - end - - - def mklist(file) - @music_list = [] - IO.foreach(file) do |line| - if /(.*\.(mp3|ogg))(\s+(.*))?/ =~ line.strip - f = $1 - test(?s, f) and @music_list << [f, $3 || File.basename(f)] - end - end - end - - - attr_accessor :music_list - def play(frame = @frame) - music = @music_list[@index][0] - prog = (/ogg$/ =~ music ? "ogg123" : "mpg123") - @frame = frame || "0" - cmd = [prog, "-v", "-k", @frame, music] - - @mp3thread = Thread.new { - Open3.popen3(*cmd) do |i, o, e, thr| - @pid = thr.pid - eline = "" - while chr = e.read(1) - eline << chr - next unless /[\r\n]/ =~ chr - - if /(Frame#|Time:)\s+([0-9:.]+)/ =~ eline - @frame = $2 - ## STDERR.printf("Frame = #%d\r", @frame) - eline = "" - end - - end - end - } - return @music_list[@index][1] - end - - - def stop(chime = nil) - if @pid - Process.kill(:INT, @pid) rescue nil - Thread.new { - @mp3thread.join - system("mpg123 -q btn.mp3 >/dev/null") if chime - } - @pid = nil - end - end - - def nextMusic(arg = 1) - stop - @index+=arg - if @index >= @music_list.length - return nil - end - @frame = "0" - return sprintf("%02d : %s", @index, @music_list[@index][1]) - end - - def prevMusic(arg = -1) - nextMusic(arg) - end - - def setMusic(n) - @index = [[0, n].max, @music_list.length-1].min - return nextMusic(0) - end -end - -mp3play = MP3Player.new(ARGV[0]) - - - - -clients = Set.new -ans = {} -cli2tm = {} -print("No clients yet...") -EM.run do - iqif = IQif.new(mp3play.music_list) - EM::WebSocket.start({:host => "0.0.0.0", :port => PORT}) do |ws_conn| - ws_conn.onopen do - clients << ws_conn - # p "hello"+ws_conn.inspect - iqif.printf("%d guest(s)\n", clients.length) - end - ws_conn.onmessage do |message| - warn = nil - - if message > "" - if ans[message] - ans[message] << ws_conn # Even if it is myself - else # First time - ans[message] = [] - ans[message] << ws_conn - cli2tm[ws_conn] = message # Remenber team name - mp3play.stop(true) - end - - announce = ans.keys.join(", ") - clients.each do |conn| - tm = cli2tm[conn] - - - warn = if tm && ans[tm] && ans[tm].length > 1 - # printf("tm=%d\n", tm) - warn ="もう押しています" - end - - rank = (ans.keys.index(tm) || -1) + 1 - answer = {"info" => announce, "warn" => warn, "rank" => rank} - conn.send(JSON.pretty_generate(answer)) - end - else - ws_conn.send(JSON.pretty_generate({"warn"=>"Team名を入れてね!"})) - end - end - - ws_conn.onclose do - clients.delete(ws_conn) - # p "bye"+ws_conn.inspect - iqif.printf("%d GUEST(s)\n", clients.length) - end - - def broadcast(clients, mesg) - clients.each {|c| - c.send(JSON.generate({"info" => mesg})) - } - end - - - cast_nonpush_clients = lambda {|mesg| # Send to non-pushing clients - s = JSON.generate({"info" => mesg}) - clients.each {|c| - team = cli2tm[c] - c.send(s) if !ans.has_key?(team) - } - } - - EM::defer do - puts "..captured!" - while line = iqif.action - case line.chomp - when /p/ - cast_nonpush_clients.call("GO!") - # STDERR.printf("START: %s", mp3play.play) - iqif.printf("START: %s", mp3play.play) - when /s/ - mp3play.stop - when /[nr0-9]/ - iqif.puts("Reset clients") - s = JSON.pretty_generate({"info" => "Ready..."}) - broadcast(clients, "Ready...") - ans = {}; cli2tm = {}; - if /n/ =~ line - iqif.printf("次: %s\n", mp3play.nextMusic) - elsif /^\d+/ =~ line - iqif.printf("%d: %s\n", line.to_i, mp3play.setMusic(line.to_i)) - end - end - end - exit - end - end -end - diff --git a/sarver.rb~ b/sarver.rb~ deleted file mode 100644 index 1f72d48..0000000 --- a/sarver.rb~ +++ /dev/null @@ -1,10 +0,0 @@ -require 'em-websocket' -EM.run { - @channel = EM::Channel.new - EM::WebSocket.start(:host => "localhost", :port => 4946) do |ws| - sid = nil - ws.onopen { sid = @channel.subscribe { |msg| ws.send msg } } - ws.onmessage { |msg| @channel.push "#{sid}: #{msg}" } - ws.onclose { @channel.unsubscribe(sid) } - end -} diff --git a/sarver2.rb~ b/sarver2.rb~ deleted file mode 100644 index bf700b7..0000000 --- a/sarver2.rb~ +++ /dev/null @@ -1,15 +0,0 @@ -require 'em-websocket' -require 'pp' - -connnections = [] - -EM::WebSocket.start({:host => "0.0.0.0", :port => 8888}) do |ws_conn| - ws_conn.onopen do - connnections << ws_conn - end - - ws_conn.onmessage do |message| - pp message - connnections.each{|conn| conn.send(message) } - end -end