opentok-network-test-js
Advanced tools
Comparing version 2.2.0 to 2.2.1
{ | ||
"name": "opentok-network-test-js", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "Precall network test for applications using the OpenTok platform.", | ||
@@ -5,0 +5,0 @@ "main": "dist/NetworkTest/index.js", |
@@ -52,2 +52,31 @@ /** | ||
/** | ||
* Clean subscriber objects before disconnecting from the session | ||
* @param session | ||
* @param subscriber | ||
*/ | ||
function cleanSubscriber(session: OT.Session, subscriber: OT.Subscriber) { | ||
return new Promise((resolve, reject) => { | ||
subscriber.on('destroyed', () => { | ||
resolve(); | ||
}); | ||
if (!subscriber) { | ||
resolve(); | ||
} | ||
session.unsubscribe(subscriber); | ||
}); | ||
} | ||
function cleanPublisher(publisher: OT.Publisher) { | ||
return new Promise((resolve, reject) => { | ||
publisher.on('destroyed', () => { | ||
resolve(); | ||
}); | ||
if (!publisher) { | ||
resolve(); | ||
} | ||
publisher.destroy(); | ||
}); | ||
} | ||
/** | ||
* Attempt to connect to the OpenTok sessionope | ||
@@ -203,5 +232,7 @@ */ | ||
const disconnectAndReject = (rejectError: Error) => { | ||
disconnectFromSession(session).then(() => { | ||
reject(rejectError); | ||
}); | ||
cleanPublisher(publisher) | ||
.then(() => disconnectFromSession(session)) | ||
.then(() => { | ||
reject(rejectError); | ||
}); | ||
}; | ||
@@ -255,5 +286,6 @@ if (!publisher.stream) { | ||
otLogging.logEvent({ action: 'testConnectivity', variation: 'Success' }); | ||
return disconnectFromSession(flowResults.session).then(() => { | ||
return resolve(results); | ||
}); | ||
return cleanSubscriber(flowResults.session, flowResults.subscriber) | ||
.then(() => cleanPublisher(flowResults.publisher)) | ||
.then(() => disconnectFromSession(flowResults.session)) | ||
.then(() => resolve(results)) | ||
}; | ||
@@ -260,0 +292,0 @@ |
@@ -38,3 +38,3 @@ /** | ||
export interface QualityTestResults extends HasAudioVideo<AverageStats> {} | ||
export interface QualityTestResults extends HasAudioVideo<AverageStats> { } | ||
@@ -44,2 +44,3 @@ type MOSResultsCallback = (state: MOSState) => void; | ||
type AvailableDevices = { audio: DeviceMap, video: DeviceMap }; | ||
type PublisherSubscriber = { publisher: OT.Publisher, subscriber: OT.Subscriber }; | ||
@@ -112,3 +113,3 @@ let audioOnly = false; // By default, the initial test is audio-video | ||
function publishAndSubscribe(OT: OT.Client, options?: NetworkTestOptions) { | ||
return (session: OT.Session): Promise<OT.Subscriber> => | ||
return (session: OT.Session): Promise<PublisherSubscriber> => | ||
new Promise((resolve, reject) => { | ||
@@ -171,3 +172,3 @@ let publisherOptions: OT.PublisherProperties; | ||
reject(new e.SubscribeToSessionError(subscribeError.message)) : | ||
resolve(subscriber); | ||
resolve({ publisher, subscriber }); | ||
}); | ||
@@ -186,3 +187,3 @@ }); | ||
credentials: OT.SessionCredentials, | ||
options?: NetworkTestOptions): Promise<OT.Subscriber> { | ||
options?: NetworkTestOptions): Promise<PublisherSubscriber> { | ||
return new Promise((resolve, reject) => { | ||
@@ -214,2 +215,35 @@ connectToSession(session, credentials.token) | ||
/** | ||
* Clean subscriber objects before disconnecting from the session | ||
* @param session | ||
* @param subscriber | ||
*/ | ||
function cleanSubscriber(session: OT.Session, subscriber: OT.Subscriber) { | ||
return new Promise((resolve, reject) => { | ||
subscriber.on('destroyed', () => { | ||
resolve(); | ||
}); | ||
if (!subscriber) { | ||
resolve(); | ||
} | ||
session.unsubscribe(subscriber); | ||
}); | ||
} | ||
/** | ||
* Clean publisher objects before disconnecting from the session | ||
* @param publisher | ||
*/ | ||
function cleanPublisher(publisher: OT.Publisher) { | ||
return new Promise((resolve, reject) => { | ||
publisher.on('destroyed', () => { | ||
resolve(); | ||
}); | ||
if (!publisher) { | ||
resolve(); | ||
} | ||
publisher.destroy(); | ||
}); | ||
} | ||
function checkSubscriberQuality( | ||
@@ -228,3 +262,3 @@ OT: OT.Client, | ||
subscribeToTestStream(OT, session, credentials, options) | ||
.then((subscriber: OT.Subscriber) => { | ||
.then(({ publisher, subscriber }: PublisherSubscriber) => { | ||
if (!subscriber) { | ||
@@ -261,3 +295,5 @@ reject(new e.MissingSubscriberError()); | ||
}); | ||
session.disconnect(); | ||
cleanSubscriber(session, subscriber) | ||
.then(() => cleanPublisher(publisher)) | ||
.then(() => session.disconnect()); | ||
} | ||
@@ -322,3 +358,3 @@ }; | ||
testTimeout = audioOnly ? config.getStatsAudioOnlyDuration : | ||
config.getStatsVideoAndAudioTestDuration; | ||
config.getStatsVideoAndAudioTestDuration; | ||
if (options && options.timeout) { | ||
@@ -325,0 +361,0 @@ testTimeout = Math.min(testTimeout, options.timeout, 30000); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
498945
4599