-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscratch2-ex.js
More file actions
32 lines (25 loc) · 791 Bytes
/
scratch2-ex.js
File metadata and controls
32 lines (25 loc) · 791 Bytes
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
"use strict";
var express = require('express');
var app = express();
var server = app.listen(12345, function(){
console.log("Server start... listening port " + server.address().port);
});
var volume = 0;
app.get('/poll', (req, res) => {
res.send("volume " + volume);
});
app.get('/playBeep', (req, res) => {
console.log("play beep!");
process.stderr.write("\x07"); // to prevent new line (instead of console.log)
res.send("OK");
});
app.get('/setVolume/:volume', (req, res) => {
var tmp_volume = req.params.volume;
if(tmp_volume >= 0 && tmp_volume <= 10){
volume = tmp_volume;
console.log("set volume= " + volume);
}else{
console.log("out of range: " + tmp_volume);
}
res.send("OK");
});