node-red-contrib-sonospollytts
Advanced tools
Comparing version 1.0.21 to 1.1.0
@@ -5,3 +5,11 @@ # Node-Red | ||
<a href="http://eepurl.com/gJm095" target="_blank">Subscribe to my channel.</a> Only news about my nodes, no spam, no ads. I'm a github developer, not a merchant. | ||
<p> | ||
<b>Version 1.1.0</b><br/> | ||
- Now support HTTPS installations.<br/> | ||
- MAJOR CHANGE IN HANDLING COMMUNICATIONS BETWEEN NODE-RED AND SONOS. Due to added support for HTTPS installation, the node behaviour has been changed. The node will now create his own webserver, instead of using node-red webserver. This permits to overcome SSL certificate problems with Sonos. If your node-red run behind a firewall, REMEMBER TO FORMWARD the node webserver port (default port is 1980)<br/> | ||
</p> | ||
<p> | ||
<b>Version 1.0.21</b><br/> | ||
@@ -8,0 +16,0 @@ - Added handling of non standard nodered installations, having httpAdminRoot, httpNodeRoot or httpRoot altered by user. Thanks @ukmoose.<br/> |
{ | ||
"name": "node-red-contrib-sonospollytts", | ||
"version": "1.0.21", | ||
"version": "1.1.0", | ||
"description": "Node-Red TTS with Sonos and Amazon Polly", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,3 +10,3 @@ # Node-Red SonosPollyTTS | ||
<img src='https://github.com/Supergiovane/node-red-contrib-sonospollytts/raw/master/README.png' width="100%"> | ||
<img src='https://github.com/Supergiovane/node-red-contrib-sonospollytts/raw/master/README.png' width="50%"> | ||
@@ -17,2 +17,7 @@ ## DESCRIPTION | ||
<a href="http://eepurl.com/gJm095" target="_blank">Subscribe to my channel.</a> Only news about my nodes, no spam, no ads. I'm a github developer, not a merchant. | ||
## ---> IMPORTANT - READ THIS <--- | ||
MAJOR CHANGE STARTING FROM ***V1.1.0***, IN HANDLING COMMUNICATIONS BETWEEN NODE-RED AND SONOS. Due to added support for HTTPS installation, the node behaviour has been changed. The node will now create his own webserver, instead of using node-red webserver. This permits to overcome SSL certificate problems with Sonos. If your node-red run behind a firewall, REMEMBER TO FORMWARD the node webserver port (default port is 1980). **If your node-red is running behind a firewall and you ran an older version, remember to add a rule in your firewall, to forward the new port. The old configured port 1880 is not valid anymore and the node will default to 1980 instead.** | ||
## CHANGELOG | ||
@@ -22,2 +27,3 @@ * See <a href="https://github.com/Supergiovane/node-red-contrib-sonospollytts/blob/master/CHANGELOG.md">here the changelog</a> | ||
## FEATURES | ||
* Works with node-red in HTTP and in HTTPS mode. | ||
* TTS queues handling. If you send multiple payloads to the node, it'll handle it in his own queue. | ||
@@ -24,0 +30,0 @@ * TTS caching. Amazon AWS charges you if you use Polly for a very high rate of text to speech request. The node caches the TTS, so if you requests the same TTS the second time, the node will take it from the cache instead of asking to the Amazon Polly service. |
@@ -480,4 +480,2 @@ module.exports = function(RED) { | ||
RED.log.info('SonosPollyTTS: ConfigNode:' + config); | ||
if (this.credentials) { | ||
@@ -528,3 +526,4 @@ this.accessKey = this.credentials.accessKey; | ||
node.bNoHailing=false; // Dont't play Hailing music temporarely (from msg node ommand "nohailing="true") | ||
node.msg={}; // 08/05/2019 Node message | ||
node.msg = {}; // 08/05/2019 Node message | ||
node.oWebserver; // 11/11/2019 Stores the Webserver | ||
@@ -561,11 +560,18 @@ // 03/06/2019 you can select the temp dir | ||
// 27/10/2019 Changes made according to new httpRoot habdling, beginning from nodered 0.6.0 https://nodered.org/blog/2014/02/21/version-0-6-0-released | ||
if (RED.settings.httpAdminRoot !== "/") { | ||
// Set the httpAdminRoot as the tts endpoint root | ||
node.sNoderedURL="http://"+ config.noderedipaddress.trim() + ":" + config.noderedport.trim()+ RED.settings.httpAdminRoot; // RED.settings.uiPort | ||
}else | ||
{ | ||
// Add the httpRoot (ignore httpNodeRoot. See above link | ||
node.sNoderedURL="http://"+ config.noderedipaddress.trim() + ":" + config.noderedport.trim() + RED.settings.httpRoot; | ||
// if (RED.settings.httpAdminRoot !== "/") { | ||
// // Set the httpAdminRoot as the tts endpoint root | ||
// node.sNoderedURL="http://"+ config.noderedipaddress.trim() + ":" + config.noderedport.trim()+ RED.settings.httpAdminRoot; // RED.settings.uiPort | ||
// }else | ||
// { | ||
// // Add the httpRoot (ignore httpNodeRoot. See above link | ||
// node.sNoderedURL="http://"+ config.noderedipaddress.trim() + ":" + config.noderedport.trim() + RED.settings.httpRoot; | ||
// } | ||
// 11/11/2019 NEW in V 1.1.0, changed webserver behaviour. Redirect pre V. 1.1.0 1880 ports to the nde default 1980 | ||
if (config.noderedport.trim() == "1880") { | ||
RED.log.warn("SonosPollyTTS: The webserver port ist 1880. Please change it to another port, not to conflict with default node-red 1880 port. I've changed this temporarly for you to 1980"); | ||
config.noderedport = "1980"; | ||
} | ||
RED.log.info('SonosPollyTTS: Node-Red Endpoint will be created here: ' + node.sNoderedURL + "tts"); | ||
node.sNoderedURL = "http://" + config.noderedipaddress.trim() + ":" + config.noderedport.trim(); // 11/11/2019 New Endpoint to overcome https problem. | ||
RED.log.info('SonosPollyTTS: Node-Red node.js Endpoint will be created here: ' + node.sNoderedURL + "/tts"); | ||
@@ -588,16 +594,3 @@ // Create sonos client | ||
// Hook the Playstate event | ||
/* node.SonosClient.on('PlayState', state => { | ||
node.sSonosPlayState=state; | ||
RED.log.info('SonosPollyTTS: node.SonosClient.on Paystate: ' + node.sSonosPlayState); | ||
}); */ | ||
// Hook the current track | ||
/* node.SonosClient.on('CurrentTrack', track => { | ||
node.sSonosTrackTitle=track.uri;//track.title; | ||
//RED.log.info('SonosPollyTTS: node.SonosClient.on CurrentTrack: ' + JSON.stringify(track)); | ||
//RED.log.info('SonosPollyTTS: node.SonosClient.on CurrentTrack: ' + node.sSonosTrackTitle); | ||
}); | ||
*/ | ||
// Downloads hailing.mp3 | ||
@@ -640,21 +633,9 @@ // Check if the file already exist | ||
/* // This line opens the file as a readable stream | ||
var readStream = fs.createReadStream(__dirname +"/"+node.sHailingFile); | ||
// This will wait until we know the readable stream is actually valid before piping | ||
readStream.on('open', function () { | ||
// This just pipes the read stream to the response object (which goes to the client) | ||
readStream.pipe(fs.createWriteStream(path.join(config.dir, node.sHailingFile))); | ||
}); | ||
// This catches any errors that happen while creating the readable stream (usually invalid names) | ||
readStream.on('error', function(err) { | ||
RED.log.info('SonosPollyTTS: Error moving hailing.mp3 to temp dir : ' + err); | ||
}); */ | ||
} | ||
}; | ||
} | ||
node.status({ | ||
fill: 'green', | ||
shape: 'ring', | ||
text: 'Ready'}); | ||
@@ -666,3 +647,12 @@ this.on('input', function(msg) { | ||
} | ||
try { | ||
node.status({ | ||
fill: 'yellow', | ||
shape: 'dot', | ||
text: 'Processing ' + msg.payload }); | ||
} catch (error) { | ||
} | ||
// 17/04/2019 Verifico se possso mandare in play l'hailing | ||
@@ -711,3 +701,67 @@ if (msg.hasOwnProperty("nohailing")) { | ||
clearTimeout(node.oTimer); | ||
// 11/11/2019 Close the Webserver | ||
try { | ||
node.oWebserver.close(function () { RED.log.info("SonosPollyTTS: Webserver UP. Closing down."); }); | ||
} catch (error) { | ||
} | ||
}); | ||
// 11/11/2019 CREATE THE ENDPOINT | ||
const http = require('http') | ||
const sWebport = config.noderedport.trim(); | ||
const requestHandler = (req, res) => { | ||
try { | ||
var url = require('url'); | ||
var url_parts = url.parse(req.url, true); | ||
var query = url_parts.query; | ||
res.setHeader('Content-Disposition', 'attachment; filename=tts.mp3') | ||
if (fs.existsSync(query.f)) { | ||
var readStream = fs.createReadStream(query.f); | ||
readStream.on("error", function(err) { | ||
fine(err); | ||
}); | ||
readStream.pipe(res); | ||
res.end; | ||
}else | ||
{ | ||
RED.log.error("Playsonos RED.httpAdmin file not found: " + query.f); | ||
res.write("File not found"); | ||
res.end(); | ||
} | ||
} catch (error) { | ||
RED.log.error("Playsonos RED.httpAdmin error: " + error + " on: " + query.f); | ||
} | ||
function fine(err){ | ||
RED.log.error("Playsonos error opening stream : " + query.f + ' : ' + error); | ||
res.end; | ||
} | ||
} | ||
try { | ||
node.oWebserver = http.createServer(requestHandler); | ||
} catch (error) { | ||
// Already open. Close it and redo. | ||
RED.log.error("SonosPollyTTS: Webserver creation error: " + error); | ||
} | ||
try { | ||
node.oWebserver.listen(sWebport, (err) => { | ||
if (err) { | ||
RED.log.error("SonosPollyTTS: error starting webserver on port " + sWebport, err); | ||
} | ||
}) | ||
} catch (error) { | ||
// In case oWebserver is null | ||
RED.log.error("SonosPollyTTS: error starting webserver on port " + sWebport, error); | ||
} | ||
} | ||
@@ -766,3 +820,3 @@ RED.nodes.registerType('sonospollytts', PollyNode); | ||
}).catch(err=>{ | ||
node.status({fill:"red", shape:"dot", text:"err currtrack"}); | ||
node.status({fill:"red", shape:"dot", text:"err currtrack: " + err}); | ||
node.sSonosTrackTitle="stopped"; // force stopped | ||
@@ -774,3 +828,3 @@ HandleQueue2(node); | ||
}).catch(err=>{ | ||
node.status({fill:"red", shape:"dot", text:"err currstate"}); | ||
node.status({fill:"red", shape:"dot", text:"err currstate: " + err}); | ||
node.sSonosTrackTitle="stopped"; // force stopped | ||
@@ -1040,3 +1094,3 @@ //HandleQueue2(node); | ||
// Play directly files starting with http:// | ||
if (_songuri.toLowerCase().startsWith("http://")) { | ||
if (_songuri.toLowerCase().startsWith("http://") ) { | ||
sUrl=_songuri; | ||
@@ -1078,39 +1132,43 @@ }else{ | ||
// 25/03/2019 Create the endpoint to listen to the tts. tts.mp3 is a dummy endpoint. Please see query.f | ||
// query.f contains the filename to be played. | ||
RED.httpAdmin.get("/tts/tts.mp3", function(req, res) { | ||
try { | ||
// RED.httpAdmin.get("/tts/tts.mp3", function(req, res) { | ||
// try { | ||
var url = require('url'); | ||
var url_parts = url.parse(req.url, true); | ||
var query = url_parts.query; | ||
//res.download(query.f); | ||
// var url = require('url'); | ||
// var url_parts = url.parse(req.url, true); | ||
// var query = url_parts.query; | ||
// //res.download(query.f); | ||
res.setHeader('Content-Disposition', 'attachment; filename=tts.mp3') | ||
if (fs.existsSync(query.f)) { | ||
// res.setHeader('Content-Disposition', 'attachment; filename=tts.mp3') | ||
// if (fs.existsSync(query.f)) { | ||
var readStream = fs.createReadStream(query.f); | ||
readStream.on("error", function(err) { | ||
fine(err); | ||
}); | ||
readStream.pipe(res); | ||
res.end; | ||
}else | ||
{ | ||
RED.log.error("Playsonos RED.httpAdmin file not found: " + query.f); | ||
res.write("File not found"); | ||
res.end(); | ||
} | ||
// var readStream = fs.createReadStream(query.f); | ||
// readStream.on("error", function(err) { | ||
// fine(err); | ||
// }); | ||
// readStream.pipe(res); | ||
// res.end; | ||
// }else | ||
// { | ||
// RED.log.error("Playsonos RED.httpAdmin file not found: " + query.f); | ||
// res.write("File not found"); | ||
// res.end(); | ||
// } | ||
} catch (error) { | ||
RED.log.error("Playsonos RED.httpAdmin error: " + error + " on: " + query.f); | ||
} | ||
function fine(err){ | ||
RED.log.error("Playsonos error opening stream : " + query.f + ' : ' + error); | ||
res.end; | ||
} | ||
}); | ||
// } catch (error) { | ||
// RED.log.error("Playsonos RED.httpAdmin error: " + error + " on: " + query.f); | ||
// } | ||
// function fine(err){ | ||
// RED.log.error("Playsonos error opening stream : " + query.f + ' : ' + error); | ||
// res.end; | ||
// } | ||
// }); | ||
} |
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
361886
996
224
4