Provide encryption/decryption features compatible with Vonage sframe-core native package.
npm i @vonage/js-sframe
import {
AudioCodec,
Client,
KidType,
KeyContentType,
VideoCodec
} from "@vonage/js-sframe";
async function encryptConnection(
kid:KidType,
key:KeyContentType,
connection: RTCPeerConnection
) {
const [sender] = connection.getSenders();
const client = await Client.create();
await client.setCodecs(AudioCodec.OPUS, VideoCodec.VP8); // Setting codecs is mandatory for Safari.
await client.setReceiverEncryptionKey(kid, key);
await client.encrypt(kid, sender);
}
import {
AudioCodec,
Client,
KidType,
KeyContentType,
VideoCodec
} from "@vonage/js-sframe";
async function decrypt(
kid:KidType,
key:KeyContentType,
connection: RTCPeerConnection
) {
const [receiver] = connection.getReceivers();
const client = await Client.create();
await client.setCodecs(AudioCodec.OPUS, VideoCodec.VP8); // Setting codecs is mandatory for Safari.
await client.setReceiverEncryptionKey(kid, key);
await client.decrypt(kid, receiver);
}
Media codecs used can not be automatically known on Safari (WebKit). Therefore, if you want to support Safari (WebKit), you need to explicitly set them. This could be achieve via "client.setCodecs" method.
https://vonage.github.io/client-media-processing-docs/js-sframe/1.1.0/