Skip to content

Commit 0d6fead

Browse files
Add files via upload
1 parent 8636986 commit 0d6fead

File tree

5 files changed

+847
-0
lines changed

5 files changed

+847
-0
lines changed

app.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "Socket-webpush-Example with nodejs and java service",
3+
"description": "update client with nodejs service when changes into java service",
4+
"website": "https://github.com/socketio/chat-example",
5+
"repository": "https://github.com/socketio/chat-example",
6+
"logo": "https://node-js-sample.herokuapp.com/node.svg",
7+
"success_url": "/",
8+
"keywords": [
9+
"node",
10+
"express",
11+
"socket.io",
12+
"realtime",
13+
"websocket"
14+
],
15+
"scripts": {
16+
},
17+
"addons": [
18+
],
19+
"env": {
20+
"BUILDPACK_URL": "https://github.com/heroku/heroku-buildpack-nodejs"
21+
}
22+
}

index.html

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Socket.IO chat</title>
5+
<style>
6+
* {
7+
margin: 0;
8+
padding: 0;
9+
box-sizing: border-box;
10+
}
11+
12+
body {
13+
font: 13px Helvetica, Arial;
14+
}
15+
16+
</style>
17+
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet">
18+
<link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet">
19+
</head>
20+
<body>
21+
<table id="webpush"
22+
class="display nowrap table table-hover table-striped table-bordered"
23+
cellspacing="0" width="100%">
24+
<thead>
25+
<tr>
26+
<td>Property</td>
27+
<td>Reservations</td>
28+
<td>Total</td>
29+
<td>Occupancy</td>
30+
</tr>
31+
</thead>
32+
<tbody>
33+
</tbody>
34+
</table>
35+
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>
36+
<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
37+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
38+
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
39+
<script>
40+
$(function () {
41+
var socket = io();
42+
socket.on('webpush', function (msg) {
43+
jQuery('#webpush').DataTable().destroy();
44+
$('#webpush').DataTable({
45+
'data': msg,
46+
'columns': [
47+
{"data": "property"},
48+
{"data": "reservations"},
49+
{"data": "total"},
50+
{"data": "occupancy"}
51+
]
52+
});
53+
});
54+
});
55+
</script>
56+
</body>
57+
</html>

index.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var app = require('express')();
2+
var http = require('http').Server(app);
3+
var io = require('socket.io')(http);
4+
var bodyParser = require('body-parser');
5+
var url = require('url');
6+
var querystring = require('querystring');
7+
var port = process.env.PORT || 9857;
8+
9+
app.use(bodyParser.urlencoded({extended: false}));
10+
app.use(bodyParser.json());
11+
12+
app.get('/',function (request,response) {
13+
response.sendFile(__dirname + '/index.html');
14+
});
15+
app.post('/', function (request, res) {
16+
try {
17+
var strBody = request.body;
18+
console.log(strBody);
19+
20+
io.emit('webpush', strBody);
21+
22+
} catch (ex) {
23+
console.dir(ex);
24+
}
25+
});
26+
27+
http.listen(port, function () {
28+
console.log('listening on *:' + port);
29+
});

0 commit comments

Comments
 (0)