Skip to content

Commit

Permalink
Node: Add WebRtcServerDump
Browse files Browse the repository at this point in the history
  • Loading branch information
jmillan committed Oct 26, 2023
1 parent ae2d940 commit 3fe9158
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 20 deletions.
6 changes: 3 additions & 3 deletions node/src/Transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ export class Transport
async dump(): Promise<any>
{
// Should not happen.
throw new Error('method not implemented in the subclass');
throw new Error('method implemented in the subclass');
}

/**
Expand All @@ -610,7 +610,7 @@ export class Transport
async getStats(): Promise<any[]>
{
// Should not happen.
throw new Error('method not implemented in the subclass');
throw new Error('method implemented in the subclass');
}

/**
Expand All @@ -622,7 +622,7 @@ export class Transport
async connect(params: any): Promise<void>
{
// Should not happen.
throw new Error('method not implemented in the subclass');
throw new Error('method implemented in the subclass');
}

/**
Expand Down
76 changes: 60 additions & 16 deletions node/src/WebRtcServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type WebRtcServerOptions<WebRtcServerAppData extends AppData = AppData> =
export type WebRtcServerListenInfo = TransportListenInfo;

export type WebRtcServerEvents =
{
{
workerclose: [];
// Private events.
'@close': [];
Expand All @@ -42,6 +42,34 @@ export type WebRtcServerObserverEvents =
webrtctransportunhandled: [WebRtcTransport];
};

export type WebRtcServerDump =
{
id: string;
udpSockets: IpPort[];
tcpServers: IpPort[];
webRtcTransportIds: string[];
localIceUsernameFragments: IceUserNameFragment[];
tupleHashes: TupleHash[];
};

type IpPort =
{
ip: string;
port: number;
};

type IceUserNameFragment =
{
localIceUsernameFragment: string;
webRtcTransportId: string;
};

type TupleHash =
{
tupleHash: number;
webRtcTransportId: string;
};

type WebRtcServerInternal =
{
webRtcServerId: string;
Expand Down Expand Up @@ -213,7 +241,7 @@ export class WebRtcServer<WebRtcServerAppData extends AppData = AppData>
/**
* Dump WebRtcServer.
*/
async dump(): Promise<any>
async dump(): Promise<WebRtcServerDump>
{
logger.debug('dump()');

Expand Down Expand Up @@ -248,32 +276,48 @@ export class WebRtcServer<WebRtcServerAppData extends AppData = AppData>
}
}

// TODO: This function should return WebRtcServerDump TypeScript type but we
// don't have it yet (same for many other dump() methods everywhere).
function parseIpPort(binary: FbsWebRtcServer.IpPort): IpPort
{
return {
ip : binary.ip()!,
port : binary.port()
};
}

function parseIceUserNameFragment(binary: FbsWebRtcServer.IceUserNameFragment): IceUserNameFragment
{
return {
localIceUsernameFragment : binary.localIceUsernameFragment()!,
webRtcTransportId : binary.webRtcTransportId()!
};
}

function parseTupleHash(binary: FbsWebRtcServer.TupleHash): TupleHash
{
return {
tupleHash : Number(binary.tupleHash()!),
webRtcTransportId : binary.webRtcTransportId()!
};
}

function parseWebRtcServerDump(
data: FbsWebRtcServer.DumpResponse
): any
): WebRtcServerDump
{
return {
id : data.id(),
id : data.id()!,
udpSockets : utils.parseVector(
data, 'udpSockets', (udpSocket: any) => udpSocket.unpack()
data, 'udpSockets', parseIpPort
),
tcpServers : utils.parseVector(
data, 'tcpServers', (tcpServer: any) => tcpServer.unpack()
data, 'tcpServers', parseIpPort
),
webRtcTransportIds : utils.parseVector(data, 'webRtcTransportIds'),
localIceUsernameFragments : utils.parseVector(
data, 'localIceUsernameFragments', (localIceUsernameFragment: any) => localIceUsernameFragment.unpack()
data, 'localIceUsernameFragments', parseIceUserNameFragment
),
tupleHashes : utils.parseVector(
data, 'tupleHashes', (tupleHash: any) =>
{
return {
localIceUsernameFragment : Number(tupleHash.localIceUsernameFragment()),
webRtcTransportId : tupleHash.webRtcTransportId()
};
}
data, 'tupleHashes', parseTupleHash
)
};
}
2 changes: 1 addition & 1 deletion worker/fbs/webRtcServer.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ table IceUserNameFragment {
}

table TupleHash {
local_ice_username_fragment: uint64;
tuple_hash: uint64;
web_rtc_transport_id: string (required);
}

Expand Down

0 comments on commit 3fe9158

Please sign in to comment.