Canonical repo for Dong Web (dong.vielle.dev)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add chromium support:

- replace all calls to .bytes() and .toBase64() with functions which call those methods when avaliable, but fall back to more supported methods for compatiability
- remove unneeded console.log calls (will improve error info later)
- move audio definition to start of class to prevent multiple audio sources

+43 -44
+43 -44
src/pages/index.astro
··· 10 10 } 11 11 } 12 12 13 + const blobBytes = async (blob: Blob) => { 14 + if ("bytes" in blob) return blob.bytes(); 15 + return new Response(blob).arrayBuffer().then((buffer) => { 16 + const uint = new Uint8Array(buffer); 17 + return uint; 18 + }); 19 + }; 20 + 21 + const uint8array64 = (arru8: Uint8Array) => { 22 + if ("toBase64" in arru8) return arru8.toBase64(); 23 + 24 + function _arrayBufferToBase64(bytes: Uint8Array) { 25 + var binary = ""; 26 + var len = bytes.byteLength; 27 + for (var i = 0; i < len; i++) { 28 + binary += String.fromCharCode(bytes[i]); 29 + } 30 + return btoa(binary); 31 + } 32 + return _arrayBufferToBase64(arru8); 33 + }; 34 + 13 35 class CreateDong extends HTMLElement { 14 36 connectedCallback() { 15 37 const shadow = this.attachShadow({ mode: "open" }); ··· 53 75 if (image.type === "" || audio.type === "") 54 76 return console.warn("Mime types invalid"); 55 77 56 - console.log( 57 - image.size, 58 - audio.size, 59 - await image.bytes(), 60 - await audio.bytes() 61 - ); 62 - 63 78 const dongFile = new File( 64 79 [ 65 80 // version ··· 77 92 (() => { 78 93 const value = new Uint32Array(1); 79 94 value[0] = image.size; 80 - console.log("image size: ", image.size, value); 81 95 return value; 82 96 })(), 83 97 // audio type ··· 88 102 (() => { 89 103 const value = new Uint32Array(1); 90 104 value[0] = audio.size; 91 - console.log("audio size: ", audio.size, value); 92 105 return value; 93 106 })(), 94 107 // image data 95 - await image.bytes(), 108 + await blobBytes(image), 96 109 // audio data 97 - await audio.bytes(), 110 + await blobBytes(audio), 98 111 ], 99 112 `${prompt("Filename:") ?? "file"}.dong`, 100 113 { 101 114 type: "application/prs.vielle.dong", 102 115 } 103 - ); 104 - 105 - console.log( 106 - dongFile, 107 - dongFile.size, 108 - await dongFile.text(), 109 - await dongFile.bytes() 110 116 ); 111 117 112 118 // download the dong file ··· 133 139 // image 134 140 const image = document.createElement("img"); 135 141 142 + // do not append as this is only for playing audio 143 + // loaded here to prevent overlaying the sound 144 + const audio = document.createElement("audio"); 145 + 146 + 136 147 dongSelect.type = "file"; 137 148 dongSelect.accept = ".dong"; 138 149 loadButton.type = "submit"; ··· 166 177 // get files 167 178 const dongFile = dongSelect.files[0]; 168 179 169 - console.log(dongFile, dongFile.size); //, await dongFile.bytes()); 170 - 171 180 // get first 2 bytes and verify 172 - const version = new Uint8Array(await dongFile.slice(0, 2).bytes()); 181 + const version = new Uint8Array(await blobBytes(dongFile.slice(0, 2))); 173 182 if (version[0] !== 0xd0 || version[1] !== 2) 174 183 return console.warn("Invalid file"); 175 184 ··· 181 190 182 191 // get next 4 bytes and get image size 183 192 const imgSize = new Uint32Array( 184 - (await dongFile.slice(258, 262).bytes()).buffer 193 + (await blobBytes(dongFile.slice(258, 262))).buffer 185 194 )[0]; 186 195 187 196 // get next 256 bytes and get mime type ··· 192 201 193 202 // get next 4 bytes and get image size 194 203 const audSize = new Uint32Array( 195 - (await dongFile.slice(518, 522).bytes()).buffer 204 + (await blobBytes(dongFile.slice(518, 522))).buffer 196 205 )[0]; 197 206 198 - const imageBytes = await dongFile.slice(522, 522 + imgSize).bytes(); 199 - const audioBytes = await dongFile 200 - .slice(522 + imgSize, 522 + imgSize + audSize) 201 - .bytes(); 207 + const imageBytes = await blobBytes( 208 + dongFile.slice(522, 522 + imgSize) 209 + ); 210 + const audioBytes = await blobBytes( 211 + dongFile.slice(522 + imgSize, 522 + imgSize + audSize) 212 + ); 202 213 203 - image.src = `data:${imgMimeType};base64,${imageBytes.toBase64()}`; 214 + image.src = `data:${imgMimeType};base64,${uint8array64(imageBytes)}`; 204 215 205 216 // audio play 206 - const audio = document.createElement("audio"); 207 - audio.src = `data:${audMimeType};base64,${audioBytes.toBase64()}`; 217 + audio.src = `data:${audMimeType};base64,${uint8array64(audioBytes)}`; 208 218 audio.play(); 209 - 210 - console.log( 211 - imgMimeType, 212 - audMimeType, 213 - imgSize, 214 - audSize, 215 - imageBytes, 216 - audioBytes, 217 - btoa(String.fromCharCode(...imageBytes)), 218 - image, 219 - shadow 220 - ); 221 219 }); 222 220 } 223 221 } ··· 235 233 href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase6400" 236 234 >here</a 237 235 >.) Please use firefox, a gecko based browser, safari, or a webkit based 238 - browser. (iOs has no issues with this site regardless of browser)<br> 239 - Contact me if chrome starts working or you encounter any issues (up to u to figure out how) 236 + browser. (iOs has no issues with this site regardless of browser)<br /> 237 + Contact me if chrome starts working or you encounter any issues (up to u to figure 238 + out how) 240 239 </h1> 241 240 242 241 <create-dong></create-dong>