Mercurial > hg > webaudioevaluationtool
comparison core.js @ 2147:0eeb17318f7e
Adding PHP Keygen
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Tue, 08 Mar 2016 14:35:51 +0000 |
parents | bcc677a7c759 |
children | 879b0b20b20c |
comparison
equal
deleted
inserted
replaced
2146:14a3089443b6 | 2147:0eeb17318f7e |
---|---|
164 function loadProjectSpecCallback(response) { | 164 function loadProjectSpecCallback(response) { |
165 // Function called after asynchronous download of XML project specification | 165 // Function called after asynchronous download of XML project specification |
166 //var decode = $.parseXML(response); | 166 //var decode = $.parseXML(response); |
167 //projectXML = $(decode); | 167 //projectXML = $(decode); |
168 | 168 |
169 // First perform XML schema validation | 169 // Check if XML is new or a resumption |
170 var Module = { | 170 var parse = new DOMParser(); |
171 xml: response, | 171 var responseDocument = parse.parseFromString(response,'text/xml'); |
172 schema: schemaXSD, | 172 var errorNode = responseDocument.getElementsByTagName('parsererror'); |
173 arguments:["--noout", "--schema", 'test-schema.xsd','document.xml'] | |
174 }; | |
175 | |
176 var xmllint = validateXML(Module); | |
177 console.log(xmllint); | |
178 if(xmllint != 'document.xml validates\n') | |
179 { | |
180 document.getElementsByTagName('body')[0].innerHTML = null; | |
181 var msg = document.createElement("h3"); | |
182 msg.textContent = "FATAL ERROR"; | |
183 var span = document.createElement("h4"); | |
184 span.textContent = "The XML validator returned the following errors when decoding your XML file"; | |
185 document.getElementsByTagName('body')[0].appendChild(msg); | |
186 document.getElementsByTagName('body')[0].appendChild(span); | |
187 xmllint = xmllint.split('\n'); | |
188 for (var i in xmllint) | |
189 { | |
190 document.getElementsByTagName('body')[0].appendChild(document.createElement('br')); | |
191 var span = document.createElement("span"); | |
192 span.textContent = xmllint[i]; | |
193 document.getElementsByTagName('body')[0].appendChild(span); | |
194 } | |
195 return; | |
196 } | |
197 | |
198 var parse = new DOMParser(); | |
199 projectXML = parse.parseFromString(response,'text/xml'); | |
200 var errorNode = projectXML.getElementsByTagName('parsererror'); | |
201 if (errorNode.length >= 1) | 173 if (errorNode.length >= 1) |
202 { | 174 { |
203 var msg = document.createElement("h3"); | 175 var msg = document.createElement("h3"); |
204 msg.textContent = "FATAL ERROR"; | 176 msg.textContent = "FATAL ERROR"; |
205 var span = document.createElement("span"); | 177 var span = document.createElement("span"); |
208 document.getElementsByTagName('body')[0].appendChild(msg); | 180 document.getElementsByTagName('body')[0].appendChild(msg); |
209 document.getElementsByTagName('body')[0].appendChild(span); | 181 document.getElementsByTagName('body')[0].appendChild(span); |
210 document.getElementsByTagName('body')[0].appendChild(errorNode[0]); | 182 document.getElementsByTagName('body')[0].appendChild(errorNode[0]); |
211 return; | 183 return; |
212 } | 184 } |
185 if (responseDocument.children[0].nodeName == "waet") { | |
186 // document is a specification | |
187 | |
188 // Perform XML schema validation | |
189 var Module = { | |
190 xml: response, | |
191 schema: schemaXSD, | |
192 arguments:["--noout", "--schema", 'test-schema.xsd','document.xml'] | |
193 }; | |
194 projectXML = responseDocument; | |
195 var xmllint = validateXML(Module); | |
196 console.log(xmllint); | |
197 if(xmllint != 'document.xml validates\n') | |
198 { | |
199 document.getElementsByTagName('body')[0].innerHTML = null; | |
200 var msg = document.createElement("h3"); | |
201 msg.textContent = "FATAL ERROR"; | |
202 var span = document.createElement("h4"); | |
203 span.textContent = "The XML validator returned the following errors when decoding your XML file"; | |
204 document.getElementsByTagName('body')[0].appendChild(msg); | |
205 document.getElementsByTagName('body')[0].appendChild(span); | |
206 xmllint = xmllint.split('\n'); | |
207 for (var i in xmllint) | |
208 { | |
209 document.getElementsByTagName('body')[0].appendChild(document.createElement('br')); | |
210 var span = document.createElement("span"); | |
211 span.textContent = xmllint[i]; | |
212 document.getElementsByTagName('body')[0].appendChild(span); | |
213 } | |
214 return; | |
215 } | |
216 | |
217 // Generate the session-key | |
218 storage.initialise(); | |
219 | |
220 } else if (responseDocument.children[0].nodeName == "waetresult") { | |
221 // document is a result | |
222 projectXML = responseDocument.getElementsByTagName('waet')[0]; | |
223 // Use the session-key | |
224 var sessionKey = responseDocument.children[0].getAttribute(key); | |
225 storage.initialise(sessionKey); | |
226 } | |
213 | 227 |
214 // Build the specification | 228 // Build the specification |
215 specification.decode(projectXML); | 229 specification.decode(projectXML); |
216 storage.initialise(); | |
217 /// CHECK FOR SAMPLE RATE COMPATIBILITY | 230 /// CHECK FOR SAMPLE RATE COMPATIBILITY |
218 if (specification.sampleRate != undefined) { | 231 if (specification.sampleRate != undefined) { |
219 if (Number(specification.sampleRate) != audioContext.sampleRate) { | 232 if (Number(specification.sampleRate) != audioContext.sampleRate) { |
220 var errStr = 'Sample rates do not match! Requested '+Number(specification.sampleRate)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.'; | 233 var errStr = 'Sample rates do not match! Requested '+Number(specification.sampleRate)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.'; |
221 alert(errStr); | 234 alert(errStr); |
428 } | 441 } |
429 | 442 |
430 function decibelToLinear(gain) | 443 function decibelToLinear(gain) |
431 { | 444 { |
432 return Math.pow(10,gain/20.0); | 445 return Math.pow(10,gain/20.0); |
446 } | |
447 | |
448 function randomString(length) { | |
449 return Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, length))).toString(36).slice(1); | |
433 } | 450 } |
434 | 451 |
435 function interfacePopup() { | 452 function interfacePopup() { |
436 // Creates an object to manage the popup | 453 // Creates an object to manage the popup |
437 this.popup = null; | 454 this.popup = null; |
3095 this.testPages = []; | 3112 this.testPages = []; |
3096 this.document = document.implementation.createDocument(null,"waetresult"); | 3113 this.document = document.implementation.createDocument(null,"waetresult"); |
3097 this.root = this.document.childNodes[0]; | 3114 this.root = this.document.childNodes[0]; |
3098 this.state = 0; | 3115 this.state = 0; |
3099 | 3116 |
3100 this.initialise = function() | 3117 this.initialise = function(sessionKey) |
3101 { | 3118 { |
3102 if (specification.preTest != undefined){this.globalPreTest = new this.surveyNode(this,this.root,specification.preTest);} | 3119 if (specification.preTest != undefined){this.globalPreTest = new this.surveyNode(this,this.root,specification.preTest);} |
3103 if (specification.postTest != undefined){this.globalPostTest = new this.surveyNode(this,this.root,specification.postTest);} | 3120 if (specification.postTest != undefined){this.globalPostTest = new this.surveyNode(this,this.root,specification.postTest);} |
3104 }; | 3121 if (sessionKey == undefined) { |
3122 // We need to get the sessionKey | |
3123 this.SessionKey.generateKey(); | |
3124 } else { | |
3125 this.SessionKey.key = sessionKey; | |
3126 } | |
3127 }; | |
3128 | |
3129 this.SessionKey = { | |
3130 key: null, | |
3131 request: new XMLHttpRequest(), | |
3132 parent: this, | |
3133 handleEvent: function() { | |
3134 var parse = new DOMParser(); | |
3135 var xml = parse.parseFromString(this.request.response,"text/xml"); | |
3136 if (xml.getAllElementsByTagName("state")[0].textContent == "OK") { | |
3137 this.key = xml.getAllElementsByTagName("key")[0].textContent; | |
3138 } else { | |
3139 this.generateKey(); | |
3140 } | |
3141 }, | |
3142 generateKey: function() { | |
3143 var temp_key = randomString(32); | |
3144 this.request.open("GET","keygen.php?key="+temp_key,true); | |
3145 this.request.addEventListener("load",this); | |
3146 this.request.send(); | |
3147 } | |
3148 } | |
3105 | 3149 |
3106 this.createTestPageStore = function(specification) | 3150 this.createTestPageStore = function(specification) |
3107 { | 3151 { |
3108 var store = new this.pageNode(this,specification); | 3152 var store = new this.pageNode(this,specification); |
3109 this.testPages.push(store); | 3153 this.testPages.push(store); |