Skip to content

Commit

Permalink
flatbuffers
Browse files Browse the repository at this point in the history
  • Loading branch information
jmillan authored and nazar-pc committed Apr 18, 2023
1 parent 6c9a942 commit 0a88526
Show file tree
Hide file tree
Showing 201 changed files with 54,720 additions and 8,018 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/mediasoup-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,27 @@ jobs:
ci:
- os: ubuntu-22.04
node: 16
cc: gcc
cxx: g++
- os: ubuntu-22.04
node: 18
cc: gcc
cxx: g++
- os: macos-12
node: 18
cc: clang
cxx: clang++
- os: windows-2022
node: 18
cc: cl
cxx: cl

runs-on: ${{ matrix.ci.os }}

env:
CC: ${{ matrix.ci.cc }}
CXX: ${{ matrix.ci.cxx }}

steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/mediasoup-rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ jobs:
command: clippy
args: --all-targets -- -D warnings

- name: cargo test
uses: actions-rs/cargo@v1
env:
KEEP_BUILD_ARTIFACTS: '1'
with:
command: test
args: --verbose
#- name: cargo test
# uses: actions-rs/cargo@v1
# env:
# KEEP_BUILD_ARTIFACTS: '1'
# with:
# command: test
# args: --verbose
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
## Node.
/node_modules
/node/lib
# Flatc generated files.
/node/src/fbs

## Rust.
/Cargo.lock
Expand All @@ -16,6 +18,8 @@
## Worker.
/worker/out
/worker/scripts/node_modules
# Flatc generated files.
/worker/include/FBS
# Vistual Studio generated Stuff.
/worker/**/Debug
/worker/**/Release
Expand Down
1 change: 1 addition & 0 deletions node/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node/src/fbs
12 changes: 9 additions & 3 deletions node/src/ActiveSpeakerObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
} from './RtpObserver';
import { Producer } from './Producer';
import { AppData } from './types';
import { Event, Notification } from './fbs/notification';
import * as FbsActiveSpeakerObserver from './fbs/active-speaker-observer';

export type ActiveSpeakerObserverOptions<ActiveSpeakerObserverAppData extends AppData = AppData> =
{
Expand Down Expand Up @@ -65,13 +67,17 @@ export class ActiveSpeakerObserver<ActiveSpeakerObserverAppData extends AppData

private handleWorkerNotifications(): void
{
this.channel.on(this.internal.rtpObserverId, (event: string, data?: any) =>
this.channel.on(this.internal.rtpObserverId, (event: Event, data?: Notification) =>
{
switch (event)
{
case 'dominantspeaker':
case Event.ACTIVESPEAKEROBSERVER_DOMINANT_SPEAKER:
{
const producer = this.getProducerById(data.producerId);
const notification = new FbsActiveSpeakerObserver.DominantSpeakerNotification();

data!.body(notification);

const producer = this.getProducerById(notification.producerId()!);

if (!producer)
{
Expand Down
41 changes: 30 additions & 11 deletions node/src/AudioLevelObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
} from './RtpObserver';
import { Producer } from './Producer';
import { AppData } from './types';
import * as utils from './utils';
import { Event, Notification } from './fbs/notification';
import * as FbsAudioLevelObserver from './fbs/audio-level-observer';

export type AudioLevelObserverOptions<AudioLevelObserverAppData extends AppData = AppData> =
{
Expand Down Expand Up @@ -87,22 +90,27 @@ export class AudioLevelObserver<AudioLevelObserverAppData extends AppData = AppD

private handleWorkerNotifications(): void
{
this.channel.on(this.internal.rtpObserverId, (event: string, data?: any) =>
this.channel.on(this.internal.rtpObserverId, (event: Event, data?: Notification) =>
{
switch (event)
{
case 'volumes':
case Event.AUDIOLEVELOBSERVER_VOLUMES:
{
const notification = new FbsAudioLevelObserver.VolumesNotification();

data!.body(notification);

// Get the corresponding Producer instance and remove entries with
// no Producer (it may have been closed in the meanwhile).
const volumes: AudioLevelObserverVolume[] = data
.map(({ producerId, volume }: { producerId: string; volume: number }) => (
{
producer : this.getProducerById(producerId),
volume
}
))
.filter(({ producer }: { producer: Producer }) => producer);
const volumes: AudioLevelObserverVolume[] =
utils.parseVector(notification, 'volumes', parseVolume)
.map(({ producerId, volume }: { producerId: string; volume: number }) => (
{
producer : this.getProducerById(producerId)!,
volume
}
))
.filter(({ producer }: { producer: Producer }) => producer);

if (volumes.length > 0)
{
Expand All @@ -115,7 +123,7 @@ export class AudioLevelObserver<AudioLevelObserverAppData extends AppData = AppD
break;
}

case 'silence':
case Event.AUDIOLEVELOBSERVER_SILENCE:
{
this.safeEmit('silence');

Expand All @@ -133,3 +141,14 @@ export class AudioLevelObserver<AudioLevelObserverAppData extends AppData = AppD
});
}
}

function parseVolume(binary: FbsAudioLevelObserver.Volume): {
producerId: string;
volume: number;
}
{
return {
producerId : binary.producerId()!,
volume : binary.volume()
};
}

0 comments on commit 0a88526

Please sign in to comment.