opentok-network-test-js
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "opentok-network-test-js", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Precall network test for applications using the OpenTok platform.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -25,3 +25,18 @@ /** | ||
/** | ||
* Disconnect from a session. Once disconnected, remove all session | ||
* event listeners and invoke the provided callback function. | ||
*/ | ||
function disconnectFromSession(session: OT.Session) { | ||
return new Promise((resolve, reject) => { | ||
session.on('sessionDisconnected', () => { | ||
session.off(); | ||
resolve(); | ||
}); | ||
session.disconnect(); | ||
}); | ||
} | ||
/** | ||
* Attempt to connect to the OpenTok session | ||
@@ -115,2 +130,7 @@ */ | ||
return new Promise((resolve, reject) => { | ||
const disconnectAndReject = (rejectError: Error) => { | ||
disconnectFromSession(session).then(() => { | ||
reject(rejectError); | ||
}); | ||
}; | ||
checkCreateLocalPublisher(OT) | ||
@@ -120,12 +140,10 @@ .then(({ publisher }: CreateLocalPublisherResults) => { | ||
if (error) { | ||
session.on('sessionDisconnected', () => { | ||
if (errorHasName(error, OTErrorType.NOT_CONNECTED)) { | ||
reject(new e.PublishToSessionNotConnectedError()); | ||
} else if (errorHasName(error, OTErrorType.UNABLE_TO_PUBLISH)) { | ||
reject(new e.PublishToSessionPermissionOrTimeoutError()); | ||
} else if (error) { | ||
reject(new e.PublishToSessionError()); | ||
} | ||
}); | ||
session.disconnect(); | ||
if (errorHasName(error, OTErrorType.NOT_CONNECTED)) { | ||
disconnectAndReject(new e.PublishToSessionNotConnectedError()); | ||
} else if (errorHasName(error, OTErrorType.UNABLE_TO_PUBLISH)) { | ||
disconnectAndReject( | ||
new e.PublishToSessionPermissionOrTimeoutError()); | ||
} else if (error) { | ||
disconnectAndReject(new e.PublishToSessionError()); | ||
} | ||
} else { | ||
@@ -136,6 +154,3 @@ resolve({ ...{ session }, ...{ publisher } }); | ||
}).catch((error: e.ConnectivityError) => { | ||
session.on('sessionDisconnected', () => { | ||
reject(error); | ||
}); | ||
session.disconnect(); | ||
disconnectAndReject(error); | ||
}); | ||
@@ -151,7 +166,9 @@ }); | ||
const config = { testNetwork: true, audioVolume: 0 }; | ||
const disconnectAndReject = (rejectError: Error) => { | ||
disconnectFromSession(session).then(() => { | ||
reject(rejectError); | ||
}); | ||
}; | ||
if (!publisher.stream) { | ||
session.on('sessionDisconnected', () => { | ||
reject(new e.SubscribeToSessionError()); // TODO: Specific error for this | ||
}); | ||
session.disconnect(); | ||
disconnectAndReject(new e.SubscribeToSessionError()); | ||
} else { | ||
@@ -161,6 +178,3 @@ const subscriberDiv = document.createElement('div'); | ||
if (error) { | ||
session.on('sessionDisconnected', () => { | ||
reject(new e.SubscribeToSessionError()); | ||
}); | ||
session.disconnect(); | ||
disconnectAndReject(new e.SubscribeToSessionError()); | ||
} else { | ||
@@ -206,7 +220,6 @@ resolve({ ...{ session }, ...{ publisher }, ...{ subscriber } }); | ||
otLogging.logEvent({ action: 'testConnectivity', variation: 'Success' }); | ||
flowResults.session.on('sessionDisconnected', () => { | ||
return disconnectFromSession(flowResults.session).then(() => { | ||
onComplete && onComplete(undefined, results); | ||
return resolve(results); | ||
}); | ||
flowResults.session.disconnect(); | ||
}; | ||
@@ -213,0 +226,0 @@ |
@@ -212,2 +212,3 @@ /** | ||
resolve(audioVideoResults); | ||
session.off(); | ||
}); | ||
@@ -231,2 +232,3 @@ session.disconnect(); | ||
resolve(audioVideoResults); | ||
session.off(); | ||
}); | ||
@@ -233,0 +235,0 @@ session.disconnect(); |
@@ -171,4 +171,4 @@ /** | ||
off<EventName extends keyof EventMap>( | ||
eventName: EventName, | ||
callback: (event: EventMap[EventName]) => void | ||
eventName?: EventName, | ||
callback?: (event: EventMap[EventName]) => void | ||
): void; | ||
@@ -175,0 +175,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27991836
4150