UNPKG

odyssey-spatial-comms

Version:

Drop-in replacement for Dolby/Voxeet SDK using Odyssey Spatial Audio Service

50 lines 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SessionAPI = void 0; const events_1 = require("events"); class SessionAPI extends events_1.EventEmitter { constructor(apiClient) { super(); this.currentParticipant = null; this.apiClient = apiClient; // Set up bidirectional reference for session context this.apiClient.session = this; } get participant() { return this.currentParticipant; } async open(participantInfo) { if (!this.apiClient.getAccessToken()) { throw new Error('SDK not initialized. Call initializeToken() first.'); } try { const response = await this.apiClient.post('/api/session/open', participantInfo); // Ensure participant has externalId for session context this.currentParticipant = Object.assign(Object.assign(Object.assign({}, participantInfo), (response.data || response)), { externalId: participantInfo.externalId }); this.emit('sessionOpened', this.currentParticipant); return this.currentParticipant; } catch (error) { console.error('SPATIAL-AUDIO: Session open failed with detailed error:', error); throw error; // Re-throw original error to preserve details } } async close() { if (!this.apiClient.getAccessToken() || !this.currentParticipant) { return; } try { await this.apiClient.post('/api/session/close', {}); this.currentParticipant = null; this.emit('sessionClosed'); } catch (error) { throw new Error(`Session close failed: ${error.message}`); } } isOpen() { return this.currentParticipant !== null; } } exports.SessionAPI = SessionAPI; //# sourceMappingURL=session.js.map