How to use wsPort method in wpt

Best JavaScript code snippet using wpt

para-node.ts

Source:para-node.ts Github

copy

Full Screen

1import tcpPortUsed from "tcp-port-used";2import path from "path";3import { killAll, run } from "polkadot-launch";4import {5 BINARY_PATH,6 RELAY_BINARY_PATH,7 DISPLAY_LOG,8 SPAWNING_TIME,9 RELAY_CHAIN_NODE_NAMES,10} from "./constants";11const debug = require("debug")("test:para-node");12export async function findAvailablePorts(parachainCount: number = 1) {13 // 2 nodes per prachain, and as many relaychain nodes14 const relayCount = parachainCount + 1;15 const paraNodeCount = parachainCount * 2; // * 2;16 const nodeCount = relayCount + paraNodeCount;17 const portCount = nodeCount * 3;18 const availablePorts = await Promise.all(19 new Array(portCount).fill(0).map(async (_, index) => {20 let selectedPort = 0;21 let endingPort = 65535;22 const portDistance: number = Math.floor((endingPort - 1024) / portCount);23 let port = 1024 + index * portDistance + (process.pid % portDistance);24 while (!selectedPort && port < endingPort) {25 try {26 const inUse = await tcpPortUsed.check(port, "127.0.0.1");27 if (!inUse) {28 selectedPort = port;29 }30 } catch (e) {31 console.log("caught err ", e);32 }33 port++;34 }35 if (!selectedPort) {36 throw new Error(`No available port`);37 }38 return selectedPort;39 })40 );41 return new Array(nodeCount).fill(0).map((_, index) => ({42 p2pPort: availablePorts[index * 3 + 0],43 rpcPort: availablePorts[index * 3 + 1],44 wsPort: availablePorts[index * 3 + 2],45 }));46}47// Stores if the node has already started.48// It is used when a test file contains multiple describeDevMoonbeam. Those are49// executed within the same PID and so would generate a race condition if started50// at the same time.51let nodeStarted = false;52export type ParachainOptions = {53 chain:54 | "moonbase-local"55 | "moonriver-local"56 | "moonbeam-local"57 | "moonbase"58 | "moonriver"59 | "moonbeam";60 relaychain?: "rococo-local" | "westend-local" | "kusama-local" | "polkadot-local";61 numberOfParachains?: number;62};63export interface ParachainPorts {64 parachainId: number;65 ports: NodePorts[];66}67export interface NodePorts {68 p2pPort: number;69 rpcPort: number;70 wsPort: number;71}72// This will start a parachain node, only 1 at a time (check every 100ms).73// This will prevent race condition on the findAvailablePorts which uses the PID of the process74// Returns ports for the 3rd parachain node75export async function startParachainNodes(options: ParachainOptions): Promise<{76 relayPorts: NodePorts[];77 paraPorts: ParachainPorts[];78}> {79 while (nodeStarted) {80 // Wait 100ms to see if the node is free81 await new Promise((resolve) => {82 setTimeout(resolve, 100);83 });84 }85 const relaychain = options.relaychain || "rococo-local";86 // For now we only support one, two or three parachains87 const numberOfParachains =88 (options.numberOfParachains < 4 &&89 options.numberOfParachains > 0 &&90 options.numberOfParachains) ||91 1;92 const parachainArray = new Array(numberOfParachains).fill(0);93 nodeStarted = true;94 // Each node will have 3 ports. There are 2 nodes per parachain, and as many relaychain nodes.95 // So numberOfPorts = 3 * 2 * parachainCount96 const ports = await findAvailablePorts(numberOfParachains);97 //Build hrmpChannels, all connected to first parachain98 const hrmpChannels = [];99 new Array(numberOfParachains - 1).fill(0).forEach((_, i) => {100 hrmpChannels.push({101 sender: 1000,102 recipient: 1000 * (i + 2),103 maxCapacity: 8,104 maxMessageSize: 512,105 });106 hrmpChannels.push({107 sender: 1000 * (i + 2),108 recipient: 1000,109 maxCapacity: 8,110 maxMessageSize: 512,111 });112 });113 // Build launchConfig114 const launchConfig = {115 relaychain: {116 bin: RELAY_BINARY_PATH,117 chain: relaychain,118 nodes: new Array(numberOfParachains + 1).fill(0).map((_, i) => {119 return {120 name: RELAY_CHAIN_NODE_NAMES[i],121 port: ports[i].p2pPort,122 rpcPort: ports[i].rpcPort,123 wsPort: ports[i].wsPort,124 };125 }),126 genesis: {127 runtime: {128 runtime_genesis_config: {129 configuration: {130 config: {131 validation_upgrade_frequency: 1,132 validation_upgrade_delay: 1,133 },134 },135 },136 },137 },138 },139 parachains: parachainArray.map((_, i) => {140 return {141 bin: BINARY_PATH,142 chain: options.chain,143 nodes: [144 {145 port: ports[i * 2 + numberOfParachains + 1].p2pPort,146 rpcPort: ports[i * 2 + numberOfParachains + 1].rpcPort,147 wsPort: ports[i * 2 + numberOfParachains + 1].wsPort,148 name: "alice",149 flags: [150 "--log=info,rpc=trace,evm=trace,ethereum=trace",151 "--unsafe-rpc-external",152 "--rpc-cors=all",153 "--",154 "--execution=wasm",155 ],156 },157 {158 port: ports[i * 2 + numberOfParachains + 2].p2pPort,159 rpcPort: ports[i * 2 + numberOfParachains + 2].rpcPort,160 wsPort: ports[i * 2 + numberOfParachains + 2].wsPort,161 name: "bob",162 flags: [163 "--log=info,rpc=trace,evm=trace,ethereum=trace",164 "--unsafe-rpc-external",165 "--rpc-cors=all",166 "--",167 "--execution=wasm",168 ],169 },170 ],171 };172 }),173 simpleParachains: [],174 hrmpChannels: hrmpChannels,175 finalization: true,176 };177 const onProcessExit = function () {178 killAll();179 };180 const onProcessInterrupt = function () {181 process.exit(2);182 };183 process.once("exit", onProcessExit);184 process.once("SIGINT", onProcessInterrupt);185 await run(path.join(__dirname, "../"), launchConfig);186 return {187 relayPorts: new Array(numberOfParachains + 1).fill(0).map((_, i) => {188 return {189 p2pPort: ports[i].p2pPort,190 rpcPort: ports[i].rpcPort,191 wsPort: ports[i].wsPort,192 };193 }),194 paraPorts: parachainArray.map((_, i) => {195 return {196 parachainId: 1000 * (i + 1),197 ports: [198 {199 p2pPort: ports[i * 2 + numberOfParachains + 1].p2pPort,200 rpcPort: ports[i * 2 + numberOfParachains + 1].rpcPort,201 wsPort: ports[i * 2 + numberOfParachains + 1].wsPort,202 },203 {204 p2pPort: ports[i * 2 + numberOfParachains + 2].p2pPort,205 rpcPort: ports[i * 2 + numberOfParachains + 2].rpcPort,206 wsPort: ports[i * 2 + numberOfParachains + 2].wsPort,207 },208 ],209 };210 }),211 };212}213export async function stopParachainNodes() {214 killAll();215 await new Promise((resolve) => {216 // TODO: improve, make killAll async https://github.com/paritytech/polkadot-launch/issues/139217 console.log("Waiting 10 seconds for processes to shut down...");218 setTimeout(resolve, 10000);219 nodeStarted = false;220 console.log("... done");221 });...

Full Screen

Full Screen

index.ts

Source:index.ts Github

copy

Full Screen

1const router = require('express').Router();2// @ts-expect-error3import Stream from 'node-rtsp-stream';4import { Request, Response, Application } from 'express';5import { Api } from '../interface';6import * as dotenv from 'dotenv';7dotenv.config();8const db: any = {};9const ffmpegOptions: any = { '-r': 30 };10router.post('/start/:wsPort', (req: Request<Api.id, Api.Resp, Api.body>, res: Response<Api.Resp>): void => {11 try {12 const { streamUrl } = req.body;13 const wsPort: number = parseInt(`${req.params.wsPort}`);14 const valid = Object.keys(db).includes(`${wsPort}`);15 if (valid) throw { message: `el puerto ${wsPort} ya esta ocupado`, info: { url: 'ws://localhost:' + wsPort } };16 const cam: any = new Stream({ streamUrl, wsPort, ffmpegOptions });17 db[wsPort] = { streamUrl, wsPort, ffmpegOptions, cam };18 const url: string = 'ws://44.202.237.3:' + cam.wsPort;19 //const url: string = `ws://${process.env.HOST}:${cam.wsPort}`;20 console.log('========================')21 console.log('url:',url)22 console.log('cam.wsPort:',cam.wsPort)23 console.log('wsPort:',wsPort)24 console.log('========================')25 setTimeout(() => res.status(200).json({ message: `camara ${cam.wsPort} encendida`, info: { url } }), 30000);26 } catch (err: any) {27 console.clear();28 console.log(err);29 res.status(400).json(err);30 }31});32router.delete('/stop/:wsPort', (req: Request<Api.id, Api.Resp>, res: Response<Api.Resp>): void => {33 try {34 const wsPort: number = parseInt(`${req.params.wsPort}`);35 const valid = Object.keys(db).length;36 if (!valid) throw { message: `el puerto ${wsPort} no esta ocupado` };37 db[wsPort].cam.stop();38 delete db[wsPort];39 res.status(200).json({ message: `camara ${wsPort} a sido apagada encendida` });40 } catch (err: any) {41 console.clear();42 console.log(err);43 res.status(400).json(err);44 }45});46router.get('/wsPorts', (req: Request<Api.id, Api.Resp, Api.body>, res: Response<Api.Resp>): void => {47 try {48 const wsPorts: number[] = Object.keys(db).map((key: any) => key);49 res.status(200).json({ message: `camara apagada`, info: { wsPorts } });50 } catch (err) {51 console.clear();52 console.log(err);53 res.status(400).json({ message: `error al apagar la camara` });54 }55});56export default (app: Application) => {57 app.use(router);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2wptools.page('Albert Einstein').then(function(page) {3 page.wsPort(function(port) {4 console.log('port: ' + port);5 });6});7[MIT](LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var wppath = wptoolkit.wpPath();3var wppath = wptoolkit.wsPort();4console.log(wppath);5var wptoolkit = require('wptoolkit');6var wppath = wptoolkit.wpPath();7console.log(wppath);8var wptoolkit = require('wptoolkit');9var wppath = wptoolkit.wpPath();10console.log(wppath);11var wptoolkit = require('wptoolkit');12var wppath = wptoolkit.wpPath();13console.log(wppath);14var wptoolkit = require('wptoolkit');15var wppath = wptoolkit.wpPath();16console.log(wppath);17var wptoolkit = require('wptoolkit');18var wppath = wptoolkit.wpPath();19console.log(wppath);20var wptoolkit = require('wptoolkit');21var wppath = wptoolkit.wpPath();22console.log(wppath);23var wptoolkit = require('wptoolkit');24var wppath = wptoolkit.wpPath();25console.log(wppath);26var wptoolkit = require('wptoolkit');27var wppath = wptoolkit.wpPath();28console.log(wppath);29var wptoolkit = require('wptoolkit');30var wppath = wptoolkit.wpPath();31console.log(wppath);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful