Skip to content

Commit

Permalink
feat: wip whip answer neg
Browse files Browse the repository at this point in the history
  • Loading branch information
birme committed Jun 28, 2024
1 parent 5128a0c commit c9b7f0a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/api_productions_core_functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ export class CoreFunctions {
);
}

console.log(sdpAnswer);
return sdpAnswer;
}

Expand Down
66 changes: 52 additions & 14 deletions src/connection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SessionDescription, parse } from 'sdp-transform';
import { inspect } from 'util';

import {
AudioSmbPayloadParameters,
Expand Down Expand Up @@ -90,6 +91,7 @@ export class Connection {
}
];

console.log('Offer created: ', inspect(offer, { depth: null }));
return offer;
}

Expand All @@ -100,6 +102,9 @@ export class Connection {
if (!this.endpointDescription['bundle-transport']) {
throw new Error('Missing bundle-transport in endpointDescription');
}
if (!this.mediaStreams) {
throw new Error('Missing endpointDescription audio');
}

const transport = this.endpointDescription['bundle-transport'];

Expand All @@ -113,9 +118,14 @@ export class Connection {
const parsedSDP = parse(offer);
parsedSDP.origin && parsedSDP.origin.sessionVersion++;

// We are only interested in audio now
parsedSDP.media = parsedSDP.media.filter((media) => media.type == 'audio');

let mediaStreamIdx = 0;
let bundleGroupMids = '';

for (const media of parsedSDP.media) {
const mediaStreamSsrc = this.mediaStreams.audio.ssrcs[mediaStreamIdx];
bundleGroupMids =
bundleGroupMids === ''
? `${media.mid}`
Expand All @@ -128,8 +138,8 @@ export class Connection {
hash: transport.dtls.hash
};
media.setup = media.setup === 'actpass' ? 'active' : 'actpass';
media.ssrcGroups = undefined;
media.ssrcs = undefined;
media.ssrcGroups = [];
media.ssrcs = [];
media.msid = undefined;
media.port = 9;
media.rtcp = {
Expand All @@ -138,6 +148,26 @@ export class Connection {
ipVer: 4,
address: '0.0.0.0'
};
media.ssrcs.push({
id: mediaStreamSsrc.ssrc,
attribute: 'cname',
value: mediaStreamSsrc.cname
});
media.ssrcs.push({
id: mediaStreamSsrc.ssrc,
attribute: 'label',
value: mediaStreamSsrc.label
});
media.ssrcs.push({
id: mediaStreamSsrc.ssrc,
attribute: 'mslabel',
value: mediaStreamSsrc.mslabel
});
media.ssrcs.push({
id: mediaStreamSsrc.ssrc,
attribute: 'msid',
value: `${mediaStreamSsrc.mslabel} ${mediaStreamSsrc.label}`
});
media.candidates = transport.ice.candidates.map((element) => {
return {
foundation: element.foundation,
Expand All @@ -153,18 +183,25 @@ export class Connection {
'network-id': element.network
};
});
if (media.type === 'audio') {
media.rtp = media.rtp.filter(
(rtp) => rtp.codec.toLowerCase() === 'opus'
);
const opusPayloadType = media.rtp.at(0)?.payload;
media.fmtp = media.fmtp.filter(
(fmtp) => fmtp.payload === opusPayloadType
);
media.payloads = `${opusPayloadType}`;
media.direction = 'recvonly';
media.rtcpFb = undefined;
}
media.connection = {
version: 4,
ip: '0.0.0.0'
};

media.rtp = media.rtp.filter((rtp) => rtp.codec.toLowerCase() === 'opus');
const opusPayloadType = media.rtp.at(0)?.payload;
media.fmtp = media.fmtp.filter(
(fmtp) => fmtp.payload === opusPayloadType
);
media.payloads = `${opusPayloadType}`;
media.direction = 'recvonly';
media.rtcpFb = undefined;
media.ext = this.endpointDescription.audio['rtp-hdrexts'].flatMap(
(element) => {
return { value: element.id, uri: element.uri };
}
);
mediaStreamIdx++;
}
parsedSDP.groups = [
{
Expand All @@ -173,6 +210,7 @@ export class Connection {
}
];

console.log('Answer negotiated: ', inspect(parsedSDP, { depth: null }));
return parsedSDP;
}

Expand Down
6 changes: 3 additions & 3 deletions src/smb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface BaseAllocationRequest {

export class SmbProtocol {
async allocateConference(smbUrl: string, smbKey: string): Promise<string> {
console.log('Allocate conference', smbUrl);
const allocateResponse = await fetch(smbUrl, {
method: 'POST',
headers: {
Expand Down Expand Up @@ -70,10 +71,9 @@ export class SmbProtocol {
if (idleTimeout) {
request['idleTimeout'] = idleTimeout;
}
Log().debug(request);

const url = smbUrl + conferenceId + '/' + endpointId;
Log().debug(url);
Log().debug('Allocate endpoint', url, request);
const response = await fetch(url, {
method: 'POST',
headers: {
Expand Down Expand Up @@ -114,7 +114,7 @@ export class SmbProtocol {
},
body: JSON.stringify(request)
});
Log().debug(request);
Log().debug('Configure endpoint', url, request);

if (!response.ok) {
Log().debug(JSON.stringify(request));
Expand Down

0 comments on commit c9b7f0a

Please sign in to comment.