Server

Manages the connection to the backend server, including Firebase-based authentication and all server-side data operations.

Constructor

new Server(callbacks)

Parameters:
NameTypeDescription
callbacksobjectcallback functions for server connection events
Properties
NameTypeDescription
onStatusChangedfunctionFired whenever `serverStatus` changes.
onConnectfunctionFired after a successful login.
onDisconnectfunctionFired after a successful logout.

Classes

Server

Members

_cachedToken

Cached Firebase ID token — refreshed on each getToken() call

backendUser :object|null

Backend user profile returned by /api/users/me.
Type:
  • object | null

firebaseUser :object|null

Firebase user object — set when signed in via Firebase Auth.
Type:
  • object | null

Methods

audioUrl(id) → {string}

Returns a URL that streams the project's audio. Uses the most recently cached token for
Parameters:
NameTypeDescription
idstringThe project's unique identifier.
Returns:
The audio stream URL.
Type: 
string

(async) checkAudioReady(projectId) → {Promise.<boolean>}

Checks whether audio.mp3 is ready for a project.
Parameters:
NameTypeDescription
projectIdstringThe project's unique identifier.
Returns:
True if audio.mp3 is available.
Type: 
Promise.<boolean>

(async) compressProject(projectId) → {Promise.<object>}

Compresses a project by deleting its original non-MP3 audio file.
Parameters:
NameTypeDescription
projectIdstringThe project's unique identifier.
Returns:
{ ok, audio_format }
Type: 
Promise.<object>

(async) connectLocal() → {Promise.<void>}

Connects to the local embedded server without Firebase authentication. Used in LOCAL_MODE where the backend accepts requests with no token.
Returns:
Type: 
Promise.<void>

(async) connectWithFirebaseUser(serverUrl, firebaseUser) → {Promise.<void>}

Connects to the server using a Firebase-authenticated user. Gets a fresh ID token, verifies backend access via /api/users/me, then fires onConnect.
Parameters:
NameTypeDescription
serverUrlstringBase URL of the server (trailing slash is stripped).
firebaseUserobjectSigned-in Firebase user.
Returns:
Type: 
Promise.<void>

(async) createFolder(parentPath, name) → {Promise.<{name: string, path: string}>}

Creates a new folder on the server.
Parameters:
NameTypeDescription
parentPathstringparent folder path ('' for root)
namestringname for the new folder
Returns:
Type: 
Promise.<{name: string, path: string}>

(async) createProject(metadata, waveformData, audioFile, transcriptFile, sampleFiles, onProgressopt, signalopt) → {Promise.<object>}

Creates a new project on the server.
Parameters:
NameTypeAttributesDescription
metadataobjectProject metadata (name, description, etc.).
waveformDataobjectPre-computed waveform data.
audioFileFile | nullThe audio file to upload, or null to create an empty project.
transcriptFileFileThe transcript CSV file to upload.
sampleFilesArray.<File>Speaker voice sample files to upload.
onProgressfunction<optional>
upload progress callback, fraction 0–1.
signalAbortSignal<optional>
Optional signal to abort the request.
Returns:
The newly created project object.
Type: 
Promise.<object>

(async) deleteAudio(projectId) → {Promise.<void>}

Deletes the audio file for a project.
Parameters:
NameTypeDescription
projectIdstringThe project's unique identifier.
Returns:
Type: 
Promise.<void>

(async) deleteFolder(folderPath, merge) → {Promise.<{ok: boolean}>}

Deletes a folder on the server.
Parameters:
NameTypeDescription
folderPathstringfolder to delete
mergebooleanif true, move contents to parent first
Returns:
Type: 
Promise.<{ok: boolean}>

(async) deleteProject(projectId) → {Promise.<boolean>}

Deletes a project by ID.
Parameters:
NameTypeDescription
projectIdstringThe project's unique identifier.
Returns:
True if deletion was successful.
Type: 
Promise.<boolean>

(async) deleteTranscript(projectId) → {Promise.<void>}

Deletes the transcript for a project.
Parameters:
NameTypeDescription
projectIdstringThe project's unique identifier.
Returns:
Type: 
Promise.<void>

(async) disconnectFromServer()

Signs out of Firebase and resets all connection state.

(async) duplicateProject(projectId, folderPathopt) → {Promise.<object>}

Duplicates a project on the server and returns the new project object.
Parameters:
NameTypeAttributesDescription
projectIdstringThe project's unique identifier.
folderPathstring<optional>
Destination folder path for the duplicate.
Returns:
The newly created duplicate project object.
Type: 
Promise.<object>

(async) getAnnotations(projectId) → {Promise.<object>}

Retrieves the annotations (hyperlinks, etc.) for a project.
Parameters:
NameTypeDescription
projectIdstringThe project's unique identifier.
Returns:
Annotations object with a 'hyperlinks' key.
Type: 
Promise.<object>

(async) getCompressInfo(projectId) → {Promise.<object>}

Returns storage size info for a project before and after compression.
Parameters:
NameTypeDescription
projectIdstringThe project's unique identifier.
Returns:
{ can_compress, before_bytes?, after_bytes?, audio_format?, reason? }
Type: 
Promise.<object>

(async) getFolderCount(folderPath) → {Promise.<{projects: number, folders: number}>}

Gets the count of projects and subfolders within a folder.
Parameters:
NameTypeDescription
folderPathstringfolder to inspect
Returns:
Type: 
Promise.<{projects: number, folders: number}>

(async) getProject(projectId) → {Promise.<object>}

Retrieves a single project by ID.
Parameters:
NameTypeDescription
projectIdstringThe project's unique identifier.
Returns:
The project object.
Type: 
Promise.<object>

(async) getProjectList() → {Promise.<Array.<object>>}

Retrieves the list of all projects from the server.
Returns:
Array of project metadata objects.
Type: 
Promise.<Array.<object>>

(async) getSharedFolders() → {Promise.<Array.<object>>}

Retrieves folders shared with the current user.
Returns:
Array of shared folder metadata objects.
Type: 
Promise.<Array.<object>>

(async) getSharedProjects() → {Promise.<Array.<object>>}

Retrieves projects shared with the current user.
Returns:
Array of shared project metadata objects.
Type: 
Promise.<Array.<object>>

(async) getSpeakerSample(projectId, speakerId) → {Promise.<ArrayBuffer>}

Retrieves a speaker's voice sample as an ArrayBuffer.
Parameters:
NameTypeDescription
projectIdstringThe project's unique identifier.
speakerIdstringThe speaker's unique identifier.
Returns:
The raw audio data.
Type: 
Promise.<ArrayBuffer>

(async) getSpeakers(projectId) → {Promise.<object>}

Retrieves the speakers dictionary for a project.
Parameters:
NameTypeDescription
projectIdstringThe project's unique identifier.
Returns:
Dictionary of speaker objects keyed by speaker id.
Type: 
Promise.<object>

(async) getToken() → {Promise.<(string|null)>}

Returns a fresh Firebase ID token (auto-refreshes if near expiry).
Returns:
Type: 
Promise.<(string|null)>

(async) getTranscript(projectId) → {Promise.<{contentType: string, text: string}>}

Retrieves the transcript for a project.
Parameters:
NameTypeDescription
projectIdstringThe project's unique identifier.
Returns:
The content type and raw text body.
Type: 
Promise.<{contentType: string, text: string}>

(async) getWaveform(projectId) → {Promise.<object>}

Retrieves the waveform data for a project.
Parameters:
NameTypeDescription
projectIdstringThe project's unique identifier.
Returns:
The waveform data object.
Type: 
Promise.<object>

(async) listDirectory(folderPath) → {Promise.<{folders: Array.<object>, projects: Array.<object>}>}

Lists the immediate contents of a server folder.
Parameters:
NameTypeDescription
folderPathstringrelative folder path ('' for root)
Returns:
Type: 
Promise.<{folders: Array.<object>, projects: Array.<object>}>

(async) moveProjectToFolder(projectId, targetFolderPath) → {Promise.<object>}

Moves a project to a different folder.
Parameters:
NameTypeDescription
projectIdstringthe project's unique identifier
targetFolderPathstringdestination folder path ('' for root)
Returns:
updated project summary
Type: 
Promise.<object>

(async) refreshUser() → {Promise.<void>}

Re-fetches /api/users/me and updates backendUser in place. Call this after operations that change storage usage so that subsequent file-size checks use current data.
Returns:
Type: 
Promise.<void>

(async) renameFolder(folderPath, newName) → {Promise.<{name: string, path: string}>}

Renames a folder on the server.
Parameters:
NameTypeDescription
folderPathstringcurrent path of the folder
newNamestringnew name
Returns:
Type: 
Promise.<{name: string, path: string}>

(async) retranscribeSegments(projectId, segments, modelSizeopt) → {Promise.<{results: Array.<{idx: number, words: Array}>}>}

Retranscribes specific time-range segments and returns updated word-level timestamps.
Parameters:
NameTypeAttributesDefaultDescription
projectIdstringThe project ID
segmentsArray.<{start: number, end: number, idx: number}>Segments to retranscribe
modelSizestring<optional>
mediumWhisper model size to use
Returns:
Type: 
Promise.<{results: Array.<{idx: number, words: Array}>}>

sampleUrl(id, spkId) → {string}

Returns a URL for a specific speaker's voice sample file. Uses the most recently cached token for direct link compatibility.
Parameters:
NameTypeDescription
idstringThe project's unique identifier.
spkIdstringThe speaker's unique identifier.
Returns:
The sample file URL.
Type: 
string

(async) saveAnnotations(projectId, data) → {Promise.<void>}

Saves annotations (hyperlinks, etc.) for a project.
Parameters:
NameTypeDescription
projectIdstringThe project's unique identifier.
dataobjectAnnotations object with a 'hyperlinks' key.
Returns:
Type: 
Promise.<void>

(async) saveWaveform(projectId, waveformData) → {Promise.<void>}

Saves waveform metadata (peaks, duration, sampleRate) to the server.
Parameters:
NameTypeDescription
projectIdstringThe project's unique identifier.
waveformDataObjectWaveform peaks and audio metadata.
Returns:
Type: 
Promise.<void>

(async) transcribeProject(projectId, options, onEvent, signalopt) → {Promise.<void>}

Starts transcription and streams progress events via a callback.
Parameters:
NameTypeAttributesDescription
projectIdstringThe project's unique identifier.
optionsobject{ modelSize, speakerCount }
onEventfunctioncalled with each SSE event object
signalAbortSignal<optional>
optional abort signal
Returns:
Type: 
Promise.<void>

transcriptUrl(id) → {string}

Returns the URL to download the project's transcript CSV.
Parameters:
NameTypeDescription
idstringThe project's unique identifier.
Returns:
The transcript download URL.
Type: 
string

(async) updateProject(projectId, metadata, speakersData, audioFile, transcriptFile, sampleFiles, onProgressopt, signalopt) → {Promise.<object>}

Updates an existing project on the server.
Parameters:
NameTypeAttributesDescription
projectIdstringThe project's unique identifier.
metadataobjectUpdated project metadata (name, created, modified).
speakersDataobject | nullFull speakers dict if speakers section is dirty, or null.
audioFileFile | nullReplacement audio file, or null to leave unchanged.
transcriptFileFile | nullReplacement transcript file, or null to leave unchanged.
sampleFilesObject.<string, File>Replacement sample files keyed by speaker id.
onProgressfunction<optional>
upload progress callback, fraction 0–1.
signalAbortSignal<optional>
Optional signal to abort the request.
Returns:
The updated project object.
Type: 
Promise.<object>