Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add conversationId to transcriptions #12

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ activateTranscriptions({
sentiment: false,
},
},
symblStreamingMessageCallback: (event) => { // optional. If you need it for a custom use case
console.log('event from symbl')
},
});
```

Expand All @@ -61,7 +64,10 @@ activateTranscriptions({
speaker: {
email: '[email protected]',
}
}
},
symblStreamingMessageCallback: (event) => { // optional. If you need it for a custom use case
console.log('event from symbl')
},
});
```

Expand Down
7 changes: 2 additions & 5 deletions demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,20 @@
const init = async () => {
try {
const params = new URLSearchParams(window.location.search);
const roomName = params.get('roomName') || '';
const authToken = params.get('authToken') || '';
const symblAccessToken = params.get('symblAccessToken') || '';

if (!authToken || (roomName && !authToken)) {
alert('Please pass authToken (and roomName, if you are using v1 APIs) in query params');
if (!authToken) {
alert('Please pass authToken in query params');

Check warning on line 19 in demo/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected alert
return;
}
if (!symblAccessToken) {
alert('Please pass symblAccessToken in query params');

Check warning on line 23 in demo/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected alert
return;
}

const meeting = await DyteClient.init({
authToken,
roomName,
apiBase: 'https://api.dyte.io',
defaults: {
audio: false,
video: false,
Expand Down Expand Up @@ -84,7 +81,7 @@
removeTranscriptionsListener({ meeting });
});
} catch (e) {
console.log(e);

Check warning on line 84 in demo/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
}
};

Expand Down
1 change: 1 addition & 0 deletions src/param_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ActivateTranscriptionsConfig {
symblStartRequestParams?: { // https://docs.symbl.ai/reference/streaming-api-reference#start_request
[key:string]: any,
},
symblStreamingMessageCallback?: (event: any) => void,
}

export interface DeactivateTranscriptionsConfig {
Expand Down
15 changes: 15 additions & 0 deletions src/symbl_transcriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import audioTranscriptionMiddleware from './audio_middleware';
import { ActivateTranscriptionsConfig, DeactivateTranscriptionsConfig } from './param_types';
import {
getConversationId,
getPeerIdBySymblId,
getWebSocket,
setConversationId,
setPeerIdForSymblId,
setTranscriptions,
setWebSocket,
Expand All @@ -22,6 +24,7 @@
connectionId,
speakerUserId,
symblStartRequestParams = {},
symblStreamingMessageCallback,
}: ActivateTranscriptionsConfig) {
// As a fail-safe, deactivateTranscriptions if activateTranscriptions function is called twice
// eslint-disable-next-line no-use-before-define
Expand All @@ -37,9 +40,14 @@
ws.onmessage = async (event) => {
const data = JSON.parse(event.data);
if (data.type === 'error') {
console.error('Symbl error: ', data);

Check warning on line 43 in src/symbl_transcriptions.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
return;
}
if (data.type === 'message' && data.message.type === 'conversation_created') {
// console.log('Symbl conversation created: ', data);
setConversationId(data.message.data.conversationId);
}

if (data.type === 'message_response') {
data.messages?.forEach((message: any) => {
// console.log('Live transcript (more accurate): ', message.payload.content, data);
Expand All @@ -56,6 +64,7 @@
peerId: meeting.self.id,
displayName: meeting.self.name,
id: message.id,
conversationId: getConversationId(),
},
);
}
Expand All @@ -80,10 +89,16 @@
endTimeISO: data.message.duration?.endTime || new Date().toISOString(),
peerId: meeting.self.id,
displayName: meeting.self.name,
conversationId: getConversationId(),
},
);
}
}

// Call the callback
if (symblStreamingMessageCallback) {
symblStreamingMessageCallback(data);
}
};

// Fired when the WebSocket closes unexpectedly due to an error or lost connetion
Expand Down
11 changes: 11 additions & 0 deletions src/transcriptions_building_blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { BroadcastMessagePayload } from '@dytesdk/web-core';
let ws: WebSocket;

let transcriptions: BroadcastMessagePayload[] = [];
let conversationId: string = '';

const symblIdToPeerIdMap: {[key: string]: string} = {};

Expand All @@ -29,11 +30,21 @@ function setPeerIdForSymblId(symblId: string, peerId: string) {
symblIdToPeerIdMap[symblId] = peerId;
}

function getConversationId() {
return conversationId;
}

function setConversationId(newConversationId: string) {
conversationId = newConversationId;
}

export {
getWebSocket,
setWebSocket,
getTranscriptions,
setTranscriptions,
getPeerIdBySymblId,
setPeerIdForSymblId,
getConversationId,
setConversationId,
};
Loading