1 pièce(s) jointe(s)
Application chat sur raspberry pi 3
Bonjour,
j'ai suivi les instructions pour créer un application chat sur mon raspberry pi 3 modèle b sous rasbian. Cependant, je rencontre un problème et mon niveau de connaissance en node est limité à ce que j'ai lu pour créer l'application. Si quelqu'un est capable de m'aider cela serait bien apprécier pour un débutant comme moi qui veux apprendre.
Le problème est le suivant:
Citation:
/home/pi/chat-example/node_modules/socket.io/node_modules/engine.io/node_modules/uws.js:3
const http = require('http'):
^^^^^
syntaxError: use of const in strict mode.
Pièce jointe 354396
code index.js
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var port = process.env.PORT || 3000;
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket){
socket.on('chat message', function(msg){
io.emit('chat message', msg);
});
});
http.listen(port, function(){
console.log('listening on *:' + port);
}); |
code package.json
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| {
"name":"socket-chat-example",
"version":"0.0.1",
"description":"my first socket.io app",
"dependence":{
"express":"^4.15.2",
"socket.io"
},
"scripts":{
"start": "node index.js"
}
} |
code index.html
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| <!doctype html>
<html>
<head>
<title>Socket.IO chat</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { front: 13px Helvetica, Arial; }
from { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
from input { border: 0; padding: 10px; width:90%; margin-right:.5%; }
from button { width: 9%; background: rgb(130,224,255); border: none; padding: 10px; }
#messages { list-style-type: none; margin:0; padding:0; }
#messages li { padding:5px 10px; }
#messages li:nth-child(odd) { background: #eee; }
#message { margin-bottom: 40px }
</style>
</head>
<body>
<ul id="message"></ul>
<form action="">
<input id="m" autocomplete="off"/><button>Send</button>
</form>
<script src="/socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script>
$(function(){
var socket = io();
$('from').submit(function(){
socket.emit('chat message',$('#m').val());
$('#m').val('');
return false;
});
socket.on('chat message', function(msg){
$('#message').append($('<li>').text(msg));
window.scrollTo(0,document.body.scrollHeight);
});
});
</script>
</body>
</html> |
code app.json
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
{
"name": "Socket-Chat-Example",
"description": "my first socket.io app",
"website": "https://github.com/socketio/chat-example",
"repository": "https://github.com/socketio/chat-example",
"logo": "https://node-js-sample.herokuapp.com/node.svg",
"success_url": "/",
"keywords": [
"node",
"express",
"socket.io",
"realtime",
"websocket"
],
"scripts": {
},
"addons": [
],
"env": {
"BUILDPACK_URL": "https://github.com/heroku/heroku-buildpack-nodejs"
}
} |