-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement data channel message type * Better logging * Update * Ignore jest setup files * [MM-60561] RTC client metrics (#41) * Client metrics * Improve loss detection in case of senders of loss
- Loading branch information
1 parent
93c0c8b
commit 2ad11b3
Showing
24 changed files
with
424 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Encoder, Decoder } from '@msgpack/msgpack'; | ||
import { DCMessageType } from './types'; | ||
export declare function encodeDCMsg(enc: Encoder, msgType: DCMessageType, payload?: any): Uint8Array; | ||
export declare function decodeDCMsg(dec: Decoder, data: Uint8Array): { | ||
mt: unknown; | ||
payload: unknown; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { zlibSync, unzlibSync, strToU8, strFromU8 } from 'fflate'; | ||
import { DCMessageType } from './types'; | ||
export function encodeDCMsg(enc, msgType, payload) { | ||
const mt = enc.encode(msgType); | ||
if (typeof payload === 'undefined') { | ||
return mt; | ||
} | ||
let pl; | ||
if (msgType === DCMessageType.SDP) { | ||
pl = enc.encode(zlibSync(strToU8(JSON.stringify(payload)))); | ||
} | ||
else { | ||
pl = enc.encode(payload); | ||
} | ||
// Flat encoding | ||
const msg = new Uint8Array(mt.byteLength + pl.byteLength); | ||
msg.set(mt); | ||
msg.set(pl, mt.byteLength); | ||
return msg; | ||
} | ||
export function decodeDCMsg(dec, data) { | ||
let mt; | ||
let payload; | ||
let i = 0; | ||
// Messages are expected to be flat (no surrounding object). | ||
// We also support payload-less messages (e.g. ping/pong). | ||
for (const val of dec.decodeMulti(data)) { | ||
if (i === 0) { | ||
mt = val; | ||
} | ||
else if (i === 1) { | ||
payload = val; | ||
break; | ||
} | ||
i++; | ||
} | ||
if (mt === DCMessageType.SDP) { | ||
payload = strFromU8(unzlibSync(payload)); | ||
} | ||
return { mt, payload }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { TextEncoder, TextDecoder } from 'util'; | ||
global.TextEncoder = TextEncoder; | ||
// @ts-ignore | ||
global.TextDecoder = TextDecoder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export declare enum DCMessageType { | ||
Ping = 1, | ||
Pong = 2, | ||
SDP = 3, | ||
LossRate = 4, | ||
RoundTripTime = 5, | ||
Jitter = 6 | ||
} | ||
export type DCMessageSDP = Uint8Array; | ||
export type DCMessageLossRate = number; | ||
export type DCMessageRoundTripTime = number; | ||
export type DCMessageJitter = number; |
Oops, something went wrong.