rendered paste body /**************************************************\| || VideoStream Class || --------------------- || This class creates and controls a video stream || object, once started, it is self sustaining and || has members for changing its resolution, mapping || the image object and the stream name to the dom || tree, and controling the feed (start, stop, pause,|| rewind, fastforward, seek, ect (most arent done, || but will be comming soon)). || | \**************************************************/ /**** Singleton Array of all Streams ****/ VideoStream.prototype.allStreams = new Array(0); /******************************************\ | VideoStream constructor | | ----------------------- | | Parameters: | | name: String name of the video | | locator: IP address or Domain Name of | | the video provider | | hash: Identifier hash passed to the | | provider for authentication | | videoSize: String name of the resolution | | to use, (e.g. high, low) | | | \******************************************/ function VideoStream(name, locator, hash, frameSize) { this.streamName = document.createElement('p').appendChild(document.createTextNode(name)); this.streamState = 'stop'; this.streamVideo = document.createElement('img'); this.serverLocator = locator; this.serverHash = hash; this.frameDelay = 200; this.frameSize = frameSize; this.frameDelayTimeout = -1; this.frameLoadDelay = 1000; this.frameLoadTimeout = -1; this.frameLagCount = 0; this.streamID = (VideoStream.prototype.allStreams.push(-1)-1); VideoStream.prototype.allStreams[this.streamID] = this; //I tried this// this.streamVideo.setAttribute('onLoad', 'VideoStream.prototype.delayFrame("'+this.streamID+'")'); //and this this.streamVideo.onload = 'VideoStream.prototype.delayFrame("'+this.streamID+'")';//this.delayFrame(this.streamID); // and this// this.streamVideo.onload = VideoStream.prototype.delayFrame(this.streamID); } /************************************\| **** Video Controller Functions **** | \************************************/ VideoStream.prototype.start = function() { if (this.streamState == 'start') return true; this.streamState = 'start'; this.streamVideo.setAttribute('onLoad', 'VideoStream.prototype.delayFrame("'+this.streamID+'")'); this.streamVideo.src = this.buildURL();// this.reloadFrame(this.streamID); } VideoStream.prototype.stop = function() { if (this.streamState == 'stop') return true; this.streamState = 'stop'; } VideoStream.prototype.pause = VideoStream.prototype.stop(); /**********************************\| ******* Mapping Functions ******** | \**********************************/ /*************************************\ | mapUnder: Maps one object as a | | child to to another | | --------------------------------- | | Parameters: | | parent_obj: object to map to | | source_obj: object being mapped | | class_name: class of source | | | \*************************************/ VideoStream.prototype.mapUnder = function(parent_obj, source_obj, class_name) {// source_obj.setAttribute('class', class_name); parent_obj.appendChild(source_obj); } /*************************************\ | mapBefore: Maps one object after | | another object in DOM | | --------------------------------- | | Parameters: | | sibling_obj: object to map after | | source_obj: object being mapped | | class_name: class of source | | | \*************************************/ VideoStream.prototype.mapBefore = function(sibling_obj, source_obj, class_name) {// source_obj.setAttribute('class', class_name); sibling_obj.offsetParent.insertBefore(source_obj, sibling_obj); } /*************************************\ | mapVideoUnder/ Wrappers to mapUnder | | mapVideoBefore: and mapAfter passing | | the Video object | | ----------------------------------- | | Parameters: | | parent_id/ ID of parent or | | sibling_id: sibling | | class_name: class of source | | | \*************************************/ VideoStream.prototype.mapVideoUnder = function(parent_id, class_name) { var our_parent = document.getElementById(parent_id); if (undefined == our_parent) return false; this.mapUnder(our_parent, this.streamVideo, class_name); return true; } VideoStream.prototype.mapVideoBefore = function(sibling_id, class_name) { var our_sib = document.getElementById(sibling_id); if (undefined == our_sib) return false; this.mapBefore(our_sib, this.streamVideo, class_name); return true; } /*************************************\ | mapNameUnder/ Wrappers to mapUnder | | mapNameBefore: and mapAfter passing | | the streamName object | | ------------------------------------ | | Parameters: | | parent_id/ ID of parent or | | sibling_id: sibling | | class_name: class of source | | | \*************************************/ VideoStream.prototype.mapNameUnder = function(parent_id, class_name) { var our_parent = document.getElementById(parent_id); if (undefined == our_parent) return false; this.mapUnder(our_parent, this.streamName, class_name); return true; } VideoStream.prototype.mapNameBefore = function(sibling_id, class_name) { var our_sib = document.getElementById(sibling_id); if (undefined == our_sib) return false; this.mapBefore(our_sib, this.streamName, class_name); return true; } /****************************************\| ****** Video Continuity Functions ****** || ** You shouldn't have to modify these ** | \****************************************/ /*************************************\ | delayFrame: Called after a frame | | is loaded to create a | | delay between frames | | ---------------------------------- | | Parameters: | | id: The array slice ID for this | | Video object. | | | \*************************************/ VideoStream.prototype.delayFrame = function(id) { var stream = VideoStream.prototype.allStreams[id]; if (stream.streamState != 'start') return true; if (stream.frameLagCount > 0) stream.frameLagCount--; alert('mark'); stream.frameDelayTimeout = setTimeout( 'VideoStream.prototype.reloadFrame("' + id + '")', stream.frameDelay ); } /**************************************\ | reloadFrame: Called after delayFrame, | | buildURL returns new src | | ------------------------------------ | | Parameters: | | id: The array slice ID for this | | Video object. | | | \**************************************/ VideoStream.prototype.reloadFrame = function(id) { var stream = VideoStream.prototype.allStreams[id]; if (undefined == stream) return; if (!stream.streamVideo.complete) return; stream.streamVideo.src = stream.buildURL(); if (!window.netscape) { stream.frameLoadTimeout = setTimeout( 'VideoStream.prototype.timeoutFrame("'+id+'")', stream.frameLoadDelay ); } } VideoStream.prototype.timeoutFrame = function(id) { var stream = VideoStream.prototype.allStreams[id]; if (stream.streamState != 'start') return true; stream.frameLagCount++; if (stream.frameLagCount > 5 && stream.frameSize == 'high') { stream.frameSize = 'low'; } stream.reloadFrame(id); } /*************************************\ | buildURL: Called to build the URL | | of the video provider. | | ---------------------------------- | | Parameters: None | | | \*************************************/ VideoStream.prototype.buildURL = function() { var path = 'http://' + this.serverLocator + '/'; if (!window.netscape) path += '?single=true'; path += '&res=' + this.frameSize; path += '&t=' + (new Date()).getTime(); return path; } /*******************************************/