Skip to content

Commit

Permalink
Merge pull request twilio#172 from twilio/feature/2-x-betterments
Browse files Browse the repository at this point in the history
Merge Feature/2 x betterments
  • Loading branch information
charliesantos authored Jun 15, 2023
2 parents 53b5271 + ef47b34 commit dadc02a
Show file tree
Hide file tree
Showing 13 changed files with 1,248 additions and 13,534 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ commands:
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: Installing dependencies
command: node -v && npm install --legacy-peer-deps
command: node -v && npm install
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
Expand Down
2 changes: 1 addition & 1 deletion .circleci/images/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ services:
- /opt/app/node_modules
integrationTests: # runs integration tets. Expects that sources are mounted.
<<: *runtimeDefaults
command: bash -c "npm install --legacy-peer-deps && npm run build && ls -la /root && ls -la /root/.npm && npm run test:network"
command: bash -c "npm install && npm run build && ls -la /root && ls -la /root/.npm && npm run test:network"
bash: # runs bash shell inside container. helpful for debugging
<<: *runtimeDefaults
command: bash
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
Changes
-------

- The SDK now builds on NodeJS versions 16 and above without the `--legacy-peer-deps` flag.
- Removed usage of NodeJS modules from the SDK and some dependencies. With this change, the SDK should now work with some of the latest frameworks that use the latest versions of bundlers such as Vite and Webpack.
- Removed unnecessary files from the generated npm package.
- Links to source maps are now included in the generated npm package.
- The `ws` package has been moved to `devDependencies`.
- The SDK no longer depends on the `xmlhttprequest` npm package.
- Migrated the `AudioPlayer` dependency and is now part of the SDK. This change fixes an issue where source maps are not properly loaded.

2.5.0 (May 9, 2023)
Expand Down
2 changes: 0 additions & 2 deletions browser/ws.js

This file was deleted.

2 changes: 0 additions & 2 deletions browser/xmlhttprequest.js

This file was deleted.

3 changes: 1 addition & 2 deletions lib/twilio/errors/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
/**
* @packageDocumentation
* @module Voice
* @publicapi
* @internal
* @internalapi
*/

/**
Expand Down
28 changes: 8 additions & 20 deletions lib/twilio/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,18 @@
* @internalapi
*/
// @ts-nocheck
import { XMLHttpRequest as XHR } from 'xmlhttprequest';

function request(method, params, callback) {
const options = {};
options.XMLHttpRequest = options.XMLHttpRequest || XHR;
const xhr = new options.XMLHttpRequest();
const body = JSON.stringify(params.body || {});
const headers = new Headers();

xhr.open(method, params.url, true);
xhr.onreadystatechange = function onreadystatechange() {
if (xhr.readyState !== 4) { return; }
params.headers = params.headers || [];
Object.entries(params.headers).forEach(([headerName, headerBody]) =>
headers.append(headerName, headerBody));

if (200 <= xhr.status && xhr.status < 300) {
callback(null, xhr.responseText);
return;
}

callback(new Error(xhr.responseText));
};
// tslint:disable-next-line
for (const headerName in params.headers) {
xhr.setRequestHeader(headerName, params.headers[headerName]);
}

xhr.send(JSON.stringify(params.body));
fetch(params.url, { body, headers, method })
.then(response => response.text(), callback)
.then(responseText => callback(null, responseText), callback);
}
/**
* Use XMLHttpRequest to get a network resource.
Expand Down
9 changes: 5 additions & 4 deletions lib/twilio/statsMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class StatsMonitor extends EventEmitter {
/**
* The setInterval id for fetching samples.
*/
private _sampleInterval: NodeJS.Timer;
private _sampleInterval?: NodeJS.Timer;

/**
* Keeps track of supplemental sample values.
Expand Down Expand Up @@ -232,9 +232,10 @@ class StatsMonitor extends EventEmitter {
* @returns The current {@link StatsMonitor}.
*/
disable(): this {
clearInterval(this._sampleInterval);
delete this._sampleInterval;

if (this._sampleInterval) {
clearInterval(this._sampleInterval);
delete this._sampleInterval;
}
return this;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/twilio/wstransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
*/

import { EventEmitter } from 'events';
import * as WebSocket from 'ws';
import Backoff from './backoff';
import { SignalingErrors } from './errors';
import Log from './log';

const WebSocket = globalThis.WebSocket;

const CONNECT_SUCCESS_TIMEOUT = 10000;
const CONNECT_TIMEOUT = 5000;
const HEARTBEAT_TIMEOUT = 15000;
Expand Down
Loading

0 comments on commit dadc02a

Please sign in to comment.