Skip to content

Commit

Permalink
fix: Lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
icidasset committed Mar 21, 2024
1 parent c3ca661 commit 60488f4
Show file tree
Hide file tree
Showing 6 changed files with 1,502 additions and 994 deletions.
13 changes: 10 additions & 3 deletions examples/audio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,17 @@
"vite-plugin-wasm": "^3.3.0"
},
"eslintConfig": {
"extends": ["@fission-codes"],
"ignorePatterns": ["dist"],
"extends": [
"@fission-codes"
],
"ignorePatterns": [
"dist"
],
"rules": {
"no-console": ["off", "always"]
"no-console": [
"off",
"always"
]
}
}
}
6 changes: 3 additions & 3 deletions examples/audio/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from "@rsbuild/core";
import { defineConfig } from '@rsbuild/core'

export default defineConfig({
html: {
template: "./src/index.html",
template: './src/index.html',
},
});
})
23 changes: 15 additions & 8 deletions examples/audio/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@ import { CID, FileSystem, Path } from '@wnfs-wg/nest'
import * as IDB from 'idb-keyval'
import * as Uint8Arr from 'uint8arrays'

/////////////////
// FILE SYSTEM //
/////////////////
// FILE SYSTEM

/**
*
* @param root0
* @param root0.blockstore
*/
export async function load({
blockstore,
}: {
blockstore: Blockstore
}): Promise<FileSystem> {
const dataRoot = await IDB.get('fs-pointer')
const storedKey = await IDB.get('capsule-key')
const dataRoot: string | undefined = await IDB.get('fs-pointer')
const storedKey: string | undefined = await IDB.get('capsule-key')

const fs =
dataRoot === undefined
? await FileSystem.create({ blockstore })
: await FileSystem.fromCID(CID.parse(dataRoot), { blockstore })

// Create new or load existing private directory at the root
if (dataRoot && storedKey) {
if (dataRoot !== undefined && storedKey !== undefined) {
await fs.mountPrivateNode({
path: Path.root(),
capsuleKey: Uint8Arr.fromString(storedKey, 'base64'),
Expand All @@ -33,14 +36,18 @@ export async function load({
path: Path.root(),
})

IDB.set('capsule-key', Uint8Arr.toString(capsuleKey, 'base64'))
savePointer(await fs.calculateDataRoot())
await IDB.set('capsule-key', Uint8Arr.toString(capsuleKey, 'base64'))
await savePointer(await fs.calculateDataRoot())
}

// Fin
return fs
}

/**
*
* @param dataRoot
*/
export async function savePointer(dataRoot: CID): Promise<void> {
await IDB.set('fs-pointer', dataRoot.toString())
}
82 changes: 67 additions & 15 deletions examples/audio/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const fs = await FS.load({ blockstore })
const state = document.querySelector('#state')
if (state === null) throw new Error('Expected a #state element to exist')

/**
*
* @param msg
*/
function note(msg: string): void {
if (state !== null) state.innerHTML = msg
}
Expand All @@ -50,6 +54,12 @@ if (fi !== null)

// 🎵

/**
*
* @param fileName
* @param mimeType
* @param fileData
*/
async function createAudio(
fileName: string,
mimeType: string,
Expand Down Expand Up @@ -108,21 +118,21 @@ async function createAudio(
// Try to create media source first
let supportsMediaSource = false

// try {
// const { supported } = createMediaSource({
// audioDuration,
// audioFrameCount,
// audioFrameSize,
// fileSize,
// path,
// metadataSize,
// mimeType,
// })

// supportsMediaSource = supported
// } catch (error) {
// console.error('Failed to create media source', error)
// }
try {
const { supported } = createMediaSource({
audioDuration,
audioFrameCount,
audioFrameSize,
fileSize,
path,
metadataSize,
mimeType,
})

supportsMediaSource = supported
} catch (error) {
console.error('Failed to create media source', error)
}

// If that failed, decode the audio via wasm
if (supportsMediaSource) return
Expand All @@ -144,6 +154,10 @@ async function createAudio(

// 🛠️

/**
*
* @param covers
*/
async function mediaInfoClient(covers: boolean): Promise<MediaInfo> {
const MediaInfoFactory = await import('mediainfo.js').then((a) => a.default)

Expand All @@ -161,6 +175,17 @@ async function mediaInfoClient(covers: boolean): Promise<MediaInfo> {
//
// Let the browser decode the audio.

/**
*
* @param root0
* @param root0.audioDuration
* @param root0.audioFrameCount
* @param root0.audioFrameSize
* @param root0.fileSize
* @param root0.metadataSize
* @param root0.mimeType
* @param root0.path
*/
function createMediaSource({
audioDuration,
audioFrameCount,
Expand Down Expand Up @@ -203,6 +228,9 @@ function createMediaSource({
end: 0,
}

/**
*
*/
async function loadNext(): Promise<void> {
if (
src.readyState !== 'open' ||
Expand Down Expand Up @@ -284,6 +312,9 @@ function createMediaSource({
time
)

/**
*
*/
function abortAndRemove(): void {
if (src.readyState === 'open') sourceBuffer.abort()
sourceBuffer.addEventListener('updateend', nextUp, { once: true })
Expand All @@ -302,6 +333,9 @@ function createMediaSource({
abortAndRemove()
}

/**
*
*/
function nextUp(): void {
if (audioDuration !== undefined && !sourceBuffer.updating)
src.duration = audioDuration
Expand Down Expand Up @@ -343,6 +377,18 @@ function createMediaSource({
// ⚠️ This code assumes the audio bytes will be loaded in before
// the current audio segment ends.

/**
*
* @param root0
* @param root0.audioDuration
* @param root0.audioFrameCount
* @param root0.audioFrameSize
* @param root0.fileSize
* @param root0.mediainfo
* @param root0.metadataSize
* @param root0.mimeType
* @param root0.path
*/
async function createWebAudio({
audioDuration,
audioFrameCount,
Expand Down Expand Up @@ -423,6 +469,9 @@ async function createWebAudio({

let loading = false

/**
*
*/
async function loadNext(): Promise<MPEGDecodedAudio | undefined> {
if (loading) return
loading = true
Expand Down Expand Up @@ -503,6 +552,9 @@ async function createWebAudio({
onTimeUpdate().catch(console.error)
})

/**
*
*/
async function onTimeUpdate(): Promise<void> {
if (audio.seeking || buffered.reachedEnd) return
if (audio.currentTime + 60 > buffered.time) {
Expand Down
2 changes: 2 additions & 0 deletions examples/demo/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { IDBBlockstore } from 'blockstore-idb'
import * as uint8arrays from 'uint8arrays'

declare global {
// eslint-disable-next-line no-var
var _fs: FileSystem
// eslint-disable-next-line no-var
var _Path: typeof Path
}

Expand Down
Loading

0 comments on commit 60488f4

Please sign in to comment.