Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ version: 1.0
shards:
kemal:
github: sdogruyol/kemal
version: 0.8.0
version: 0.12.0

kilt:
github: jeromegn/kilt
version: 0.3.3

radix:
github: luislavena/radix
version: 0.1.0
version: 0.3.0

1 change: 1 addition & 0 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version: 0.1.0
dependencies:
kemal:
github: sdogruyol/kemal
version: 0.12.0

authors:
- Fatih Kadir Akın <[email protected]>
Expand Down
13 changes: 12 additions & 1 deletion src/app.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@ end

ws "/" do |socket|
sockets.push socket

socket.on_message do |message|
messages.push message
sockets.each do |a_socket|
a_socket.send messages.to_json
begin
a_socket.send messages.to_json
rescue ex
sockets.delete a_socket
end
end
end

socket.on_close do |socket|
sockets.delete socket
end
end

Kemal.run
16 changes: 15 additions & 1 deletion src/assets/javascripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ function random(min, max) {
return Math.floor(Math.random()*(max-min+1)+min);
}

function setCurrentTime() {
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()

if (minutes < 10) {
minutes = "0" + minutes
}

var timePeriod = hours > 11 ? "PM" : "AM"

return hours+":"+minutes + " " + timePeriod
}

var Chat = React.createClass({

getInitialState: function () {
Expand Down Expand Up @@ -64,7 +78,7 @@ var Chat = React.createClass({
var color = user[1];
var name = user[0];
return React.createElement("li", null,
React.createElement('span', {style: {color: color}}, name+": "),
React.createElement('span', {style: {color: color}}, name+"["+setCurrentTime()+"]: "),
React.createElement('span', null, parts.slice(1).join(":").trim())
);
});
Expand Down