<commit_before>const { toBeType } = require('jest-tobetype');
const dgram = require('dgram');
const sctp = require('sctp');
const mediasoup = require('../');
const { createWorker } = mediasoup;

expect.extend({ toBeType });

// Set node-sctp default PMTU to 1200.
sctp.defaults({ PMTU: 1200 });

let worker;
let router;
let transport;
let dataProducer;
let dataConsumer;
let udpSocket;
let sctpSocket;
let sendStreamId;
let sctpSendStream;

beforeAll(async () =>
{
	worker = await createWorker();
	router = await worker.createRouter();
	transport = await router.createPlainRtpTransport(
		{
			listenIp       : '127.0.0.1',
			enableSctp     : true,
			numSctpStreams : { OS: 256, MIS: 256 }
		});

	// Node UDP socket for SCTP.
	udpSocket = dgram.createSocket({ type: 'udp4' });

	await new Promise((resolve) => udpSocket.bind(0, '127.0.0.1', resolve));

	const localUdpPort = udpSocket.address().port;

	// Connect the mediasoup PlainRtpTransport to the UDP socket port.
	await transport.connect({ ip: '127.0.0.1', port: localUdpPort });

	const remoteUdpIp = transport.tuple.localIp;
	const remoteUdpPort = transport.tuple.localPort;
	const { OS, MIS } = transport.sctpParameters;

	// Use UDP connected socket if Node >= 12.
	if (typeof udpSocket.connect === 'function')
	{
		await new Promise((resolve, reject) =>
		{
			udpSocket.connect(remoteUdpPort, remoteUdpIp, (error) =>
			{
				if (error)
				{
					reject(error);

					return;
				}

				sctpSocket = sctp.connect(
					{
						localPort    : 5000, // Required for SCTP over UDP in mediasoup.
						port         : 5000, // Required for SCTP over UDP in mediasoup.
						OS           : OS,
						MIS          : MIS,
						udpTransport : udpSocket
					});

				resolve();
			});
		});
	}
	// Use UDP disconnected socket if Node < 12.
	else
	{
		sctpSocket = sctp.connect(
			{
				localPort    : 5000, // Required for SCTP over UDP in mediasoup.
				port         : 5000, // Required for SCTP over UDP in mediasoup.
				OS           : OS,
				MIS          : MIS,
				udpTransport : udpSocket,
				udpPeer      :
				{
					address : remoteUdpIp,
					port    : remoteUdpPort
				}
			});
	}

	// Create a explicit SCTP outgoing stream with id 123 (id 0 is already used
	// by the implicit SCTP outgoing stream built-in the SCTP socket).
	sendStreamId = 123;
	sctpSendStream = sctpSocket.createStream(sendStreamId);

	// Create DataProducer with the corresponding SCTP stream id.
	dataProducer = await transport.produceData(
		{
			sctpStreamParameters :
			{
				streamId : sendStreamId,
				ordered  : true
			}
		});
<commit_msg>cosmetic<commit_after>const { toBeType } = require('jest-tobetype');
const dgram = require('dgram');
const sctp = require('sctp');
const mediasoup = require('../');
const { createWorker } = mediasoup;

expect.extend({ toBeType });

// Set node-sctp default PMTU to 1200.
sctp.defaults({ PMTU: 1200 });

let worker;
let router;
let transport;
let dataProducer;
let dataConsumer;
let udpSocket;
let sctpSocket;
let sendStreamId;
let sctpSendStream;

beforeAll(async () =>
{
	worker = await createWorker();
	router = await worker.createRouter();
	transport = await router.createPlainRtpTransport(
		{
			listenIp       : '127.0.0.1',
			enableSctp     : true,
			numSctpStreams : { OS: 256, MIS: 256 }
		});

	// Node UDP socket for SCTP.
	udpSocket = dgram.createSocket({ type: 'udp4' });

	await new Promise((resolve) => udpSocket.bind(0, '127.0.0.1', resolve));

	const localUdpPort = udpSocket.address().port;

	// Connect the mediasoup PlainRtpTransport to the UDP socket port.
	await transport.connect({ ip: '127.0.0.1', port: localUdpPort });

	const remoteUdpIp = transport.tuple.localIp;
	const remoteUdpPort = transport.tuple.localPort;
	const { OS, MIS } = transport.sctpParameters;

	// Use UDP connected socket if Node >= 12.
	if (typeof udpSocket.connect === 'function')
	{
		await new Promise((resolve, reject) =>
		{
			udpSocket.connect(remoteUdpPort, remoteUdpIp, (error) =>
			{
				if (error)
				{
					reject(error);

					return;
				}

				sctpSocket = sctp.connect(
					{
						localPort    : 5000, // Required for SCTP over UDP in mediasoup.
						port         : 5000, // Required for SCTP over UDP in mediasoup.
						OS           : OS,
						MIS          : MIS,
						udpTransport : udpSocket
					});

				resolve();
			});
		});
	}
	// Use UDP disconnected socket if Node < 12.
	else
	{
		sctpSocket = sctp.connect(
			{
				localPort    : 5000, // Required for SCTP over UDP in mediasoup.
				port         : 5000, // Required for SCTP over UDP in mediasoup.
				OS           : OS,
				MIS          : MIS,
				udpTransport : udpSocket,
				udpPeer      :
				{
					address : remoteUdpIp,
					port    : remoteUdpPort
				}
			});
	}

	// Create a explicit SCTP outgoing stream with id 123 (id 0 is already used
	// by the implicit SCTP outgoing stream built-in the SCTP socket).
	sendStreamId = 123;
	sctpSendStream = sctpSocket.createStream(sendStreamId);

	// Create DataProducer with the corresponding SCTP stream id.
	dataProducer = await transport.produceData(
		{
			sctpStreamParameters :
			{
				streamId : sendStreamId,
				ordered  : true
			},
			label    : 'node-sctp',
			protocol : 'foo & bar 😀😀😀'
		});

{'fraction_non_alphanumeric': 0.11806217814228495, 'fraction_numerical': 0.023269120732405113, 'mean_word_length': 2.7510729613733904, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3182648', 'n_tokens_mistral': 2165, 'n_tokens_neox': 1777, 'n_words': 482}