Skip to content

Commit e0d92c5

Browse files
committed
remove logger
1 parent e036987 commit e0d92c5

6 files changed

Lines changed: 367 additions & 260 deletions

File tree

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
"type": "module",
55
"module": "src/index.ts",
66
"scripts": {
7-
"dev": "doppler run -- bun --watch src/index.ts",
8-
"dev:local": "bun --watch src/index.ts",
7+
"dev": "bun run kill-ports && doppler run -- bun --watch src/index.ts",
8+
"dev:local": "bun run kill-ports && bun --watch src/index.ts",
9+
"kill-ports": "lsof -ti:8069,8070 | xargs kill -9 2>/dev/null || true",
910
"build:webview": "bun run build.ts",
1011
"start": "doppler run -- bun run build:webview && doppler run -- bun src/index.ts",
1112
"start:local": "bun run build:webview && bun src/index.ts",
1213
"ngrok": "ngrok http --url=isaiah-tpa.ngrok.app 8069",
1314
"doppler:setup": "doppler setup"
1415
},
1516
"dependencies": {
16-
"@mentra/sdk": "^2.1.29-beta.2",
17+
"@mentra/sdk": "^2.1.31-beta.4",
1718
"@mentra/react": "^0.2.0",
1819
"@aws-sdk/client-s3": "^3.812.0",
1920
"@radix-ui/react-dialog": "^1.1.6",

src/services/recordings.service.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -438,22 +438,16 @@ class RecordingsService {
438438
// Register this as an active session
439439
registerActiveSession(userId);
440440

441-
// Set up handlers for audio chunks
442-
// IMPORTANT: This handler is intentionally synchronous for the critical path
443-
// to ensure chunks are queued in arrival order
444-
session.events.onAudioChunk((chunk: AudioChunk) => {
445-
// Fast, synchronous cache lookup
446-
const cached = this.getCachedActiveRecording(userId);
447-
448-
if (cached) {
449-
// Fast, synchronous queue push
450-
this.enqueueChunk(cached.recordingId, chunk.arrayBuffer as ArrayBuffer);
451-
}
452-
});
453-
454-
// Set up handlers for transcription
441+
// IMPORTANT: Set up transcription handler FIRST, then audio handler.
442+
// This fixes a race condition in the SDK where subscription updates are sent
443+
// as each handler is added. By setting up transcription first, we ensure
444+
// the final subscription state includes both audio_chunk AND transcription.
445+
// If audio is set up first, there's a timing issue where a subsequent
446+
// subscription update can accidentally drop the transcription subscription.
447+
448+
// Set up handlers for transcription (MUST be before audio handler)
455449
try {
456-
session.onTranscriptionForLanguage(
450+
session.events.onTranscriptionForLanguage(
457451
"en-US",
458452
async (transcription: TranscriptionData) => {
459453
console.log(
@@ -627,6 +621,22 @@ class RecordingsService {
627621
} catch (error) {
628622
console.error("Error setting up transcription handler:", error);
629623
}
624+
625+
// Set up handlers for audio chunks (AFTER transcription handler)
626+
// IMPORTANT: This handler is intentionally synchronous for the critical path
627+
// to ensure chunks are queued in arrival order
628+
session.events.onAudioChunk((chunk: AudioChunk) => {
629+
// Fast, synchronous cache lookup
630+
const cached = this.getCachedActiveRecording(userId);
631+
632+
if (cached) {
633+
// Fast, synchronous queue push
634+
this.enqueueChunk(cached.recordingId, chunk.arrayBuffer as ArrayBuffer);
635+
}
636+
});
637+
console.log(
638+
`[TPA SESSION] ✅ Handlers registered for user ${userId} (transcription + audio)`,
639+
);
630640
}
631641

632642
/**

src/webview/Api.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import axios from "axios";
66
import { RecordingI } from "./types";
7-
import logger from "./utils/remoteLogger";
87

98
/**
109
* Check if we're in development mode
@@ -56,17 +55,17 @@ const axiosInstance = axios.create({
5655
// Add response interceptor for debugging
5756
axiosInstance.interceptors.response.use(
5857
(response) => {
59-
logger.debug(
58+
console.debug(
6059
`[API] Response ${response.config.method?.toUpperCase()} ${response.config.url} - Status: ${response.status}`,
6160
);
6261
return response;
6362
},
6463
(error) => {
6564
if (axios.isAxiosError(error)) {
66-
logger.error(
65+
console.error(
6766
`[API] Error ${error.config?.method?.toUpperCase()} ${error.config?.url} - Status: ${error.response?.status}`,
6867
);
69-
logger.error("[API] Error response:", error.response?.data);
68+
console.error("[API] Error response:", error.response?.data);
7069
}
7170
return Promise.reject(error);
7271
},
@@ -120,8 +119,8 @@ const api = {
120119
},
121120

122121
startRecording: async (sessionId: string): Promise<string> => {
123-
logger.log(`[API] Starting recording with sessionId: ${sessionId}`);
124-
logger.log("[API] Auth headers:", JSON.stringify(getAuthHeader()));
122+
console.log(`[API] Starting recording with sessionId: ${sessionId}`);
123+
console.log("[API] Auth headers:", JSON.stringify(getAuthHeader()));
125124

126125
try {
127126
const response = await axiosInstance.post(
@@ -132,16 +131,16 @@ const api = {
132131
},
133132
);
134133

135-
logger.log(`[API] Start recording response status: ${response.status}`);
136-
logger.log(`[API] Start recording response data:`, response.data);
134+
console.log(`[API] Start recording response status: ${response.status}`);
135+
console.log(`[API] Start recording response data:`, response.data);
137136

138137
return response.data.id;
139138
} catch (error) {
140-
logger.error("[API] Start recording request failed:", error);
139+
console.error("[API] Start recording request failed:", error);
141140
if (axios.isAxiosError(error)) {
142-
logger.error("[API] Response status:", error.response?.status);
143-
logger.error("[API] Response data:", error.response?.data);
144-
logger.error("[API] Response headers:", error.response?.headers);
141+
console.error("[API] Response status:", error.response?.status);
142+
console.error("[API] Response data:", error.response?.data);
143+
console.error("[API] Response headers:", error.response?.headers);
145144
}
146145
throw error;
147146
}

src/webview/App.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import PlaybackImproved from "./screens/PlaybackImproved/PlaybackImproved";
66
import { useRecordings } from "./hooks/useRecordings";
77
import { RecordingI } from "./types/recording";
88
import api, { setFrontendToken, getBackendUrl } from "./Api";
9-
import logger from "./utils/remoteLogger";
109

1110
/**
1211
* Check if we're in development mode
@@ -184,14 +183,14 @@ const App: React.FC = () => {
184183

185184
const handleStartRecording = async () => {
186185
try {
187-
logger.log("[APP] handleStartRecording called from App.tsx");
186+
console.log("[APP] handleStartRecording called from App.tsx");
188187
const recordingId = await startRecording();
189-
logger.log("[APP] Recording started successfully with ID:", recordingId);
188+
console.log("[APP] Recording started successfully with ID:", recordingId);
190189
return recordingId;
191190
} catch (error) {
192-
logger.error("[APP] Failed to start recording:", error);
193-
logger.error("[APP] Error type:", typeof error);
194-
logger.error(
191+
console.error("[APP] Failed to start recording:", error);
192+
console.error("[APP] Error type:", typeof error);
193+
console.error(
195194
"[APP] Error message:",
196195
error instanceof Error ? error.message : String(error),
197196
);

src/webview/hooks/useRecordings.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { useState, useEffect, useCallback, useRef } from "react";
66
import api from "../Api";
77
import { RecordingI, RecordingStatusE } from "../types/recording";
88
import { useRealTimeEvents } from "./useRealTimeEvents";
9-
import logger from "../utils/remoteLogger";
109

1110
export interface UseRecordingsOptions {
1211
autoRefresh?: boolean;
@@ -130,41 +129,41 @@ export function useRecordings(options: UseRecordingsOptions = {}) {
130129
const startRecording = useCallback(async (): Promise<string> => {
131130
// Prevent multiple simultaneous start attempts
132131
if (startingRecording.current) {
133-
logger.warn(
132+
console.warn(
134133
"[useRecordings] Already starting a recording, skipping duplicate attempt",
135134
);
136135
throw new Error("Already starting a recording");
137136
}
138137

139-
logger.log("[useRecordings] Setting startingRecording flag to true");
138+
console.log("[useRecordings] Setting startingRecording flag to true");
140139
startingRecording.current = true;
141140

142141
try {
143142
// Check session status first
144-
logger.log(
143+
console.log(
145144
"[useRecordings] Checking session status before starting recording",
146145
);
147146
const isConnected = await checkSessionStatus();
148147
if (!isConnected) {
149-
logger.error("[useRecordings] No active session, throwing error");
148+
console.error("[useRecordings] No active session, throwing error");
150149
throw new Error(
151150
"No active AugmentOS SDK session. Please ensure your glasses are connected.",
152151
);
153152
}
154153

155154
const sessionId = `session_${Date.now()}`;
156-
logger.log(
155+
console.log(
157156
`[useRecordings] Making API call to start recording with sessionId: ${sessionId}`,
158157
);
159158
const recordingId = await api.recordings.startRecording(sessionId);
160-
logger.log(
159+
console.log(
161160
`[useRecordings] Recording started successfully with ID: ${recordingId}`,
162161
);
163162
return recordingId;
164163
} catch (err) {
165-
logger.error("[useRecordings] Error starting recording:", err);
166-
logger.error("[useRecordings] Error type:", typeof err);
167-
logger.error(
164+
console.error("[useRecordings] Error starting recording:", err);
165+
console.error("[useRecordings] Error type:", typeof err);
166+
console.error(
168167
"[useRecordings] Error message:",
169168
err instanceof Error ? err.message : String(err),
170169
);
@@ -182,7 +181,7 @@ export function useRecordings(options: UseRecordingsOptions = {}) {
182181
err instanceof Error &&
183182
err.message.includes("already has an active recording")
184183
) {
185-
logger.warn(
184+
console.warn(
186185
"[useRecordings] User already has an active recording, not setting general error state",
187186
);
188187
throw err; // Still throw so caller can handle it
@@ -193,7 +192,7 @@ export function useRecordings(options: UseRecordingsOptions = {}) {
193192
);
194193
throw err;
195194
} finally {
196-
logger.log("[useRecordings] Setting startingRecording flag to false");
195+
console.log("[useRecordings] Setting startingRecording flag to false");
197196
startingRecording.current = false;
198197
}
199198
}, [checkSessionStatus]);

0 commit comments

Comments
 (0)