Releasing not used Streaming plugin ports

Hi there,

Right now I am creating a Streaming stream by doing the following:

                    const create = {
                        request: 'create',
                        type: 'rtp',
                        is_private: false,
                        media: [
                            {
                                type: 'video',
                                mid: 'v1',
                                label: 'Board video stream',
                                port: 0,
                                pt: 96,
                                codec: janusServer.config_videocodec,
                            },
                        ],
                        permanent: false,
                    };

                    pluginHandle.send({
                        message: create,
                        success: (data: any) => {
                            if (data && data.created && data.stream) {
                                resolve(data.stream);
                            } else {
                                reject(`Error creating stream on ${janusServer.hostname}`);
                            }
                        },
                        error: (error: any) => {
                            reject(`Error creating stream on ${janusServer.hostname}: ${error}`);
                        },
                    });

It randomly assigns the next available port starting from 10000. How can I reset the ports, or let the plugin clear ‘old’ and unused ports to that it won’t go up to 20000.

Kind regards,
Jesse de Wild

You can’t. The code has a slider that moves any time a port is used, and is only reset when it gets to the top. It’s an optimization a user contributed a few years ago, because otherwise each time you created a new mountpoint we would first try and bind to a whole bunch of ports that might likely be taken already, causing a ton of failed system calls before finding a usable port.

See here for context: that was for the NoSIP plugin, which had a port range before the Streaming plugin, and whose code we copied there.

Do if we assign the ports automatically, we do not need to worry about ports not releasing? That it will always get a unused port?

Ports are always released when a mountpoint is destroyed. You simply don’t get a same port as before next time you assign ports automatically until the slider wraps.