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

restart websocket through session id #8

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Vocode React SDK

See our [React Quickstart](https://docs.vocode.dev/react-quickstart) for set up!

## Invalid Hook Call

You might have more than one copy of React in the same app when using React Hooks and NPM Link together.

Our solution
```
npm_link.sh
```

Refer link:
- [Invalid Hook Call Warning](https://legacy.reactjs.org/warnings/invalid-hook-call-warning.html)
- [Solving the problem with NPM Link and React Hooks](https://medium.com/bbc-product-technology/solving-the-problem-with-npm-link-and-react-hooks-266c832dd019)
19 changes: 19 additions & 0 deletions npm_link.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
WEBAPP_PATH=$PWD/../vocode-react-demo

rm -rf node_modules/react-dom
rm -rf node_modules/react
rm -rf node_modules/@types/react-dom
rm -rf node_modules/@types/react
rm -rf node_modules/@types/node

ln -s $WEBAPP_PATH/node_modules/react-dom node_modules/react-dom
ln -s $WEBAPP_PATH/node_modules/react node_modules/react
ln -s $WEBAPP_PATH/node_modules/@types/react-dom node_modules/@types/react-dom
ln -s $WEBAPP_PATH/node_modules/@types/react node_modules/@types/react
ln -s $WEBAPP_PATH/node_modules/@types/node node_modules/@types/node

ls -ld node_modules/react-dom
ls -ld node_modules/react
ls -ld node_modules/@types/react-dom
ls -ld node_modules/@types/react
ls -ld node_modules/@types/node
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"author": "Ajay Raj <[email protected]>",
"license": "MIT",
"devDependencies": {
"@types/uuid": "^9.0.1",
"typescript": "^4.9.5"
},
"dependencies": {
Expand Down
15 changes: 13 additions & 2 deletions src/hooks/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { DeepgramTranscriberConfig, TranscriberConfig } from "../types";
import { isSafari, isChrome } from "react-device-detect";
import { Buffer } from "buffer";
import { v4 as uuidv4 } from "uuid"

const VOCODE_API_URL = "api.vocode.dev";
const DEFAULT_CHUNK_SIZE = 2048;
Expand Down Expand Up @@ -173,7 +174,7 @@ export const useConversation = (
outputAudioMetadata: { samplingRate: number; audioEncoding: AudioEncoding },
chunkSize: number | undefined,
downsampling: number | undefined,
conversationId: string | undefined
conversationId: string | undefined,
): AudioConfigStartMessage => ({
type: "websocket_audio_config_start",
inputAudioConfig: {
Expand Down Expand Up @@ -293,17 +294,27 @@ export const useConversation = (
} else {
const selfHostedConversationConfig =
config as SelfHostedConversationConfig;
let conversationId = selfHostedConversationConfig.conversationId;
if (!conversationId) {
let sessionId = sessionStorage.getItem("sessionId");
if (sessionId == undefined) {
sessionId = uuidv4();
sessionStorage.setItem("sessionId", sessionId);
}
conversationId = sessionId;
}
startMessage = getAudioConfigStartMessage(
inputAudioMetadata,
outputAudioMetadata,
selfHostedConversationConfig.chunkSize,
selfHostedConversationConfig.downsampling,
selfHostedConversationConfig.conversationId
conversationId,
);
}

socket.send(stringify(startMessage));
console.log("Access to microphone granted");
console.log(startMessage);

let recorderToUse = recorder;
if (recorderToUse && recorderToUse.state === "paused") {
Expand Down