Skip to content

Commit

Permalink
fix(voice): Fixed response types on file downloads (#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonmantank authored Sep 8, 2023
1 parent 3f94c41 commit 0446638
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
node-version: ${{ matrix.node }}

- name: Install typescript
run: npm install -g typescript npm${{ matrix.npm_version }}
run: npm install -g typescript

- name: Install packages
run: npm install
Expand Down
1 change: 0 additions & 1 deletion packages/proactive-connect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"dependencies": {
"@vonage/server-client": "^1.8.1",
"@vonage/vetch": "1.5.0",
"form-data": "^4.0.0",
"lodash.pick": "^4.4.0"
},
Expand Down
4 changes: 3 additions & 1 deletion packages/server-client/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
VetchResponse,
VetchOptions,
HTTPMethods,
Vetch,
} from '@vonage/vetch';
import { AuthenticationType } from './enums/AuthenticationType';
import * as transfomers from './transformers';
Expand Down Expand Up @@ -174,7 +175,8 @@ export abstract class Client {
): Promise<VetchResponse<T>> {
request.timeout = this.config.timeout;
request = await this.addAuthenticationToRequest(request);
const result = await vetchRequest<T>(request);
const vetch = new Vetch(this.config);
const result = await vetch.request<T>(request);
return result;
}
}
3 changes: 2 additions & 1 deletion packages/server-client/lib/types/ConfigParams.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ResponseTypes } from '@vonage/vetch';
export type ConfigParams = {
restHost?: string;
apiHost?: string;
videoHost?: string;
responseType?: string;
responseType?: ResponseTypes;
timeout?: number;
proactiveHost?: string;
meetingsHost?: string;
Expand Down
4 changes: 3 additions & 1 deletion packages/vetch/lib/enums/responseTypes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export enum ResponseTypes {
json = 'json',
json = 'json',
stream = 'stream',
text = 'text',
}
2 changes: 2 additions & 0 deletions packages/vetch/lib/vetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export class Vetch {
res: fetchResponse,
): Promise<any> {
switch (opts.responseType) {
case 'stream':
return res.buffer();
case 'json': {
let data = await res.text();
try {
Expand Down
13 changes: 12 additions & 1 deletion packages/voice/lib/voice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from './types/index';

import { CallListFilter } from './types';
import { ResponseTypes } from '@vonage/vetch';

const apiCallsToCalls = (call: CallDetailResponse): CallDetail => {
delete call._links;
Expand Down Expand Up @@ -177,8 +178,18 @@ export class Voice extends Client {
}

async downloadRecording(file: string, path: string): Promise<void> {
const client = new FileClient(this.auth, this.config);
const config = this.config;
config.responseType = ResponseTypes.stream;

const client = new FileClient(this.auth, config);
return await client.downloadFile(file, path);
}

async downloadTranscription(file: string, path: string): Promise<void> {
const config = this.config;
config.responseType = ResponseTypes.text;

const client = new FileClient(this.auth, config);
return await client.downloadFile(file, path);
}

Expand Down

0 comments on commit 0446638

Please sign in to comment.