OpenROV /
openrov-cockpit
| 1 | (function () { |
||
| 2 | $('#t')[0].userRole = 'REPLAY'; |
||
| 3 | window.cockpit.withHistory.on('blackbox-dixie-object', function (idb) { |
||
| 4 | var emitter = window.cockpit.rov; |
||
| 5 | var historicTime = new Date(); |
||
| 6 | var session = getParameterByName('rp'); |
||
| 7 | //Get the data for the session |
||
| 8 | var spawn = Dexie.spawn; |
||
| 9 | var listMP4Data = function (offset, limit) { |
||
| 10 | return idb.telemetry_events.where('sessionID').equals(session).offset(offset).filter(function (item) { |
||
| 11 | return item.event == 'x-h264-video.data'; |
||
| 12 | }).limit(limit).toArray(); |
||
| 13 | }; |
||
| 14 | var listMP4Data = function (lowerIdLimit, limit) { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 15 | return idb.telemetry_events.get(lowerIdLimit).then(function (lastItem) { |
||
| 16 | var lowerbounds = lastItem !== undefined ? lastItem.timestamp : 0; |
||
| 17 | return idb.telemetry_events.where('[sessionID+timestamp]').between([ |
||
| 18 | session, |
||
| 19 | lowerbounds |
||
| 20 | ], [ |
||
| 21 | session, |
||
| 22 | Infinity |
||
| 23 | ], false, true).filter(function (item) { |
||
| 24 | return item.event == 'x-h264-video.data'; |
||
| 25 | }).limit(limit).toArray(); |
||
| 26 | }); |
||
| 27 | }; |
||
| 28 | var listTelemetryData = function (offset, limit) { |
||
| 29 | return idb.telemetry_events.where('sessionID').equals(session).offset(offset).filter(function (item) { |
||
| 30 | return item.event !== 'x-h264-video.data'; |
||
| 31 | }).limit(limit).toArray(); |
||
| 32 | }; |
||
| 33 | var listTelemetryData = function (lowerIdLimit, limit) { |
||
|
0 ignored issues
–
show
|
|||
| 34 | return idb.telemetry_events.get(lowerIdLimit).then(function (lastItem) { |
||
| 35 | var lowerbounds = lastItem !== undefined ? lastItem.timestamp : 0; |
||
| 36 | return idb.telemetry_events.where('[sessionID+timestamp]').between([ |
||
| 37 | session, |
||
| 38 | lowerbounds |
||
| 39 | ], [ |
||
| 40 | session, |
||
| 41 | Infinity |
||
| 42 | ], false, true).filter(function (item) { |
||
| 43 | return item.event !== 'x-h264-video.data'; |
||
| 44 | }).limit(limit).toArray(); |
||
| 45 | }); |
||
| 46 | }; |
||
| 47 | var listOtherData = function (offset, limit) { |
||
| 48 | return idb.otherdata.where('sessionID').equals(session).offset(offset).limit(limit).toArray(); |
||
| 49 | }; |
||
| 50 | var listOtherData = function (lowerIdLimit, limit) { |
||
|
0 ignored issues
–
show
|
|||
| 51 | return idb.otherdata.get(lowerIdLimit).then(function (lastItem) { |
||
| 52 | var lowerbounds = lastItem !== undefined ? lastItem.timestamp : 0; |
||
| 53 | return idb.otherdata.where('[sessionID+timestamp]').between([ |
||
| 54 | session, |
||
| 55 | lowerbounds |
||
| 56 | ], [ |
||
| 57 | session, |
||
| 58 | Infinity |
||
| 59 | ], false, true).limit(limit).toArray(); |
||
| 60 | }); |
||
| 61 | }; |
||
| 62 | var timedDataGenerator = function (dataRefillFunction, callback, state) { |
||
| 63 | if (state == null) { |
||
|
0 ignored issues
–
show
It is recommended to use
=== to compare with null.
Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator. Loading history...
|
|||
| 64 | state = { |
||
| 65 | buffer: [], |
||
| 66 | dataoffset: 0, |
||
| 67 | timeoffset: null, |
||
| 68 | loadingdata: false |
||
| 69 | }; |
||
| 70 | } |
||
| 71 | if (state.loadingdata) { |
||
| 72 | setTimeout(timedDataGenerator.bind(this, dataRefillFunction, callback, state), 100); |
||
| 73 | return; |
||
| 74 | } |
||
| 75 | var limit = 25; |
||
| 76 | if (state.dataoffset == null) { |
||
|
0 ignored issues
–
show
It is recommended to use
=== to compare with null.
Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator. Loading history...
|
|||
| 77 | state.dataoffset = 0; |
||
| 78 | } |
||
| 79 | if (state.buffer == null) { |
||
|
0 ignored issues
–
show
It is recommended to use
=== to compare with null.
Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator. Loading history...
|
|||
| 80 | state.buffer = []; |
||
| 81 | } |
||
| 82 | if (state.buffer.length < 35) { |
||
| 83 | state.loadingdata = true; |
||
| 84 | dataRefillFunction(state.dataoffset, limit).then(function (newdata) { |
||
| 85 | if (newdata.length>0){ |
||
| 86 | state.buffer = state.buffer.concat(newdata); |
||
| 87 | state.dataoffset = newdata[newdata.length - 1].id; |
||
| 88 | state.loadingdata = false; |
||
| 89 | } |
||
| 90 | if (state.buffer.length == 0){ |
||
|
0 ignored issues
–
show
It is recommended to use
=== to compare with 0.
Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator. Loading history...
|
|||
| 91 | return false; //end generator, no more data |
||
| 92 | } |
||
| 93 | }); |
||
| 94 | } |
||
| 95 | if (state.timeoffset == null && state.buffer.length > 0) { |
||
|
0 ignored issues
–
show
It is recommended to use
=== to compare with null.
Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator. Loading history...
|
|||
| 96 | state.timeoffset = Date.now().valueOf() - state.buffer[0].timestamp; |
||
| 97 | } |
||
| 98 | while (state.buffer.length > 0 && state.buffer[0].timestamp + state.timeoffset < Date.now().valueOf()) { |
||
| 99 | callback(state.buffer.shift()); |
||
| 100 | } |
||
| 101 | //nothing more to play, reschedule next call |
||
| 102 | var nextCheck = 100; |
||
| 103 | if (state.buffer.length > 0) { |
||
| 104 | nextCheck = state.buffer[0].timestamp + state.timeoffset - Date.now().valueOf(); |
||
| 105 | } |
||
| 106 | setTimeout(timedDataGenerator.bind(this, dataRefillFunction, callback, state), nextCheck); |
||
| 107 | }; |
||
| 108 | |||
| 109 | window.OROV.startApp = function(){ |
||
| 110 | |||
| 111 | idb.telemetry_events.where('sessionID').equals(session).filter(function (item) { |
||
| 112 | return item.event == 'x-h264-video.data'; |
||
| 113 | }).first().then(function (initFrame) { |
||
| 114 | if (initFrame !== undefined) { |
||
| 115 | emitter.on('request_Init_Segment', function (callback) { |
||
| 116 | emitter.emit('x-h264-video.init', initFrame.data); |
||
| 117 | if (typeof callback == 'function') { |
||
| 118 | callback(initFrame.data); |
||
| 119 | } |
||
| 120 | }); |
||
| 121 | timedDataGenerator(listMP4Data, function (item) { |
||
| 122 | emitter.emit('x-h264-video.data', item.data); |
||
| 123 | }); |
||
| 124 | emitter.emit('CameraRegistration', { |
||
| 125 | connectionType: 'rov', |
||
| 126 | location: 'forward', |
||
| 127 | videoMimeType: 'video/mp4', |
||
| 128 | relativeServiceUrl: 'localhost' |
||
| 129 | }); |
||
| 130 | } |
||
| 131 | timedDataGenerator(listOtherData, function (item) { |
||
| 132 | emitter.emit.apply(emitter, [item.event].concat(JSON.parse(item.data))); |
||
| 133 | }); |
||
| 134 | timedDataGenerator(listTelemetryData, function (item) { |
||
| 135 | emitter.emit.apply(emitter, [item.event].concat([item.data])); |
||
| 136 | }); |
||
| 137 | }); |
||
| 138 | } |
||
|
0 ignored issues
–
show
There should be a semicolon.
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers. Further Readings: Loading history...
|
|||
| 139 | }); |
||
| 140 | }()); /* |
||
| 141 | idb.mp4.collection.filter(function(item){item.sessionID == session}).first(function(item){ |
||
| 142 | idb.mp4.where("sessionID").equalsIgnoreCase(data[i].sessionID).toArray(function(j,dump){ |
||
| 143 | |||
| 144 | |||
| 145 | }); |
||
| 146 | |||
| 147 | collection.filter(function(item){item.sessionID == session}).first(function(last){ |
||
| 148 | |||
| 149 | }); |
||
| 150 | */ |
||
| 151 | //function (collection,playedindex) |
||
| 152 | // |
||
| 153 | // getNextMsg(palyedidnex) //greater than playedIndex |
||
| 154 | // if nomoremessages, signal done |
||
| 155 | // if (shouldPlay(msg) { |
||
| 156 | // (emit message) |
||
| 157 | // function(collection,message.index); |
||
| 158 | // return; |
||
| 159 | // } |
||
| 160 | // |
||
| 161 | // setTimeout(function(collection,playedindex),delay_until_should_be_played(message.time)) |
||
| 162 | // } |
||
| 163 | //settimeout = to its timestamp corrected for current timestamp |
||
| 164 |