HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptMinor

Streaming media server

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
serverstreamingmedia

Problem

I'm wondering if anyone would like to give me some solid advice on how to better organize my main.js file. I have a hunch that I should probably break the file into multiple files and decrease the amount of global variables. Maybe my naming is not so great either? I'm using codekit so I can prepend if that won't screw up my scopes.

GitHub

```
//@codekit-prepend "jquery-1.10.2.min.js"
//@codekit-prepend "jquery.event.special.js"
//@codekit-prepend "jquery.easing.min.js"
//@codekit-prepend "lightbox-2.6.min.js"
//@codekit-prepend "handlebars-v1.1.2.js"

//Globals
var duration;
var seek_time;
var seek_bar_left;
var seek_bar_right;
var seek_scrub;
var seek_bar_width;
var xPos;
var name;
var cam_toggle;
var mic_toggle;
var rec_toggle;
var fav_toggle;
var mic_index = 0;//0 default mic
var cam_index = 0;//0 default cam
var drag = false;
var play_toggle = false;
var playing = false;
var recording = false;
var connection_open = false;
var current_video;
var current_user;
var user_avatar;
var user_avatar_array = [];
var comments_array = [];
var user_array = [];
var created_array = [];
var new_video = false;

//firebase globals
var db = new Firebase('https://adamgedney.firebaseio.com/');
var video_obj = db.child('/videos');
var comments_obj = db.child('/comments');

// var globalError = function(message){
// console.log(message, "error mess");
// }
//==========================================callbacks=================================//
var connected = function(success, error){
console.log(success, error);
if(success){
connection_open = true;

if(recording){
flash.startRecording(name,cam_index,mic_index);
}else{
flash.startPlaying(current_video);
};
}else{
connection_open = false;
}
};

var getDuration = function(dur){
duration = dur;
};

var seekTime = function(time){
seek_time = time;

Solution

Two random thoughts:

-
In the Category Dropdown part the $(this).html() could be extracted out to a named local variable.

-
The following code is duplicated, it could be extracted out a separate function:

$('.transport_popup').hide();
$('.rec_select').hide();
$('.mic_select').hide();
$('.cam_select').hide();

Code Snippets

$('.transport_popup').hide();
$('.rec_select').hide();
$('.mic_select').hide();
$('.cam_select').hide();

Context

StackExchange Code Review Q#40055, answer score: 2

Revisions (0)

No revisions yet.