Nitroglycerin Pickle Machine

    @observertc/sfu-monitor-js
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.0-beta.34 • Public • Published

    Javascript library to monitor Selective Forwarding Units (SFU)

    @observertc/sfu-monitor-js is javascript library to monitor your SFU and integrate with ObserveRTC.

    Table of Contents:

    Qucik Start

    Install the library by using NPM:

    npm i @observertc/sfu-monitor-js
    

    Once the library is installed, you need to integrate it. The first step is to setup a monitor in your application.

    import { SfuMonitor } from "@observertc/sfu-monitor-js";
    // see full config in Configuration section
    const config = {
        collectingPeriodInMs: 5000,
        samplingPeriodInMs: 10000,
        sendingPeriodInMs: 10000,
        sender: {
            websocket: {
                urls: ["ws://localhost:7080/samples/myServiceId/myMediaUnitId"]
            }
        }
    };
    const monitor = SfuMonitor.create(config);

    A monitor does three things: 1. Collect Stats 2. Make sample based on the collected stats 3. Send the sample to the observer

    Integrate Mediasoup

    To integrate mediasoup:3^ you can use the built-in MediasoupCollector.

    import { MediasoupCollector } from "@observertc/sfu-monitor-js";
    
    // you should use the previously created monitor object
    const collector = MediasoupCollector.create();
    monitor.addStatsCollector(collector);
    
    // ... somewhere in your code, where you use the mediasoup router to create transports
    const transport = router.createWebRtcTransport(options);
    collector.watchWebRtcTransport(transport, {
        pollStats: true
    });

    Note, the pollStats is set to true. This will order the collector to call the getStats method on every Consumers, Producers, DataProducers, DataConsumers added to the Transport.

    Integrate other type of SFUs

    To have a custom integration you could use AuxCollector as follows:

    import { AuxCollector } from "@observertc/sfu-monitor-js";
    
    const collector = AuxCollector.create();
    monitor.addStatsCollector(collector);
    
    const transportId = "myUniqueGeneratedTransportId"
    collector.addTransportStatsSupplier(transportId, async () => {
        const stats: SfuTransport = {
    
        };
        return stats;
    });
    // when you want to remove it:
    collector.removeTransportStatsSupplier(transportId);
    
    // similarly:
    collector.addInboundRtpPadStatsSupplier("padId", ...);
    collector.removeInboundRtpPadStatsSupplier("padId");
    
    collector.addOutboundRtpPadStatsSupplier("padId", ...);
    collector.removeOutboundRtpPadStatsSupplier("padId");
    
    collector.addSctpStreamStatsSupplier("channelId", ...);
    collector.removeSctpStreamSupplier("channelId");

    Sfu Monitor Storage

    Sfu Monitor collects measurements about the following components:

    • Transport: Represent a network transport connection between an SFU and an external endpoint
    • Inbound RTP Pad: Represents an ingress point for RTP sessions to the SFU.
    • Outbound RTP Pad: Represents an eggress point for RTP sessions from the SFU.
    • Media Stream: Represent a group of inbound RTP pads belong to the same outbound media track
    • Media Sink: Represent a group of outbound RTP pads belong to the same inbound media track
    • SCTP Channel: Represent an SCTP session

    Sfu Monitor Storage provided entries can be used to navigate from one collected components to another.

    Storage Navigations

    Entries:

    Transport Entries

    const storage = monitor.storage;
    for (const transport of storage.transports()) {
    
        console.log(`Transport (${transport.id}) stats:`, transport.stats);
    
        for (const inboundRtpPad of transport.inboundRtpPads()) {
            console.log(`Inbound Rtp Pad (${inboundRtpPad.id}) belongs to transport (${transport.id}) stats:`, inboundRtpPad.stats);
        }
        for (const outboundRtpPad of transport.outboundRtpPads()) {
            console.log(`Outbound Rtp Pad (${outboundRtpPad.id}) belongs to transport (${transport.id}) stats:`, outboundRtpPad.stats);
        }
        for (const sctpChannel of transport.sctpChannels()) {
            console.log(`SCTP channel (${sctpChannel.id}) belongs to transport (${transport.id}) stats:`, sctpChannel.stats);
        }
        for (const mediaSink of transport.mediaSinks()) {
            console.log(`Transport (${transport.id}) has a ${mediaSink.kind} 
                sink having ${mediaSink.getNumberOfOutboundRtpPads()} outbound Rtp pads`);
        }
        for (const mediaStream of transport.mediaStreams()) {
            console.log(`Transport (${transport.id}) has a ${mediaStream.kind} 
                sink having ${mediaStream.getNumberOfInboundRtpPads()} inbound Rtp pads`);
        }
    }

    Inbound RTP Entries

    for (const inboundRtpPad of storage.inboundRtpPads()) {
        // the transport the inbound rtp pad belongs to
        const transport = inboundRtpPad.getTransport();
        // the media stream the inbound rtp pad belongs to
        const mediaStream = inboundRtpPad.getMediaStream();
    }

    Outbound RTP Entries

    for (const outboundRtpPad of storage.outboundRtpPads()) {
        // the transport the outbound rtp pad belongs to
        const transport = outboundRtpPad.getTransport();
    
        // the media stream the outbound rtp pad belongs to
        const mediaStream = outboundRtpPad.getMediaStream();
    
        // the media sink the outbound rtp pad belongs to
        const mediaSInk = outboundRtpPad.getMediaSink();
    }

    Media Stream Entries

    for (const mediaStream of storage.mediaStreams()) {
    
        // the transport the media stream belongs to
        const transport = mediaStream.getTransport();
    
        for (const inboundRtpPad of mediaStream.inboundRtpPads()) {
            console.log(`Inbound Rtp Pad (${inboundRtpPad.id}) belongs to media stream (${mediaStream.id}) stats:`, inboundRtpPad.stats);
        }
        for (const mediaSink of mediaStream.mediaSinks()) {
            console.log(`Media stream (${mediaStream.id}) has a ${mediaSink.kind} 
                sink having ${mediaSink.getNumberOfOutboundRtpPads()} outbound Rtp pads`);
        }
    }

    Media Sink Entries

    for (const mediaSink of storage.mediaSinks()) {
        // the transport the media stream belongs to
        const transport = mediaSink.getTransport();
    
        // the media stream the media sink belongs to
        const mediaStream = mediaSink.getMediaSink();
    
        for (const outboundRtpPad of mediaSink.outboundRtpPads()) {
            console.log(`Outbound Rtp Pad (${outboundRtpPad.id}) belongs to media stream (${mediaSink.id}) stats:`, outboundRtpPad.stats);
        }
    }

    SCTP Channel Entries

    for (const sctpChannel of storage.sctpChannels()) {
        // the transport the sctp channel belongs to
        const transport = sctpChannel.getTransport();
    }

    Configurations

    const config = {
        /**
         * By setting it, the monitor calls the added statsCollectors periodically
         * and polls the stats.
         * 
         * DEFAULT: undefined
         */
        collectingPeriodInMs: 5000,
        /**
         * By setting it, the monitor make samples periodically.
         * 
         * DEFAULT: undefined
         */
        samplingPeriodInMs: 10000,
    
        /**
         * By setting it stats items and entries are deleted if they are not updated.
         * 
         * DEFAULT: undefined
         */
        statsExpirationTimeInMs: 60000,
    
        /**
         * Sampling Component Related configurations
         * 
         */
        sampler: {
                /**
             * The identifier of the SFU.
             * 
             * DEFAULT: a generated unique value
             */
            sfuId: "sfuId",
    
            /**
             * Indicate if the sampler only sample stats updated since the last sampling.
             * 
             * DEFAULT: true
             */
            incrementalSampling: true,
        },
        sender: {
            /**
             * Configure the codec used to transport samples or receieve 
             * feedback from the server.
             * 
             * Possible values: json, protobuf
             * 
             * DEFAULT: json
             * 
             */
            format: "json",
            /**
             * Websocket configuration to transport the samples
             */
            websocket: {
                /**
                 * The target urls the websocket is opened for 
                 */
                urls: ["ws://localhost:7080/samples/myServiceId/myMediaUnitId"],
                /**
                 * The maximum number of try to connect to the server
                 * 
                 * DEFAULT: 3
                 */
                maxRetry: 1,
                /**
                 * An optional field for additional socket option from ws package
                 */
                socketOptions: {
    
                },
            },
            /**
             * Configuration to setup a REST api transport method for the samples.
             */
            rest: {
                /**
                 * The target url the websocket is opened for 
                 */
                urls: ["http://localhost:7080/rest/samples/myServiceId/myMediaUnitId"];
                /**
                 * The maximum number of try to connect to the server
                 * 
                 * DEFAULT: 3
                 */
                maxRetry: 1,
            },
        }
    };

    API docs

    https://observertc.github.io/sfu-monitor-js/interfaces/SfuMonitor.html

    NPM package

    https://www.npmjs.com/package/@observertc/sfu-monitor-js

    Schemas

    https://github.com/observertc/schemas

    Getting Involved

    Sfu-monitor is made with the intention to provide an open-source monitoring solution for WebRTC developers. We develop new features and maintaining the current product with the help of the community. If you are interested in getting involved please read our contribution guideline.

    License

    Apache-2.0

    Install

    npm i @observertc/sfu-monitor-js

    DownloadsWeekly Downloads

    53

    Version

    1.0.0-beta.34

    License

    Apache-2.0

    Unpacked Size

    1.09 MB

    Total Files

    183

    Last publish

    Collaborators

    • pallab.gain
    • balazskreith