-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(media/renderers): add minimal media Renderer based on BehaviorSu…
…bject
- Loading branch information
Showing
6 changed files
with
166 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as express from 'express'; | ||
import * as bodyParser from 'body-parser'; | ||
|
||
import http = require('http'); | ||
|
||
|
||
|
||
// create server and listen on provided port (on all network interfaces). | ||
class Server { | ||
public app: express.Express; | ||
private _server:any; | ||
private _port:number|string|boolean; | ||
|
||
constructor (_port?:string) { | ||
this.app = express(); | ||
this.app.use(bodyParser.json()); | ||
this.app.use(bodyParser.urlencoded({ extended: false })); | ||
|
||
// Get port from environment and store in Express. | ||
this._port = this.normalizePort(process.env.PORT || _port || '3000'); | ||
this.app.set('port', this._port); | ||
|
||
this._server = http.createServer(this.app); | ||
} | ||
|
||
init() { | ||
this._server.listen(this._port); | ||
this._server.on('listening', this.onListening); | ||
} | ||
|
||
/** | ||
* Normalize a port into a number, string, or false. | ||
*/ | ||
normalizePort(val: any): number|string|boolean { | ||
let port = parseInt(val, 10); | ||
|
||
if (isNaN(port)) { | ||
// named pipe | ||
return val; | ||
} | ||
|
||
if (port >= 0) { | ||
// port number | ||
return port; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Event listener for HTTP server "listening" event. | ||
*/ | ||
onListening = () => { | ||
let addr = this._server.address(); | ||
let bind = typeof addr === 'string' | ||
? 'pipe ' + addr | ||
: 'port ' + addr.port; | ||
|
||
console.log('Listening on ' + bind); | ||
} | ||
}; | ||
|
||
export { Server }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|