mirror of
https://github.com/IrosTheBeggar/mStream.git
synced 2025-10-27 07:31:02 +00:00
Changing boot stuff
This commit is contained in:
parent
6f40cf3a72
commit
e79429d863
@ -37,15 +37,18 @@ function tunnel_uPNP (port, callback){
|
||||
console.log("uPNP failed. Your port may already be in use");
|
||||
|
||||
// Clear Interval
|
||||
if(tunnelInterval){
|
||||
if(tunnelInterval && callback){
|
||||
clearInterval(tunnelInterval);
|
||||
}
|
||||
|
||||
callback(false);
|
||||
if(callback){
|
||||
callback(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
callback(true);
|
||||
|
||||
if(callback){
|
||||
callback(true);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -85,29 +88,16 @@ function tunnel_uPNP (port, callback){
|
||||
// }
|
||||
|
||||
// TODO: Clean this up
|
||||
exports.setup = function(program){
|
||||
exports.setup = function(program, callback){
|
||||
if(program.tunnel.gateway){
|
||||
set_gateway(args.gateway);
|
||||
}
|
||||
|
||||
tunnel(program.port, program.tunnel.protocol, function(status){
|
||||
if(status === true){
|
||||
var protocol = 'http';
|
||||
if(program.ssl && program.ssl.cert && program.ssl.key){
|
||||
protocol = 'https';
|
||||
}
|
||||
|
||||
publicIp.v4().then(ip => {
|
||||
console.log('Access mStream on the internet: '+protocol+'://' + ip + ':' + program.port);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if(program.tunnel.refreshInterval){
|
||||
tunnelInterval = setInterval( function() {
|
||||
tunnel(program.port, program.tunnel.protocol, function(){
|
||||
|
||||
});
|
||||
tunnel(program.port, program.tunnel.protocol);
|
||||
}, program.tunnel.refreshInterval);
|
||||
}
|
||||
|
||||
tunnel(program.port, program.tunnel.protocol, callback);
|
||||
}
|
||||
|
||||
@ -9,4 +9,4 @@ if(program.error){
|
||||
}
|
||||
|
||||
const serve = require('./mstream.js');
|
||||
serve(program);
|
||||
serve.serveit(program);
|
||||
|
||||
53
mstream.js
53
mstream.js
@ -1,6 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function (program) {
|
||||
exports.logit = function(msg){
|
||||
console.log(msg);
|
||||
}
|
||||
|
||||
exports.addresses = {
|
||||
localhost: false,
|
||||
network: false,
|
||||
internet: false
|
||||
}
|
||||
|
||||
exports.serveit = function (program, callback) {
|
||||
// TODO: Verify program variable
|
||||
|
||||
const express = require('express');
|
||||
@ -145,34 +155,37 @@ module.exports = function (program) {
|
||||
|
||||
|
||||
// Start the server!
|
||||
// TODO: Check if port is in use befoe firing up server
|
||||
// TODO: Check if port is in use before firing up server
|
||||
server.on('request', mstream);
|
||||
server.listen(program.port, function () {
|
||||
// TODO: This if statement is lazy, clean it up
|
||||
if(program.ssl && program.ssl.cert && program.ssl.key){
|
||||
// Print the local network IP
|
||||
console.log('Access mStream locally: https://localhost:' + program.port);
|
||||
console.log('Access mStream on your local network: https://' + require('internal-ip').v4() + ':' + program.port);
|
||||
}else{
|
||||
// Print the local network IP
|
||||
console.log('Access mStream locally: http://localhost:' + program.port);
|
||||
console.log('Access mStream on your local network: http://' + require('internal-ip').v4() + ':' + program.port);
|
||||
}
|
||||
let protocol = program.ssl && program.ssl.cert && program.ssl.key ? 'https' : 'http';
|
||||
|
||||
exports.addresses.local = protocol + '://localhost:' + program.port;
|
||||
exports.addresses.network = protocol + '://' + require('internal-ip').v4() + ':' + program.port;
|
||||
|
||||
exports.logit('Access mStream locally: ' + exports.addresses.local);
|
||||
exports.logit('Access mStream on your local network: ' + exports.addresses.network);
|
||||
|
||||
// Handle Port Forwarding
|
||||
if(program.tunnel){
|
||||
try{
|
||||
require('./modules/auto-port-forwarding.js').setup(program);
|
||||
require('./modules/auto-port-forwarding.js').setup(program, function(status){
|
||||
if(status === true){
|
||||
require('public-ip').v4().then(ip => {
|
||||
// console.log('Access mStream on the internet: '+protocol+'://' + ip + ':' + program.port);
|
||||
exports.addresses.internet = protocol + '://' + ip + ':' + program.port;
|
||||
exports.logit('Access mStream on your local network:the internet: ' + exports.addresses.internet);
|
||||
});
|
||||
}else{
|
||||
console.log('Port Forwarding Failed');
|
||||
exports.logit('Port Forwarding Failed. The server is runnig but you will have to configure your own port forwarding');
|
||||
}
|
||||
});
|
||||
}catch(err){
|
||||
console.log('Port Forwarding Failed')
|
||||
console.log('Port Forwarding Failed');
|
||||
exports.logit('Port Forwarding Failed. The server is runnig but you will have to configure your own port forwarding');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// This would be ideal but it returns the wrong address on occasion
|
||||
// require('dns').lookup(require('os').hostname(), function (err, add, fam) {
|
||||
// console.log('Access mStream on your local network: http://' + add + ':' + program.port);
|
||||
// })
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user