livekit-client
Advanced tools
{ | ||
"name": "livekit-client", | ||
"version": "2.5.5", | ||
"version": "2.5.6", | ||
"description": "JavaScript/TypeScript client SDK for LiveKit", | ||
@@ -5,0 +5,0 @@ "main": "./dist/livekit-client.umd.js", |
@@ -118,2 +118,7 @@ import { Encryption_Type, TrackInfo } from '@livekit/protocol'; | ||
case 'enable': | ||
if (data.enabled) { | ||
this.keyProvider.getKeys().forEach((keyInfo) => { | ||
this.postKey(keyInfo); | ||
}); | ||
} | ||
if ( | ||
@@ -138,7 +143,2 @@ this.encryptionEnabled !== data.enabled && | ||
} | ||
if (this.encryptionEnabled) { | ||
this.keyProvider.getKeys().forEach((keyInfo) => { | ||
this.postKey(keyInfo); | ||
}); | ||
} | ||
break; | ||
@@ -201,2 +201,5 @@ case 'ratchetKey': | ||
} | ||
keyProvider.getKeys().forEach((keyInfo) => { | ||
this.postKey(keyInfo); | ||
}); | ||
this.setParticipantCryptorEnabled( | ||
@@ -206,5 +209,2 @@ this.room.localParticipant.isE2EEEnabled, | ||
); | ||
keyProvider.getKeys().forEach((keyInfo) => { | ||
this.postKey(keyInfo); | ||
}); | ||
}); | ||
@@ -211,0 +211,0 @@ room.localParticipant.on(ParticipantEvent.LocalTrackPublished, async (publication) => { |
import { workerLogger } from '../../logger'; | ||
import { VideoCodec } from '../../room/track/options'; | ||
import { AsyncQueue } from '../../utils/AsyncQueue'; | ||
import { KEY_PROVIDER_DEFAULTS } from '../constants'; | ||
@@ -20,2 +21,3 @@ import { CryptorErrorReason } from '../errors'; | ||
let sharedKeyHandler: ParticipantKeyHandler | undefined; | ||
let messageQueue = new AsyncQueue(); | ||
@@ -35,81 +37,83 @@ let isEncryptionEnabled: boolean = false; | ||
onmessage = (ev) => { | ||
const { kind, data }: E2EEWorkerMessage = ev.data; | ||
messageQueue.run(async () => { | ||
const { kind, data }: E2EEWorkerMessage = ev.data; | ||
switch (kind) { | ||
case 'init': | ||
workerLogger.setLevel(data.loglevel); | ||
workerLogger.info('worker initialized'); | ||
keyProviderOptions = data.keyProviderOptions; | ||
useSharedKey = !!data.keyProviderOptions.sharedKey; | ||
// acknowledge init successful | ||
const ackMsg: InitAck = { | ||
kind: 'initAck', | ||
data: { enabled: isEncryptionEnabled }, | ||
}; | ||
postMessage(ackMsg); | ||
break; | ||
case 'enable': | ||
setEncryptionEnabled(data.enabled, data.participantIdentity); | ||
workerLogger.info( | ||
`updated e2ee enabled status for ${data.participantIdentity} to ${data.enabled}`, | ||
); | ||
// acknowledge enable call successful | ||
postMessage(ev.data); | ||
break; | ||
case 'decode': | ||
let cryptor = getTrackCryptor(data.participantIdentity, data.trackId); | ||
cryptor.setupTransform( | ||
kind, | ||
data.readableStream, | ||
data.writableStream, | ||
data.trackId, | ||
data.codec, | ||
); | ||
break; | ||
case 'encode': | ||
let pubCryptor = getTrackCryptor(data.participantIdentity, data.trackId); | ||
pubCryptor.setupTransform( | ||
kind, | ||
data.readableStream, | ||
data.writableStream, | ||
data.trackId, | ||
data.codec, | ||
); | ||
break; | ||
case 'setKey': | ||
if (useSharedKey) { | ||
setSharedKey(data.key, data.keyIndex); | ||
} else if (data.participantIdentity) { | ||
switch (kind) { | ||
case 'init': | ||
workerLogger.setLevel(data.loglevel); | ||
workerLogger.info('worker initialized'); | ||
keyProviderOptions = data.keyProviderOptions; | ||
useSharedKey = !!data.keyProviderOptions.sharedKey; | ||
// acknowledge init successful | ||
const ackMsg: InitAck = { | ||
kind: 'initAck', | ||
data: { enabled: isEncryptionEnabled }, | ||
}; | ||
postMessage(ackMsg); | ||
break; | ||
case 'enable': | ||
setEncryptionEnabled(data.enabled, data.participantIdentity); | ||
workerLogger.info( | ||
`set participant sender key ${data.participantIdentity} index ${data.keyIndex}`, | ||
`updated e2ee enabled status for ${data.participantIdentity} to ${data.enabled}`, | ||
); | ||
getParticipantKeyHandler(data.participantIdentity).setKey(data.key, data.keyIndex); | ||
} else { | ||
workerLogger.error('no participant Id was provided and shared key usage is disabled'); | ||
} | ||
break; | ||
case 'removeTransform': | ||
unsetCryptorParticipant(data.trackId, data.participantIdentity); | ||
break; | ||
case 'updateCodec': | ||
getTrackCryptor(data.participantIdentity, data.trackId).setVideoCodec(data.codec); | ||
break; | ||
case 'setRTPMap': | ||
// this is only used for the local participant | ||
rtpMap = data.map; | ||
participantCryptors.forEach((cr) => { | ||
if (cr.getParticipantIdentity() === data.participantIdentity) { | ||
cr.setRtpMap(data.map); | ||
// acknowledge enable call successful | ||
postMessage(ev.data); | ||
break; | ||
case 'decode': | ||
let cryptor = getTrackCryptor(data.participantIdentity, data.trackId); | ||
cryptor.setupTransform( | ||
kind, | ||
data.readableStream, | ||
data.writableStream, | ||
data.trackId, | ||
data.codec, | ||
); | ||
break; | ||
case 'encode': | ||
let pubCryptor = getTrackCryptor(data.participantIdentity, data.trackId); | ||
pubCryptor.setupTransform( | ||
kind, | ||
data.readableStream, | ||
data.writableStream, | ||
data.trackId, | ||
data.codec, | ||
); | ||
break; | ||
case 'setKey': | ||
if (useSharedKey) { | ||
await setSharedKey(data.key, data.keyIndex); | ||
} else if (data.participantIdentity) { | ||
workerLogger.info( | ||
`set participant sender key ${data.participantIdentity} index ${data.keyIndex}`, | ||
); | ||
await getParticipantKeyHandler(data.participantIdentity).setKey(data.key, data.keyIndex); | ||
} else { | ||
workerLogger.error('no participant Id was provided and shared key usage is disabled'); | ||
} | ||
}); | ||
break; | ||
case 'ratchetRequest': | ||
handleRatchetRequest(data); | ||
break; | ||
case 'setSifTrailer': | ||
handleSifTrailer(data.trailer); | ||
break; | ||
default: | ||
break; | ||
} | ||
break; | ||
case 'removeTransform': | ||
unsetCryptorParticipant(data.trackId, data.participantIdentity); | ||
break; | ||
case 'updateCodec': | ||
getTrackCryptor(data.participantIdentity, data.trackId).setVideoCodec(data.codec); | ||
break; | ||
case 'setRTPMap': | ||
// this is only used for the local participant | ||
rtpMap = data.map; | ||
participantCryptors.forEach((cr) => { | ||
if (cr.getParticipantIdentity() === data.participantIdentity) { | ||
cr.setRtpMap(data.map); | ||
} | ||
}); | ||
break; | ||
case 'ratchetRequest': | ||
handleRatchetRequest(data); | ||
break; | ||
case 'setSifTrailer': | ||
handleSifTrailer(data.trailer); | ||
break; | ||
default: | ||
break; | ||
} | ||
}); | ||
}; | ||
@@ -215,5 +219,5 @@ | ||
function setSharedKey(key: CryptoKey, index?: number) { | ||
async function setSharedKey(key: CryptoKey, index?: number) { | ||
workerLogger.info('set shared key', { index }); | ||
getSharedKeyHandler().setKey(key, index); | ||
await getSharedKeyHandler().setKey(key, index); | ||
} | ||
@@ -220,0 +224,0 @@ |
@@ -236,7 +236,13 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ | ||
if (!keySet) { | ||
throw new TypeError( | ||
`key set not found for ${ | ||
this.participantIdentity | ||
} at index ${this.keys.getCurrentKeyIndex()}`, | ||
this.emit( | ||
CryptorEvent.Error, | ||
new CryptorError( | ||
`key set not found for ${ | ||
this.participantIdentity | ||
} at index ${this.keys.getCurrentKeyIndex()}`, | ||
CryptorErrorReason.MissingKey, | ||
this.participantIdentity, | ||
), | ||
); | ||
return; | ||
} | ||
@@ -243,0 +249,0 @@ const { encryptionKey } = keySet; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
6709345
17.31%56134
9.46%