').attr('id', 'forcesave');
forcesave.append(
$('
').text('Click the button below to force an immediate settings save. This differs from a regular save to memory and file save on exit by saving directly to file while operating. This may slow server processes for a short period of time.')
).append(
$('').click(function()
{
if(confirmDelete('Are you sure you want to force a JSON save?') == true)
{
forceJSONSave();
}
}).text( 'force save to JSON file' )
);
$('#page').append(forcesave);
break;
case 'protocols':
$table = $('');
$table.html("Protocol Port Interface ");
$tbody = $('');
var tr, i, protocol,
len = (settings.settings.config.protocols ? settings.settings.config.protocols.length : 0);
$tbody.html('');
for(i = 0; i < len; i++)
{
protocol = settings.settings.config.protocols[i]; // local copy
tr = $('').attr('id', 'protocol-' + i);
tr.append( $('').text( protocol.connector ) );
tr.append( $(' ').text( protocol.port ) );
tr.append( $(' ').text( protocol['interface'] ) ); // interface is a reserved JS keyword
tr.append( $(' ').attr('class', 'center').append( $('').click(function()
{
if(confirmDelete('Are you sure you want to delete this protocol?') == true)
{
var id = $(this).parent().parent().attr('id').replace('protocol-', '');
settings.settings.config.protocols.splice(id, 1);
$(this).parent().parent().remove();
loadSettings();
}
}).text('delete') ) );
$tbody.append(tr);
}
// add new protocol!
$nprot = $('').attr('class', 'outsidetable');
// protocol select
$pname = $('').attr('id', 'new-protocol-name');
$pname.append( $('').attr('value', 'HTTP').text('HTTP') );
$pname.append( $(' ').attr('value', 'RTMP').text('RTMP') );
$nprot.append( $('').append($pname) );
// the port value
$nprot.append( $(' ').append( $(' ').attr('type', 'number').attr('id', 'new-protocol-val') ) );
// interface
$nprot.append( $(' ').append( $(' ').attr('type', 'text').attr('id', 'new-protocol-interface') ) );
$nprot.append(
$(' ').attr('class', 'center').append(
$('').click(function()
{
if($('#new-protocol-val').val() == '')
{
$('#new-protocol-val').focus();
return;
}
if(!settings.settings.config.protocols)
{
settings.settings.config.protocols = [];
}
var nobj =
{
connector: $('#new-protocol-name :selected').val(),
port: Math.abs($('#new-protocol-val').val())
};
nobj['interface'] = $('#new-protocol-interface').val();
settings.settings.config.protocols.push(nobj);
loadSettings(function()
{
showTab('protocols');
});
}).text('add new')
)
);
$tbody.append($nprot);
$table.append($tbody);
$('#page').append($table);
break;
case 'streams':
// the filter element containr
$div = $('').attr('id', 'streams-filter');
// filters the table. uses the streamsdisplay
function filterTable()
{
$('#streams-list-tbody').children().each(function(k, v)
{
var type = $($(v).children()[0]).text().toLowerCase();
$(v).show();
if(type == 'recorded' && streamsdisplay[0] == false)
{
$(v).hide();
}
if(type == 'live' && streamsdisplay[1] == false)
{
$(v).hide();
}
});
}
function filterOn(event, elem)
{
if(event.target.id == '')
{
return; // label click goes bubbles on checkbox, so ignore it
}
var what = $(elem).text();
if(what == 'recorded')
{
streamsdisplay[0] = !streamsdisplay[0];
$('#stream-filter-recorded').attr('checked', streamsdisplay[0]);
}else{
streamsdisplay[1] = !streamsdisplay[1];
$('#stream-filter-live').attr('checked', streamsdisplay[1]);
}
filterTable();
}
$div.append(
$('
').attr('for', 'stream-filter-recorded').text('recorded').append(
$(' ').attr('type', 'checkbox').attr('id', 'stream-filter-recorded').attr('checked', streamsdisplay[0])
).click(function(event)
{
filterOn(event, this);
})
);
$div.append(
$('').attr('for', 'stream-filter-live').text('live').append(
$(' ').attr('type', 'checkbox').attr('id', 'stream-filter-live').attr('checked', streamsdisplay[1])
).click(function(event)
{
filterOn(event, this);
})
);
$('#page').append($div);
// refresh every streams' data (status and viewer count)
function refreshStreams()
{
getStreamsData(function(streams)
{
for(stream in streams)
{
if( $('stream-' + stream) )
{
var row = $('#stream-' + stream);
var status = streams[stream][0];
/*
if(status == 1)
{
$(row.children()[3]).html("Running ");
}
$(row.children()[3]).html("" + (status == 0 ? 'Offline' : (!status ? 'Unknown, checking...' : status) ) + " ");
}
*/
$(row.children()[3]).html( formatStatus(status) );
$(row.children()[4]).text(streams[stream][1]);
}
}
});
};
sinterval = setInterval(function()
{
refreshStreams();
}, 10000);
refreshStreams();
$table = $('');
$table.html("Type Embed Name Status Viewers Edit ");
$tbody = $('');
var stream, cstr, $tr;
$tbody.html('').attr('id', 'streams-list-tbody');
for(stream in settings.settings.streams)
{
var cstr = settings.settings.streams[stream];
$tr = $('').attr('id', 'stream-' + stream);
$tr.append( $('').text( TypeofResource( cstr.channel.URL ) ) );
$tr.append( $(' ').append( $('').text('embed').click(function()
{
var sname = $(this).parent().parent().attr('id').replace('stream-', '');
showTab('embed', sname);
}) ) ); // end function, end click(), end append(), end append(). Huzzah jQuery.
$tr.append( $('').text(cstr.name) );
/*
if(cstr.online && cstr.online == 1)
{
$tr.append( $(' ').html("Running ") );
}else{
$tr.append( $(' ').html("" + (cstr.online == 0 ? 'Offline' : 'Unknown, checking...') + " ") );
}
*/
$tr.append( $(' ').html( formatStatus(cstr.online) );
var cviewers = 0;
if(settings.settings.statistics && settings.settings.statistics[stream])
{
if(settings.settings.statistics[stream] && settings.settings.statistics[stream].curr)
{
for(viewer in settings.settings.statistics[stream].curr)
{
cviewers++;
}
}
}else{
cviewers = 0;
}
$tr.append( $(' ').text( cviewers ) );
$tr.append( $(' ').append( $('').text('edit').click(function()
{
var sname = $(this).parent().parent().attr('id').replace('stream-', '');
showTab('editstream', sname);
}) ) ); // end function, end click, end append, end append.
$tbody.append($tr);
}
$table.append($tbody);
$('#page').append($table);
// on page load, also filter with the (users' defined) stream filter
filterTable();
$('#page').append(
$('').attr('class', 'floatright').click(function()
{
showTab('editstream', 'new');
}).text('add new')
);
break;
case 'editstream':
var sdata, title;
if(streamname == 'new')
{
sdata =
{
name: '',
channel:
{
URL: ''
},
limits: [],
preset:
{
cmd: ''
}
};
title = 'add new stream';
}else{
sdata = settings.settings.streams[streamname];
title = 'edit stream "' + sdata.name + '"';
}
$('#page').append( $('').text(title) );
$('#page').append(
$('
').attr('id', 'editserver').append(
$('
').attr('for', 'stream-edit-name').text('name').append(
$(' ').attr('type', 'text').attr('placeholder', 'NAME').attr('id', 'stream-edit-name').attr('value', sdata.name)
)
).append(
$('').attr('for', 'stream-edit-source').text('source').append(
$(' ').attr('type', 'text').attr('placeholder', 'SOURCE').attr('id', 'stream-edit-source').attr('value', sdata.channel.URL).keyup(function()
{
var text = $(this).val();
if(text.charAt(0) == '/' || text.substr(0, 7) == 'push://')
{
$('#stream-edit-preset').val('');
$('#stream-edit-preset').hide();
$('#stream-edit-preset-label').hide();
}else{
$('#stream-edit-preset').show();
$('#stream-edit-preset-label').show();
}
})
)
).append(
$('').attr('id', 'stream-edit-preset-label').attr('for', 'stream-edit-preset').text('preset').append(
$(' ').attr('type', 'text').attr('placeholder', 'PRESET').attr('id', 'stream-edit-preset').attr('value', sdata.preset.cmd)
)
)
);
// if the source is push or file, don't do a preset
var text = $('#stream-edit-source').val();
if(text.charAt(0) == '/' || text.substr(0, 7) == 'push://')
{
$('#stream-edit-preset').hide();
$('#stream-edit-preset-label').hide();
}else{
$('#stream-edit-preset').show();
$('#stream-edit-preset-label').show();
}
$('#editserver').append(
$('').attr('class', 'floatright').click(function()
{
if(streamname == 'new')
{
showTab('streams');
}else{
if(confirmDelete('Are you sure you want to delete the stream "' + settings.settings.streams[streamname].name + '"?') == true)
{
delete settings.settings.streams[streamname];
loadSettings(function()
{
showTab('streams');
});
}
}
}).text( streamname == 'new' ? 'cancel' : 'delete' )
);
$('#editserver').append(
$('').attr('class', 'floatright').click(function()
{
var n = $('#stream-edit-name');
var s = $('#stream-edit-source');
var p = $('#stream-edit-preset');
if(n.val() == ''){ n.focus(); return; }
if(s.val() == ''){ s.focus(); return; }
var newname = n.val().replace(/([^a-zA-Z0-9_])/g, '').toLowerCase();
sdata.name = newname;
sdata.channel.URL = s.val();
sdata.preset.cmd = p.val();
if(streamname == 'new')
{
streamname = newname;
}
if(!settings.settings.streams)
{
settings.settings.streams = {};
}
delete settings.settings.streams[streamname];
settings.settings.streams[newname] = sdata;
loadSettings(function()
{
showTab('streams');
});
}).text('save')
);
break;
case 'embed':
if(isThereAHTTPConnector())
{
var embed = 'http://' + parseURL(settings.server).host + ':8080/embed_' + streamname + '.js';
$('#page').append( $('').attr('class', 'nocapitals').text('The embed URL is "' + embed + '".') );
$('#page').append( $('').text('preview').click(function()
{
showTab('preview', streamname);
} ) );
}else{
$('#page').append( $('').attr('class', 'nocapitals').text('Could\'t find a HTTP connector. Please add a HTTP connector on the "protocol" page.') );
}
break;
case 'preview':
var embed = 'http://' + parseURL(settings.server).host + ':8080/embed_' + streamname + '.js';
$('#page').append( $('
').html( "" ) );
break;
case 'limits':
$table = $('
');
$table.html("Type Hard/soft Value applies to Action ");
$tbody = $('');
var i, tr, limit, stream, clims,
alllimits = settings.settings.config.limits;
for(stream in settings.settings.streams)
{
clims = settings.settings.streams[stream].limits;
$.each(clims, function(k, v)
{
this.appliesto = stream;
this.appliesi = k;
});
alllimits = alllimits.concat(clims);
}
len = alllimits.length;
// remove old items
$tbody.html('');
for(i = 0; i < len; i++)
{
tr = $('').attr('id', 'limits-' + i);
limit = alllimits[i];
tr.append( $('').text( shortToLongLimit(limit.name) ) );
tr.append( $(' ').text( limit.type ) );
tr.append( $(' ').text( limit.val ) );
if(limit.appliesto)
{
tr.append( $(' ').text( settings.settings.streams[limit.appliesto].name ).attr('id', 'limit-at-' + limit.appliesto + '-' + limit.appliesi) );
}else{
tr.append( $(' ').text( 'server' ) );
}
delete limit.appliesto;
delete limit.appliesi;
tr.append( $(' ').attr('class', 'center').append( $('').click(function()
{
if(confirmDelete('Are you sure you want to delete this limit?') == true)
{
var id = $(this).parent().parent().attr('id').replace('limits-', '');
var at = $($(this).parent().parent().children()[3]).attr('id');
if(at == undefined)
{
settings.settings.config.limits.splice(id, 1);
}else{
var data = at.replace('limit-at-', '').split('-');
var loc = data.pop();
data = data.join('-');
settings.settings.streams[data].limits.splice(loc, 1);
}
$(this).parent().parent().remove();
loadSettings();
}
}).text('delete') ) );
$tbody.append(tr);
}
// add new limit
$nltr = $('').attr('class', 'outsidetable');
// type selector
$ltype = $('').attr('id', 'new-limit-type');
for(i = 0; i < ltypes.length; i++)
{
$ltype.append( $('').attr('value', ltypes[i][0]).text(ltypes[i][1]) );
}
$nltr.append( $('').append( $ltype ) );
// hard/soft limit
$nltr.append( $(' ').append( $('').attr('id', 'new-limit-hs').append( $('').attr('value', 'hard').text('Hard limit') ).append( $(' ').attr('value', 'soft').text('Soft limit') ) ) );
// value
$nltr.append( $('').append( $(' ').attr('type', 'text').attr('id', 'new-limit-val') ) );
// applies to (stream)
var $appliesto = $('').attr('id', 'new-limit-appliesto').append( $('').attr('value', 'server').text('Server') );
for(var strm in settings.settings.streams)
{
$appliesto.append(
$(' ').attr('value', strm).text(settings.settings.streams[strm].name)
);
}
$nltr.append( $('').append( $appliesto ) );
$nltr.append(
$(' ').attr('class', 'center').append(
$('').click(function()
{
var obj =
{
name: $('#new-limit-type :selected').val(),
type: $('#new-limit-hs :selected').val(),
val: $('#new-limit-val').val()
};
if( $('#new-limit-appliesto').val() == 'server')
{
settings.settings.config.limits.push(obj);
}else{
settings.settings.streams[ $('#new-limit-appliesto').val() ].limits.push(obj);
}
loadSettings(function()
{
showTab('limits');
});
}).text('add new')
)
);
$tbody.append($nltr);
$table.append($tbody);
$('#page').append($table);
break;
case 'logs':
$table = $('');
$table.html("Date(MM/DD/YYYY) Type Message ");
$tbody = $('');
if(!settings.settings.log)
{
return; // no logs, so just bail
}
var i, cur, $tr,
logs = settings.settings.log,
len = logs.length;
if(len >= 2 && settings.settings.log[0][0] < settings.settings.log[len - 1][0])
{
logs.reverse();
}
$tbody.html('');
for(i = 0; i < len; i++)
{
cur = settings.settings.log[i];
$tr = $('').append(
$('').text(formatDate(cur[0]))
).append(
$(' ').text(cur[1])
).append(
$(' ').text(cur[2])
);
$tbody.append($tr);
}
$table.append($tbody);
$('#page').append($table);
$('#page').append(
$('').attr('class', 'floatright').click(function()
{
settings.settings.clearstatlogs = 1;
loadSettings(function()
{
showTab('logs');
});
}).text('Purge logs')
);
break;
case 'disconnect':
showTab('login');
setHeaderState('disconnected');
$('#nav').css('visibility', 'hidden');
settings =
{
server: '',
credentials:
{
username: "",
password: "",
authstring: ""
},
settings: {}
};
break;
} // end switch
//placeholder for older browsers
$('input[placeholder]').placeholder();
}