Allow for compatibility when using this package outside of the browser environment.
WebSocket and atob()/btoa() are natively supported in the browser environment. Previously, if run outside of browser environment, some SignalingClient methods wouldn't work, as those globals don't exist. Now, if the browser environment is not detected, then we try the nodejs equivalent of those methods.
And verified the new one worked by replacing the node_modules/amazon-kinesis-video-streams-webrtc/lib folder with the new one.
Before:
/Users/me/Downloads/js-sdk-test/node_modules/amazon-kinesis-video-streams-webrtc/lib/SignalingClient.js:108
this.websocket = new WebSocket(signedURL);
^
ReferenceError: WebSocket is not defined
at SignalingClient.<anonymous> (/Users/me/Downloads/js-sdk-test/node_modules/amazon-kinesis-video-streams-webrtc/lib/SignalingClient.js:108:46)
at step (/Users/me/Downloads/js-sdk-test/node_modules/tslib/tslib.js:141:27)
at Object.next (/Users/me/Downloads/js-sdk-test/node_modules/tslib/tslib.js:122:57)
at fulfilled (/Users/me/Downloads/js-sdk-test/node_modules/tslib/tslib.js:112:62)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitted 'error' event on SignalingClient instance at:
at SignalingClient.onError (/Users/me/Downloads/js-sdk-test/node_modules/amazon-kinesis-video-streams-webrtc/lib/SignalingClient.js:282:14)
at /Users/me/Downloads/js-sdk-test/node_modules/amazon-kinesis-video-streams-webrtc/lib/SignalingClient.js:84:50
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
After:
FINISHED!
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Issue #, if available:
https://github.com/awslabs/amazon-kinesis-video-streams-webrtc-sdk-js/issues/115
Description of changes:
WebSocket
andatob()
/btoa()
are natively supported in the browser environment. Previously, if run outside of browser environment, some SignalingClient methods wouldn't work, as those globals don't exist. Now, if the browser environment is not detected, then we try the nodejs equivalent of those methods..toJSON()
, it is not necessary.Testing
npm run develop
(connected master+viewer to verify).package.json
``` { "name": "js-sdk-test", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "amazon-kinesis-video-streams-webrtc": "^2.1.0" } } ```index.js (some information redacted)
``` const SignalingClient = require('amazon-kinesis-video-streams-webrtc').SignalingClient; const Roles = require('amazon-kinesis-video-streams-webrtc').Role; try { let client = new SignalingClient({ channelARN: "arn:aws:kinesisvideo:us-west-2:x:channel/demo-channel/x", channelEndpoint: "wss://m-x.kinesisvideo.us-west-2.amazonaws.com", role: Roles.MASTER, region: 'us-west-2', credentials: { accessKeyId: "x", secretAccessKey: "x", sessionToken: "x", }, }); client.open(); console.log('FINISHED!') } catch (e) { console.error(e); } ```And verified the new one worked by replacing the
node_modules/amazon-kinesis-video-streams-webrtc/lib
folder with the new one.Before:
After:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.