Skip to content

Commit a993beb

Browse files
committed
Upload chat-jqm-heroku-sample
0 parents  commit a993beb

File tree

677 files changed

+75441
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

677 files changed

+75441
-0
lines changed

Diff for: .DS_Store

6 KB
Binary file not shown.

Diff for: chat-jqm-heroku-node/.DS_Store

6 KB
Binary file not shown.

Diff for: chat-jqm-heroku-node/hello.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var express = require('express');
2+
3+
var app = express.createServer(express.logger()), io = require('socket.io').listen(app);
4+
5+
io.configure(function () {
6+
io.set("transports", ["xhr-polling"]);
7+
io.set("polling duration", 10);
8+
});
9+
10+
app.get('/', function(request, response) {
11+
response.sendfile(__dirname + '/index.html');
12+
});
13+
14+
var port = process.env.PORT || 3000;
15+
console.log("Listening on " + port);
16+
17+
app.listen(port);
18+
19+
io.sockets.on('connection', function (socket) {
20+
socket.broadcast.emit('news from the server');
21+
22+
socket.on('message', function (data) {
23+
console.log('message on server');
24+
//socket.broadcast.emit(data);
25+
socket.broadcast.send(data);
26+
});
27+
});

Diff for: chat-jqm-heroku-node/index.html

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5+
6+
<title>chat</title>
7+
<link type="text/css" rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.min.css"/>
8+
<script src="http://code.jquery.com/jquery-1.7.1.min.js"/></script>
9+
<script src="http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.min.js"></script>
10+
<script src="/socket.io/socket.io.js"></script>
11+
12+
<script type="text/javascript">
13+
14+
function getCurrentDate(){
15+
var currentTime = new Date();
16+
var hours = currentTime.getHours();
17+
var mins = currentTime.getMinutes();
18+
var secs = currentTime.getSeconds();
19+
return(hours + ':'+ mins + ':' + secs);
20+
}
21+
22+
function getDisplayMessage(){
23+
var message = $('#messageText').val();
24+
var userName = $('#usernameText').val();
25+
return('<em>'+userName + ' (' + getCurrentDate() +')</em>: ' + message);
26+
}
27+
28+
$(document).ready(function() {
29+
30+
var socket = io.connect('http://warm-samurai-5416.herokuapp.com/');
31+
32+
socket.on('connect', function() {
33+
$('#messages').append('<li>Connected to the server.</li>');
34+
35+
});
36+
37+
socket.on('message', function(message) {
38+
39+
$('#messages').append('<li>' + message + '</li>');
40+
$('#messages').listview("refresh");
41+
});
42+
43+
socket.on('disconnect', function() {
44+
$('#messages').append('<li>Disconnected from the server.</li>');
45+
46+
});
47+
48+
$('#sendButton').bind('click', function() {
49+
50+
socket.send(getDisplayMessage());
51+
$('#messages').append('<li class="mySelf">' + getDisplayMessage() + '</li>');
52+
$('#messages').listview("refresh");
53+
$('#messageText').val('');
54+
});
55+
});
56+
</script>
57+
58+
<style>
59+
.mySelf{
60+
color:#09C;
61+
}
62+
63+
.listDiv{
64+
margin-top:40px;
65+
margin-left:10px;
66+
margin-right:10px;
67+
}
68+
</style>
69+
</head>
70+
71+
<body>
72+
73+
<div data-role="page" id="loginPage">
74+
75+
<div data-role="header" data-position="fixed">
76+
<h1>Welcome</h1>
77+
</div><!-- /header -->
78+
79+
<div data-role="content">
80+
<div id="formLogin">
81+
<p>
82+
<label for="usertext">Please enter your username:</label>
83+
<input type="text" id="usernameText"/>
84+
</p>
85+
86+
<p>
87+
<a href="#chatPage" data-role="button">Submit</a>
88+
</p>
89+
</div>
90+
91+
</div>
92+
93+
</div>
94+
<div data-role="page" id="chatPage">
95+
96+
<div data-role="header" data-position="fixed">
97+
<h1>Let's chat</h1>
98+
</div>
99+
100+
<div data-role="content">
101+
102+
<div>
103+
<label for="messageText">Your message</label>
104+
<input type="text" id="messageText"/>
105+
<button id="sendButton" >Send</button>
106+
</div>
107+
<div class="listDiv">
108+
<ul id="messages" data-role="listview">
109+
110+
</ul>
111+
</div>
112+
113+
</div>
114+
115+
</div>
116+
117+
</body>
118+
</html>

Diff for: chat-jqm-heroku-node/node_modules/.DS_Store

6 KB
Binary file not shown.

Diff for: chat-jqm-heroku-node/node_modules/.bin/express

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: chat-jqm-heroku-node/node_modules/express/.npmignore

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)