Skip to content

Commit

Permalink
Allow to set audio/video device id that is used for testing #96
Browse files Browse the repository at this point in the history
  • Loading branch information
miksansegundo committed Jul 5, 2019
1 parent 37d0be7 commit 11a696b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@types/webrtc": "0.0.22",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.7.0",
"dotenv": "^4.0.0",
"fs-extra": "^4.0.3",
"jasmine": "^2.99.0",
Expand Down
3 changes: 2 additions & 1 deletion src/NetworkTest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import OTKAnalytics = require('opentok-solutions-logging');
export interface NetworkTestOptions {
audioOnly?: boolean;
timeout?: number;
audioSource?: string;
videoSource?: string;
}

export default class NetworkTest {
Expand Down Expand Up @@ -106,7 +108,6 @@ export default class NetworkTest {
throw new InvalidOnUpdateCallback();
}
}

return testQuality(
this.OT, this.credentials, this.otLogging, this.options, updateCallback);
}
Expand Down
7 changes: 7 additions & 0 deletions src/NetworkTest/testConnectivity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ function checkCreateLocalPublisher(
insertMode: 'append',
showControls: false,
};
if (options && options.audioSource) {
publisherOptions.audioSource = options.audioSource
}
if (options && options.videoSource) {
publisherOptions.videoSource = options.videoSource
}
if (options && options.audioOnly) {
publisherOptions.videoSource = null;
}
Expand All @@ -140,6 +146,7 @@ function checkCreateLocalPublisher(
if (!error) {
resolve({ publisher });
} else {
console.error('OT.initPublisher', publisherOptions, error)
reject(new e.FailedToCreateLocalPublisher());
}
});
Expand Down
21 changes: 15 additions & 6 deletions src/NetworkTest/testQuality/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function validateDevices(OT: OT.Client): Promise<AvailableDevices> {
/**
* Create a test publisher and subscribe to the publihser's stream
*/
function publishAndSubscribe(OT: OT.Client) {
function publishAndSubscribe(OT: OT.Client, options?: NetworkTestOptions) {
return (session: OT.Session): Promise<OT.Subscriber> =>
new Promise((resolve, reject) => {
let publisherOptions: OT.PublisherProperties;
Expand All @@ -130,6 +130,13 @@ function publishAndSubscribe(OT: OT.Client) {
insertMode: 'append',
showControls: false,
};
if (options && options.audioSource) {
publisherOptions.audioSource = options.audioSource
}
if (options && options.videoSource) {
publisherOptions.videoSource = options.videoSource
}
console.log('AQUI test', publisherOptions)
if (audioOnly) {
publisherOptions.videoSource = null;
}
Expand Down Expand Up @@ -172,10 +179,11 @@ function publishAndSubscribe(OT: OT.Client) {
function subscribeToTestStream(
OT: OT.Client,
session: OT.Session,
credentials: OT.SessionCredentials): Promise<OT.Subscriber> {
credentials: OT.SessionCredentials,
options?: NetworkTestOptions): Promise<OT.Subscriber> {
return new Promise((resolve, reject) => {
connectToSession(session, credentials.token)
.then(publishAndSubscribe(OT))
.then(publishAndSubscribe(OT, options))
.then(resolve)
.catch(reject);
});
Expand Down Expand Up @@ -203,14 +211,15 @@ function checkSubscriberQuality(
OT: OT.Client,
session: OT.Session,
credentials: OT.SessionCredentials,
options?: NetworkTestOptions,
onUpdate?: UpdateCallback<OT.SubscriberStats>,
audioOnlyFallback?: boolean,
): Promise<QualityTestResults> {

let mosEstimatorTimeoutId: number;

return new Promise((resolve, reject) => {
subscribeToTestStream(OT, session, credentials)
subscribeToTestStream(OT, session, credentials, options)
.then((subscriber: OT.Subscriber) => {
if (!subscriber) {
reject(new e.MissingSubscriberError());
Expand All @@ -234,7 +243,7 @@ function checkSubscriberQuality(
const audioVideoResults: QualityTestResults = buildResults(builder);
if (!audioOnly && !isAudioQualityAcceptable(audioVideoResults)) {
audioOnly = true;
checkSubscriberQuality(OT, session, credentials, onUpdate, true)
checkSubscriberQuality(OT, session, credentials, options, onUpdate, true)
.then((results: QualityTestResults) => {
resolve(results);
});
Expand Down Expand Up @@ -322,7 +331,7 @@ export function testQuality(
validateBrowser()
.then(() => {
const session = OT.initSession(credentials.apiKey, credentials.sessionId);
checkSubscriberQuality(OT, session, credentials, onUpdate)
checkSubscriberQuality(OT, session, credentials, options, onUpdate)
.then(onSuccess)
.catch(onError);
})
Expand Down

0 comments on commit 11a696b

Please sign in to comment.