From 8522ce4fb0e68d68c0075b7d1c3f4be15fd9e805 Mon Sep 17 00:00:00 2001 From: Madhu Date: Wed, 3 Jan 2024 15:33:02 +0530 Subject: [PATCH 1/3] fix: add conversationId to transcriptions --- demo/index.ts | 7 ++----- src/param_types.ts | 1 + src/symbl_transcriptions.ts | 15 +++++++++++++++ src/transcriptions_building_blocks.ts | 11 +++++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/demo/index.ts b/demo/index.ts index 208f1e9..14ef009 100644 --- a/demo/index.ts +++ b/demo/index.ts @@ -12,12 +12,11 @@ defineCustomElements(); 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'); return; } if (!symblAccessToken) { @@ -27,8 +26,6 @@ const init = async () => { const meeting = await DyteClient.init({ authToken, - roomName, - apiBase: 'https://api.dyte.io', defaults: { audio: false, video: false, diff --git a/src/param_types.ts b/src/param_types.ts index 1e9ba53..32648ea 100644 --- a/src/param_types.ts +++ b/src/param_types.ts @@ -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 { diff --git a/src/symbl_transcriptions.ts b/src/symbl_transcriptions.ts index 8573e0a..680a02c 100644 --- a/src/symbl_transcriptions.ts +++ b/src/symbl_transcriptions.ts @@ -2,8 +2,10 @@ import merge from 'lodash-es/merge'; import audioTranscriptionMiddleware from './audio_middleware'; import { ActivateTranscriptionsConfig, DeactivateTranscriptionsConfig } from './param_types'; import { + getConversationId, getPeerIdBySymblId, getWebSocket, + setConversationId, setPeerIdForSymblId, setTranscriptions, setWebSocket, @@ -22,6 +24,7 @@ async function activateTranscriptions({ connectionId, speakerUserId, symblStartRequestParams = {}, + symblStreamingMessageCallback = () => {}, }: ActivateTranscriptionsConfig) { // As a fail-safe, deactivateTranscriptions if activateTranscriptions function is called twice // eslint-disable-next-line no-use-before-define @@ -40,6 +43,11 @@ async function activateTranscriptions({ console.error('Symbl error: ', data); 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); @@ -56,6 +64,7 @@ async function activateTranscriptions({ peerId: meeting.self.id, displayName: meeting.self.name, id: message.id, + conversationId: getConversationId(), }, ); } @@ -80,10 +89,16 @@ async function activateTranscriptions({ 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 diff --git a/src/transcriptions_building_blocks.ts b/src/transcriptions_building_blocks.ts index 1320771..68fc667 100644 --- a/src/transcriptions_building_blocks.ts +++ b/src/transcriptions_building_blocks.ts @@ -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} = {}; @@ -29,6 +30,14 @@ function setPeerIdForSymblId(symblId: string, peerId: string) { symblIdToPeerIdMap[symblId] = peerId; } +function getConversationId() { + return conversationId; +} + +function setConversationId(newConversationId: string) { + conversationId = newConversationId; +} + export { getWebSocket, setWebSocket, @@ -36,4 +45,6 @@ export { setTranscriptions, getPeerIdBySymblId, setPeerIdForSymblId, + getConversationId, + setConversationId, }; From 8399ee6aae424c6dfb9f47e41f04e3a1a0b95d23 Mon Sep 17 00:00:00 2001 From: Madhu Date: Wed, 3 Jan 2024 15:36:53 +0530 Subject: [PATCH 2/3] fix: add docs --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e17990e..ce58747 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,9 @@ activateTranscriptions({ sentiment: false, }, }, + symblStreamingMessageCallback: (event) => { // optional. If you need it for a custom use case + console.log('event from symbl') + }, }); ``` @@ -61,7 +64,10 @@ activateTranscriptions({ speaker: { email: 'test@test.com', } - } + }, + symblStreamingMessageCallback: (event) => { // optional. If you need it for a custom use case + console.log('event from symbl') + }, }); ``` From ee3af8166ede777a6386c28a4b57fa8299bd2068 Mon Sep 17 00:00:00 2001 From: Madhu Date: Wed, 3 Jan 2024 15:39:52 +0530 Subject: [PATCH 3/3] fix: do not set a default parameter --- src/symbl_transcriptions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/symbl_transcriptions.ts b/src/symbl_transcriptions.ts index 680a02c..eb3a63f 100644 --- a/src/symbl_transcriptions.ts +++ b/src/symbl_transcriptions.ts @@ -24,7 +24,7 @@ async function activateTranscriptions({ connectionId, speakerUserId, symblStartRequestParams = {}, - symblStreamingMessageCallback = () => {}, + symblStreamingMessageCallback, }: ActivateTranscriptionsConfig) { // As a fail-safe, deactivateTranscriptions if activateTranscriptions function is called twice // eslint-disable-next-line no-use-before-define