// Initializing script

//// Global Variable
var debugMode = true;

//// Player status:
var stPLAYER_STOPED = 0     // the player has with a normal/stoped mode
var stPLAYER_PLAYING = 1   // the player are playing some video right now
var stPLAYER_PAUSED = 2    // the player in pause
var stPLAYER_FASTFWD = 3   // the player is at fast-forward mode
var stPLAYER_SEEKING = 4   // the user is seeking the video
var stPLAYER_LOADING = 8    // the whole player application loading
var stRECORDER_STARTED = 5 // the user recording himself
var stRECORDER_STOPED = 6  // the recorder is in the stop mode
var stRECORDER_LOADING = 7  // the recorder loading at startup
var stRECORDER_PLAYING = 9  // the user watching his last record
var stRECORDER_PAUSED = 10  // the user paused his replay of last record
var stRECORDER_SEEKING = 11  // the user seeking his last record

//// Panel status
var stPANEL_CLOSED = 0;
var stPANEL_OPENED = 1;

var statusArr = new Array(
    "PLAYER_STOPED",
    "PLAYER_PLAYING",
    "PLAYER_PAUSED",
    "PLAYER_FASTFWD",
    "PLAYER_SEEKING",
    "RECORDER_STARTED",
    "RECORDER_STOPED",
    "RECORDER_LOADING",
    "PLAYER_LOADING",
    "RECORDER_PLAYING",
    "RECORDER_PAUSED",
    "RECORDER_SEEKING"
)

var dtc = ""; // detect typing code in body
var timing = 0; // timing, used to detect string sequence of typing code
var last_code_time = 0; // timestamp of last time key was pressed
var noMic = false; // true if microphone device has not detected

// found recording devices on user computer
function deviceDetected() {
    plyr.onRecordReady(true);
}

// camera device was not found or there was an arror to detect the camera device
function errorCamera() {
    plyr.onRecordReady(false);
}

// microphone device was not found or there was an arror to detect the microphone device
function errorMicrophone() {
    noMic = true;
}

/*
new entry added successfully, with entry element 'addedEntry'.
list of available properties on the created entry:
    plays,width,height,views,entryId,entryName,partnerId,subpId,tags,status,
    entryType,mediaType,kshowId,kuserId,puserId,createdAtAsInt,createdAt,
    duration,description,thumbnailUrl,entryVersion,displayCredit,userScreenName,
    dataUrl,downloadUrl,adminTags,sourceLink,userLandingPage */
function addEntryComplete(addedEntry) {/*alert("entry_complete");*/ plyr.onEntryComplete(addedEntry[0]);}

// failed to add entry, with arror(s) 'err'
function addEntryFail(err) {plyr.onEntryFail(err)}

// preview recorded video finished
function previewEnd() {plyr.recordingPreviewFinished()}

// finished sending recorded stream to server
// use [RecorderElement].getRecordedTime() to get the recorded time
function flushComplete() {}

// started sending recorded camera stream to server
function recordStart() {}

// connected to server
function connected() {}
