Skip to content

Commit

Permalink
first import
Browse files Browse the repository at this point in the history
  • Loading branch information
luckcape committed Jun 8, 2017
0 parents commit 612c3e8
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Binary file added bin/darwin/tvbus
Binary file not shown.
Binary file added bin/win32/cyggcc_s-1.dll
Binary file not shown.
Binary file added bin/win32/cygstdc++-6.dll
Binary file not shown.
Binary file added bin/win32/cygwin1.dll
Binary file not shown.
Binary file added bin/win32/tvbus.exe
Binary file not shown.
106 changes: 106 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* TVBUS interface
*/
'use strict';

var path = require("path");
var child_process = require("child_process");
var events = require("events");

// import EventEmitter from 'events';

class TVBus {

static get version() {
// replaced with browserify-versionify transform
return '5.4.0';
}

constructor() {
var observer = this.observer = new events.EventEmitter();
this.on = observer.on.bind(observer);

var tvbusbin = 'tvbus';
if(process.platform == 'win32') {
tvbusbin = 'tvbus.exe';
}

var cmd = path.join(__dirname, 'bin', process.platform, tvbusbin);
var params = [];

params.push("init");
params.push("4000");
params.push("8902");

this.tvbusProcess = child_process.spawn(cmd, params);

this.tvbusProcess.stdout.on('data', function(data) {
var events = data.toString('utf8').trim().split("\n");


for (let event of events) {
console.log('TVBus.stdout: ==' + event + '==');
if(event.startsWith("[Inited]")) {
observer.emit("init", event.split(":")[1].trim())
}
else if(event.startsWith("[Prepared]") && event.endsWith(".m3u8")) {
observer.emit("prepared", event.split(" ")[1].trim())
}
else if(event.startsWith("[Buffer]")) {
observer.emit("buffer", event.split(":")[1].trim())
}
else if(event.startsWith("[Stats]")) {
observer.emit("stats", event.split(":")[1].trim())
}
else if(event.startsWith("[Stop]")) {
observer.emit("stop", event.split(":")[1].trim())
}
else if(event.startsWith("[Start]")) {
observer.emit("start", "")
}
// else {
// console.log('TVBus.stdout: ==---' + event + '==');
// }
}
});
this.tvbusProcess.stderr.on('data', function(data) {
console.log('stderr: ' + data);
//Here is where the error output goes
});
this.tvbusProcess.on('close', function(code) {
console.log('closing code: ' + code);
//Here you can get the exit code of the script
});
}

startChannel(addr, accessCode) {
if(! this.tvbusProcess) {
return;
}

if(typeof accessCode === 'string' && accessCode.length > 0) {
this.tvbusProcess.stdin.write("start -c " + accessCode + " " + addr + "\n");
}
else {
this.tvbusProcess.stdin.write("start " + addr + "\n");
}
}

stopChannel() {
if(! this.tvbusProcess) {
return;
}
this.tvbusProcess.stdin.write("stop\n");
}

quit() {
if(! this.tvbusProcess) {
return;
}
this.tvbusProcess.stdin.write("quit\n");
}

}


module.exports = TVBus;
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "tvbus.js",
"version": "0.5.1",
"description": "nodejs module for tvbus",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"tvbus",
"nodejs",
"p2p",
"streaming"
],
"author": "binstream.io",
"dependencies": {
"babel-preset-es2015": "^6.22.0"
}
}

0 comments on commit 612c3e8

Please sign in to comment.