Skip to content

Commit

Permalink
2.18.3 Release prep (#1674)
Browse files Browse the repository at this point in the history
* VIDEO 3600 7831 | Merging CancelablePromise fix and audioLevel fix (#1670)

* VIDEO-7831 Fix Connect to return CancelablePromise on Type Definitions (#1648)

* VIDEO-7831 Fixing return type on connect and implementing finally on CancelablePromise

Co-authored-by: joma <joma@twilio.com>

* Fixing merge conflicts

* VIDEO-3600 | Using twilio-webrtc.js 4.5.2-rc1

Co-authored-by: Joyce Ma <43423318+PikaJoyce@users.noreply.github.com>
Co-authored-by: joma <joma@twilio.com>

* 2.18.3-rc1

* 2.18.3-dev

* Remove .only (#1673)

Co-authored-by: joma <joma@twilio.com>

* Prep for 2.18.3 release

Co-authored-by: Joyce Ma <43423318+PikaJoyce@users.noreply.github.com>
Co-authored-by: joma <joma@twilio.com>
Co-authored-by: twilio-ci <twilio-ci@twilio.com>
  • Loading branch information
4 people authored Jan 4, 2022
1 parent 778e004 commit 7a5c045
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ The Twilio Programmable Video SDKs use [Semantic Versioning](http://www.semver.o

**Version 1.x reached End of Life on September 8th, 2021.** See the changelog entry [here](https://www.twilio.com/changelog/end-of-life-complete-for-unsupported-versions-of-the-programmable-video-sdk). Support for the 1.x version ended on December 4th, 2020.

2.18.3 (January 4, 2022)
========================

Bug Fixes
---------

- Fixed a bug where connect was returning a Promise type instead of a CancelablePromise. (VIDEO-7831)
- Fixed a bug where `audioLevel`, `frameRate`, and `captureDimensions` WebRTC stats are returning null on certain browsers. With this release, these stats are now populated whenever they are available. (VIDEO-3600)

2.18.2 (December 15, 2021)
==========================

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Releases of twilio-video.js are hosted on a CDN, and you can include these
directly in your web app using a &lt;script&gt; tag.

```html
<script src="//sdk.twilio.com/js/video/releases/2.18.2/twilio-video.min.js"></script>
<script src="//sdk.twilio.com/js/video/releases/2.18.3/twilio-video.min.js"></script>

```

Expand Down
12 changes: 12 additions & 0 deletions lib/util/cancelablepromise.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ class CancelablePromise {
promise.then(...args).then(resolve, reject);
}, this._onCancel);
}

/**
* @param {?function} onFinally
* @returns {CancelablePromise}
*/
finally() {
const args = [].slice.call(arguments);
const promise = this._promise;
return new CancelablePromise(function onCreate(resolve, reject) {
promise.finally(...args).then(resolve, reject);
}, this._onCancel);
}
}

module.exports = CancelablePromise;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"test:framework:install": "npm install chromedriver && npm install selenium-webdriver && npm install geckodriver && npm install puppeteer",
"test:framework": "npm-run-all test:framework:install test:framework:no-framework test:framework:react",
"test": "npm-run-all test:unit test:integration",
"build:es5": "rimraf ./es5 && tsc tsdef/twilio-video-tests.ts --noEmit && tsc",
"build:es5": "rimraf ./es5 && tsc tsdef/twilio-video-tests.ts --noEmit --lib es2018,dom && tsc ",
"build:js": "node ./scripts/build.js ./src/twilio-video.js ./LICENSE.md ./dist/twilio-video.js",
"build:min.js": "uglifyjs ./dist/twilio-video.js -o ./dist/twilio-video.min.js --comments \"/^! twilio-video.js/\" -b beautify=false,ascii_only=true",
"build": "npm-run-all clean lint docs test:unit test:integration build:es5 build:js build:min.js test:umd",
Expand All @@ -146,7 +146,7 @@
"clean": "rimraf ./coverage ./es5 ./dist"
},
"dependencies": {
"@twilio/webrtc": "4.5.1",
"@twilio/webrtc": "4.5.2",
"backoff": "^2.5.0",
"ws": "^7.4.6",
"xmlhttprequest": "^1.8.0"
Expand Down
47 changes: 47 additions & 0 deletions test/integration/spec/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const assert = require('assert');
const { EventEmitter } = require('events');
const { getUserMedia } = require('@twilio/webrtc');
const sinon = require('sinon');

const connect = require('../../../es5/connect');
const { audio: createLocalAudioTrack, video: createLocalVideoTrack } = require('../../../es5/createlocaltrack');
Expand Down Expand Up @@ -673,6 +674,52 @@ describe('connect', function() {
});
});

describe('called with a Room name and', () => {
let sid;
let cancelablePromise;

before(async () => {
sid = await createRoom(randomName(), defaults.topology);
const options = Object.assign({ name: sid, tracks: [] }, defaults);
cancelablePromise = connect(getToken(randomName()), options);
});

after(() => completeRoom(sid));

it('should return a promise', async () => {
const onFinally = sinon.stub();
await cancelablePromise.finally(onFinally);
sinon.assert.calledOnce(onFinally);
});

it('should resolve with a room and finally is called', async () => {
const onFinally = sinon.stub();
let room;
let errorThrown = null;
try {
room = await cancelablePromise.finally(onFinally);
} catch (error) {
errorThrown = error;
}
sinon.assert.calledOnce(onFinally);
assert(!errorThrown);
assert(room instanceof Room);
});

it('should reject and finally is called', async () => {
const onFinally = sinon.stub();
let err;
try {
await cancelablePromise.finally(onFinally);
throw new Error('Connecting to room, but expecting to cancel');
} catch (error) {
err = error;
}
assert(err);
sinon.assert.calledOnce(onFinally);
});
});

(isRTCRtpSenderParamsSupported ? describe : describe.skip)('DSCP tagging', () => {
combinationContext([
[
Expand Down
52 changes: 52 additions & 0 deletions test/unit/spec/util/cancelablepromise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const CancelablePromise = require('../../../../lib/util/cancelablepromise');

const { a } = require('../../../lib/util');

const sinon = require('sinon');

describe('CancelablePromise', () => {
describe('constructor', () => {
it('should return an instance of CancelablePromise', () => {
Expand Down Expand Up @@ -337,4 +339,54 @@ describe('CancelablePromise', () => {
});
});
});

describe('#finally', () => {
['rejected', 'resolved', 'unresolved', 'unrejected'].forEach(type => {
describe(`called on ${a(type)} ${type} CancelablePromise`, () => {
let cancelablePromise;
let resultOrReason;
let resolveOrReject;
let resolved;

beforeEach(() => {
resultOrReason = {};
resolveOrReject = null;

cancelablePromise = new CancelablePromise((resolve, reject) => {
switch (type) {
case 'canceled':
resolveOrReject = () => reject(resultOrReason);
break;
case 'rejected':
reject(resultOrReason);
break;
case 'resolved':
resolve(resultOrReason);
break;
case 'unrejected':
resolveOrReject = () => reject(resultOrReason);
break;
case 'unresolved':
resolveOrReject = () => resolve(resultOrReason);
break;
}
}, () => {
resolveOrReject();
}).then(result => {
resolved = result;
});
});

it('should have called finally', async () => {
const onFinally = sinon.stub();
await cancelablePromise.finally(onFinally);
if (resolveOrReject) {
resolveOrReject();
}
sinon.assert.calledOnce(onFinally);
assert(cancelablePromise instanceof CancelablePromise);
});
});
});
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"checkJs": false,
"declaration": false,
"target": "es5",
"lib": ["es5", "es6", "es2016", "es2019", "es2018.promise", "dom"],
"lib": ["es2019", "dom"],
"downlevelIteration": true,
"module": "commonjs",
"noImplicitAny": true,
Expand Down
4 changes: 2 additions & 2 deletions tsdef/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConnectOptions, CreateLocalTrackOptions, CreateLocalTracksOptions, LocalTrack } from './types';
import { CancelablePromise, ConnectOptions, CreateLocalTrackOptions, CreateLocalTracksOptions, LocalTrack } from './types';
import { PreflightOptions, PreflightTestReport } from './PreflightTypes';
import { LocalAudioTrack } from './LocalAudioTrack';
import { LocalVideoTrack } from './LocalVideoTrack';
Expand All @@ -10,7 +10,7 @@ import { Room } from './Room';
export const isSupported: boolean;
export const version:string;
export const Logger: Log.RootLogger;
export function connect(token: string, options?: ConnectOptions): Promise<Room>;
export function connect(token: string, options?: ConnectOptions): CancelablePromise<Room>;
export function createLocalAudioTrack(options?: CreateLocalTrackOptions): Promise<LocalAudioTrack>;
export function createLocalTracks(options?: CreateLocalTracksOptions): Promise<LocalTrack[]>;
export function createLocalVideoTrack(options?: CreateLocalTrackOptions): Promise<LocalVideoTrack>;
Expand Down
13 changes: 13 additions & 0 deletions tsdef/twilio-video-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,19 @@ let room: Video.Room | null = null;
let localVideoTrack: Video.LocalVideoTrack | null = null;
let localAudioTrack: Video.LocalAudioTrack | null = null;

// Testing finally method
const maybeRoom = Video.connect('$TOKEN', {
name: 'room-name',
video: false,
audio: false
}).then(room => {
return room;
}).catch(err => {
throw new Error(err);
}).finally(() => {
return 'Finally happened!';
});

async function initRoom() {
room = await Video.connect('$TOKEN', {
name: 'room-name',
Expand Down
3 changes: 3 additions & 0 deletions tsdef/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,6 @@ export class StatsReport {
remoteAudioTrackStats: RemoteAudioTrackStats[];
remoteVideoTrackStats: RemoteVideoTrackStats[];
}
export interface CancelablePromise<T> extends Promise<T> {
cancel: () => void;
}

0 comments on commit 7a5c045

Please sign in to comment.