Permalink
Browse files

Closes #5, Closes #11

  • Loading branch information...
1 parent 5739a03 commit 27c4071eb5aa4f7a217e1e4c757be1b67b1e4a86 Balaji committed Oct 9, 2012
@@ -1,17 +1,56 @@
(function(){
- var wami_initialized= false, recording= false;
+ var server_config= {
+ start_url: "/js-cast/start",
+ swfobject_url: "/js-cast/external/swfobject.js",
+ wami_swfurl: "/js-cast/external/wami/Wami.swf",
+ recorder_url: "/js-cast/external/wami/recorder.js"
+
+ };
+ var wami_initialized= false;
var evt_handler;
var wami_div_id;
- var stop_url= "";
+ var stop_url = "";
+ var base_url;
+
+ function loadScript(url, callback){
+ var script = document.createElement("script")
+ script.type = "text/javascript";
+
+ if (script.readyState){ //IE
+ script.onreadystatechange = function(){
+ if (script.readyState == "loaded" ||
+ script.readyState == "complete"){
+ script.onreadystatechange = null;
+ callback();
+ }
+ };
+ }
+ else { //Others
+ script.onload = function(){
+ callback();
+ };
+ }
+ script.src = url;
+ document.getElementsByTagName("head")[0].appendChild(script);
+ }
var SClass= function(){
- //load additional js required for wami
+ var href= window.location.href.toString(),
+ pathname= window.location.pathname.toString();
+ base_url= href.substr(0, href.length-pathname.length);
};
SClass.prototype.configure= function(options, callback){
wami_div_id= options.wami_container;
evt_handler= callback;
+ //load additional js required for wami
+ //swfobject is a commonly used library to embed Flash content
+ loadScript(server_config.swfobject_url, function(){
+ // Setup the recorder interface
+ loadScript(server_config.recorder_url, function(){
+ })
+ })
};
SClass.prototype.create= function(name, description){
@@ -20,8 +59,7 @@
document.getElementById(wami_div_id).style.display="";
Wami.setup({
id : wami_div_id,
- swfUrl: "/wami/Wami.swf",
- console: false,
+ swfUrl: server_config.wami_swfurl,
onReady : function(){
wami_initialized= true;
var ws= Wami.getSettings();
@@ -53,7 +91,7 @@
var self= this;
$.ajax({
data: {name: name, description: description},
- url: '/jscast/start',
+ url: server_config.start_url,
success: function(data) {
stop_url= data.stop_url;
self.start(data.post_url);
@@ -62,7 +100,7 @@
};
SClass.prototype.start= function(url){
- var recording_url= window.location.href.toString().replace(window.location.pathname.toString(), "")+url;
+ var recording_url= base_url + url;
console.log("Recording url=>"+recording_url);
try {
Wami.startRecording(recording_url);
@@ -94,5 +132,4 @@
JSCast= new SClass();
})();
-
View
@@ -7,7 +7,7 @@
"email": "balaji@ariemtech.com"
},
"dependencies": {
- "js-cast": "0.0.3",
+ "js-cast": "0.0.4",
"ejs":"0.8.3",
"express":"3.0.0rc4"
},
View
@@ -1,14 +1,13 @@
-var jscast= require("js-cast");
-
+var jscast = require("js-cast");
var express = require('express');
//NOTE: update below icecast details to suit ur server configuration.
-var options= {
-icecast: {
- server: "http://localhost:8000/",
- sourcepassword: "hackme"
- }
+var options = {
+ icecast: {
+ server: "http://localhost:8000/",
+ sourcepassword: "hackme"
+ }
};
var app = express();
@@ -32,7 +31,7 @@ app.configure('development', function(){
});
app.configure('production', function(){
- app.use(express.errorHandler());
+ app.use(express.errorHandler());
});
// Routes
@@ -47,7 +46,7 @@ app.get('/index.html', function(req, res){
app.get("/channels", function(req, res){
//This is not made part of /jscast/channels as there may be a need to hide active channels from client.
//send json response containing all the urls and names the active clients
- var channels= jscast.getActiveClients();
+ var channels = jscast.getActiveClients();
res.contentType('json');
res.send(channels);
});
View
@@ -1,14 +1,9 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
- <!-- swfobject is a commonly used library to embed Flash content -->
- <script type="text/javascript"
- src="swfobject.js"></script>
-
- <!-- Setup the recorder interface -->
- <script type="text/javascript" src="wami/recorder.js"></script>
- <script type="text/javascript" src="jquery-1.8.2.min.js"></script>
- <script type="text/javascript" src="jscast.js"></script>
+ <script type="text/javascript" src="/js-cast.js"></script>
+
+ <script type="text/javascript" src="jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="main.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1,3 @@
+
+module.exports = require('./lib/js-cast');
+
@@ -28,7 +28,7 @@ JSCast.prototype.configure= function(app, config){
this._num_active_clients= 0;
var home= fs.realpathSync(process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']);
- this._dir= home + "/"+ ".jscast"; //configuration files for ezstream stored here
+ this._dir= home + "/"+ ".js-cast"; //configuration files for ezstream stored here
try {
fs.rmrfSync(this._dir);
fs.mkdirpSync(this._dir);
@@ -38,7 +38,7 @@ JSCast.prototype.configure= function(app, config){
}
var self= this;
- app.get("/jscast/start", function(req, res,next){
+ app.get("/js-cast/start", function(req, res,next){
if (self._num_active_clients === self._max_clients){
self._send503();
}
@@ -58,8 +58,8 @@ JSCast.prototype.configure= function(app, config){
var data= {
id: id,
url: client.getUrl(),
- post_url: "/jscast/stream/?id="+id,
- stop_url: "/jscast/end/?id="+id,
+ post_url: "/js-cast/stream/?id="+id,
+ stop_url: "/js-cast/end/?id="+id,
name: name,
description: description
};
@@ -68,7 +68,7 @@ JSCast.prototype.configure= function(app, config){
}
});
- app.post('/jscast/stream', function(req, res, next){
+ app.post('/js-cast/stream', function(req, res, next){
var client= self._clients[req.query.id];
if (client){
req.on("data", function(chunk) {
@@ -83,7 +83,7 @@ JSCast.prototype.configure= function(app, config){
}
});
- app.get("/jscast/end", function(req, res, next){
+ app.get("/js-cast/end", function(req, res, next){
var client= self._clients[req.query.id];
if (client){
client.destroy();
@@ -92,7 +92,32 @@ JSCast.prototype.configure= function(app, config){
else {
self._send404(res);
}
- })
+ });
+
+
+ var nstatic = require('node-static');
+ var fileServer = new(nstatic.Server)('../');
+
+ var serveStaticFile= function(url, req, res){
+ fileServer.serveFile(url, 200, {}, req, res);
+ };
+
+ app.get("/js-cast.js", function(req, res, next){
+ serveStaticFile('/client/js-cast.js', req, res);
+ });
+
+ app.get("/js-cast/external/wami/Wami.swf", function(req, res, next){
+ serveStaticFile(req.url.replace(/^\/js-cast/,""), req, res);
+ });
+
+ app.get("/js-cast/external/wami/recorder.js", function(req, res, next){
+ serveStaticFile(req.url.replace(/^\/js-cast/,""), req, res);
+ });
+
+ app.get("/js-cast/external/swfobject.js", function(req, res, next){
+ serveStaticFile(req.url.replace(/^\/js-cast/,""), req, res);
+ });
+
};
JSCast.prototype._send404= function(res){
@@ -130,12 +155,13 @@ JSCast.prototype.handleEvent= function(evt, data){
var sc= SourceClient;
switch(evt.code){
case sc.STARTED:
+ console.log("Client started:"+data.getId());
this._clients[data.getId()]= data;
break;
case sc.ENDED:
this._num_active_clients--;
delete this._clients[data.getId()];
- console.log("Client ended:");
+ console.log("Client ended:"+data.getId());
break;
case sc.LOG:
console.log(data);
View
@@ -9,8 +9,7 @@
"dependencies": {
"fs.extra": "1.2.0",
"clone": "0.1.1",
- "ejs":"0.8.3",
- "express":"3.0.0rc4"
+ "node-static": "0.6.2"
},
"keywords": [
"icecast",

0 comments on commit 27c4071

Please sign in to comment.