mirror of
https://github.com/koush/scrypted.git
synced 2026-03-07 11:32:04 +00:00
38 lines
984 B
TypeScript
38 lines
984 B
TypeScript
// by @dgrief from @homebridge/camera-utils
|
|
|
|
export interface SrtpOptions {
|
|
srtpKey: Buffer
|
|
srtpSalt: Buffer
|
|
}
|
|
|
|
export function encodeSrtpOptions({ srtpKey, srtpSalt }: SrtpOptions) {
|
|
return Buffer.concat([srtpKey, srtpSalt]).toString('base64')
|
|
}
|
|
|
|
export function decodeSrtpOptions(encodedOptions: string): SrtpOptions {
|
|
const crypto = Buffer.from(encodedOptions, 'base64')
|
|
|
|
return {
|
|
srtpKey: crypto.slice(0, 16),
|
|
srtpSalt: crypto.slice(16, 30),
|
|
}
|
|
}
|
|
|
|
export function createCryptoLine(srtpOptions: SrtpOptions) {
|
|
const encodedOptions = encodeSrtpOptions(srtpOptions)
|
|
|
|
return `a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:${encodedOptions}`
|
|
}
|
|
|
|
export function isRtpMessagePayloadType(payloadType: number) {
|
|
return payloadType > 90 || payloadType === 0
|
|
}
|
|
|
|
export function getPayloadType(message: Buffer) {
|
|
return message.readUInt8(1) & 0x7f
|
|
}
|
|
|
|
export function getSequenceNumber(message: Buffer) {
|
|
return message.readUInt16BE(2)
|
|
}
|