-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add style, make a router for em-websocket, reorganize
- Loading branch information
Showing
14 changed files
with
218 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,7 +1,4 @@ | |||
|
# class ChatEngine | ||
class ChatEngine | # constructor: -> | ||
constructor: -> | # @sc = new SocketChat() | ||
@sc = new SocketChat() | # window.Chat = ChatEngine | ||
|
|||
|
|||
window.Chat = ChatEngine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
window.Derp = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,24 @@ | |||
class Derp.Room | |||
constructor: (@room, @user) -> | |||
@ws = new WebSocket "ws://#{ SOCKET_HOST }/#{@room}/#{@user}" | |||
|
|||
@ws.onmessage = (e) => | |||
data = JSON.parse(e.data) | |||
comments = $('#comments') | |||
|
|||
comments.append """ | |||
<div class='message'> | |||
<div class='username #{if (data['user'] == @user) then 'myself' else '' }'>#{data['user']}</div> | |||
<div class='comment'>#{data['comment']}</div> | |||
</div> | |||
""" | |||
|
|||
@ws.onclose = => @setStatus('disconnected') | |||
@ws.onopen = => @setStatus('connected') | |||
|
|||
sendMessage: -> | |||
@ws.send $('#comment').val() | |||
$('#comment').val '' | |||
|
|||
setStatus: (str) -> | |||
$('#msg').text str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
@import "twitter/bootstrap/variables.less"; | |||
@import "twitter/bootstrap/mixins.less"; | |||
|
|||
.title { | |||
h1 { | |||
font-size: 90px; margin-bottom: 32px; | |||
a { | |||
color: @black; } | |||
} | |||
text-align: center; | |||
margin-bottom: 8px; | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,19 @@ | |||
@import "twitter/bootstrap/variables.less"; | |||
@import "twitter/bootstrap/mixins.less"; | |||
|
|||
.message { | |||
.clearfix(); | |||
margin-bottom: 16px; | |||
margin-left: -20px; | |||
|
|||
.username { | |||
.makeColumn(2); | |||
color: @blue; | |||
&.myself { | |||
color: @green; | |||
} | |||
} | |||
.comment { | |||
.makeColumn(6); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,12 +1,15 @@ | |||
%h1 chat | .container | ||
= @message | .row | ||
%form{:name=>'room_join', :action=> rooms_path, :method=>'POST'} | .span4.offset4 | ||
%label | %h3 join or create | ||
RoomName | = @message | ||
%input{:name=>'room', :type=>'text', :value=>'test'} | %form.well{:name=>'room_join', :action=> rooms_path, :method=>'POST'} | ||
%label | %label{for: 'room'} Room name | ||
UserName | %input{:name=>'room', :type=>'text', :placeholder => 'Name a room'} | ||
%input{:name=>'user', :type=>'text', :value=> session[:user] || 'noname'} | %label{for: 'user'} Your name | ||
%input{name: 'user', type: 'text', placeholder: 'Name yourself'} | |||
|
|
||
%input{:type=>'submit'} | %br | ||
|
|||
%button.btn{:type=>'submit'} go | |||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,49 +1,17 @@ | |||
- content_for :head do | - content_for :head do | ||
%title= @room | %title= @room | ||
%script | %script | ||
var room_name = "#{ @room }"; | var room = new Derp.Room('#{@room}', '#{@user}'); | ||
var user_name = "#{ @user }"; | |||
|
|||
:javascript | |||
function message(str) { | |||
var msg = document.getElementById('msg'); | |||
msg.innerHTML += str; | |||
} | |||
|
|||
ws = new WebSocket('ws://' + SOCKET_HOST + '/?room='+room_name+'&user='+user_name); | |||
|
|||
ws.onmessage = function (e) { | |||
var data = JSON.parse(e.data); | |||
var comments = document.getElementById('comments'); | |||
comments.innerHTML = "<tr><td class='user_name'>" + | |||
data['user'] + "</td><td class='comment'>" + | |||
data['comment'] + "</td></tr>" + | |||
comments.innerHTML; | |||
} | |||
|
|||
ws.onclose = function () { | |||
message('disconnected'); | |||
} | |||
|
|||
ws.onopen= function () { | |||
message('connected'); | |||
} | |||
|
|||
var post_comment = function () { | |||
comment = document.getElementById('comment'); | |||
ws.send(comment.value); | |||
comment.value = ''; | |||
} | |||
|
|
||
.container | .container | ||
.row | .row | ||
.span12 | .span8.offset2 | ||
|
|||
%h2= @room | %h2= @room | ||
%div#form | %div#form | ||
%form#comment_form{:onsubmit => 'post_comment(); return false'} | %form.form-inline#comment_form{:onsubmit => 'room.sendMessage(); return false'} | ||
%input#comment{:type=>'text', :style => 'width:200px'} | %input.span4#comment{:type=>'text'} | ||
%input#submit.btn.info{:type=>'button', :value=>'send', :onclick=>'post_comment();'} | %input#submit.btn.info{:type=>'button', :value=>'send', :onclick=>'room.sendMessage();'} | ||
%span#msg | %span#msg | ||
%table#comments |
|
||
%table.table.table-condensed#comments | |||
|
|
Oops, something went wrong.