How to use createBody method in wpt

Best JavaScript code snippet using wpt

scene.ts

Source:scene.ts Github

copy

Full Screen

...41 let offset = Math.SQRT2 * size;42 const m = 1.0;4344 for (let i = 0; i < links; i++) {45 const body = world.createBody(46 i === 0 || i === links - 1 ? Number.POSITIVE_INFINITY : m,47 i === 0 || i === links - 1 ? Number.POSITIVE_INFINITY : m * 0.1,48 vec2.fromValues(offset - Math.SQRT2 * size + x - 11, 10),49 -Math.PI * 0.2550 );51 world.addCollider(new BodyCollider(body, createQuadShape(size)));5253 if (i > 0) {54 const bodyA = chain[i - 1];55 const pointA = vec2.fromValues(size * 0.5, size * 0.5);56 const pointB = vec2.fromValues(-size * 0.5, -size * 0.5);57 world.addDistanceJoint(bodyA, pointA, body, pointB, distance);58 }5960 chain[i] = body;61 offset += Math.SQRT2 * size + distance * 0.5;62 }63};6465export const createStackScene = (n: number) => {66 world.restitution = 0.5;67 world.pushFactor = 0.5;68 world.friction = 0.72;6970 // floor71 world.addCollider(72 new BodyCollider(73 world.createBody(74 Number.POSITIVE_INFINITY,75 Number.POSITIVE_INFINITY,76 vec2.fromValues(0.0, -9),77 0.078 ),79 createRectShape(20, 1)80 )81 );8283 // left wall84 world.addCollider(85 new BodyCollider(86 world.createBody(87 Number.POSITIVE_INFINITY,88 Number.POSITIVE_INFINITY,89 vec2.fromValues(-10, 0),90 0.091 ),92 createRectShape(1, 16)93 )94 );9596 // right wall97 world.addCollider(98 new BodyCollider(99 world.createBody(100 Number.POSITIVE_INFINITY,101 Number.POSITIVE_INFINITY,102 vec2.fromValues(10, 0),103 0.0104 ),105 createRectShape(1, 16)106 )107 );108109 for (let x = -8.0; x <= 8.0; x += 1) {110 for (let y = -8.0; y <= 8.0; y += 1) {111 world.addCollider(112 new BodyCollider(113 world.createBody(1.0, 1.0, vec2.fromValues(x, y * 0.999), 0.0),114 createRectShape(1, 1)115 )116 );117 }118 }119};120121export const createPendulumScene = (n: number) => {122 const step = 1.0;123 const length = 8;124 const m = 1.0;125126 world.restitution = 1.0; //elastic bounces127 world.pushFactor = 0.96;128 world.friction = 0.0;129130 // ceil131 const ceil = world.createBody(132 Number.POSITIVE_INFINITY,133 Number.POSITIVE_INFINITY,134 vec2.fromValues(0.0, 10),135 0.0136 );137 world.addCollider(new BodyCollider(ceil, createRectShape(20, 1)));138139 let offset = 0;140141 while (n--) {142 let pendulum: Body;143 if (n === 1) {144 pendulum = world.createBody(145 m,146 m,147 vec2.fromValues(148 (n % 2 ? offset : -offset) + length * Math.sin(Math.PI * 0.25),149 length * Math.cos(Math.PI * 0.25)150 ),151 0.0152 );153 world.addCollider(new BodyCollider(pendulum, new Circle(step * 0.5)));154 } else {155 pendulum = world.createBody(156 m,157 m,158 vec2.fromValues(n % 2 ? offset : -offset, 0),159 0.0160 );161 world.addCollider(new BodyCollider(pendulum, new Circle(step * 0.5)));162 }163164 world.addDistanceJoint(165 ceil,166 vec2.fromValues(n % 2 ? offset : -offset, 0.0),167 pendulum,168 vec2.fromValues(0.0, 0.0),169 length170 );171172 if (n % 2) {173 offset += step;174 }175 }176};177178export const createStairsScene = (n: number) => {179 world.restitution = 0.2;180 world.pushFactor = 0.4;181 world.friction = 0.2;182183 const w = 6;184 const h = 2.0;185 const xDist = 5.0;186 const yDist = 0.0;187 const m = 10.0;188 const interval = 1000;189190 let k = 32;191192 const spawn = () => {193 world.addCollider(194 new BodyCollider(195 world.createBody(m, m * 0.015, vec2.fromValues(w * 0.5, 12), 0.0),196 new Circle(0.5)197 )198 );199 if (k--) {200 setTimeout(() => spawn(), interval);201 }202 };203204 let y = 10.0 - h;205 while (n--) {206 const x = n % 2 ? xDist * 0.5 : -(xDist * 0.5);207208 world.addCollider(209 new BodyCollider(210 world.createBody(211 Number.POSITIVE_INFINITY,212 Number.POSITIVE_INFINITY,213 vec2.fromValues(x, y),214 n % 2 ? Math.PI * 0.125 : -Math.PI * 0.125215 ),216 createRectShape(w, 0.5)217 )218 );219220 y -= h + yDist;221 }222223 world.addCollider(224 new BodyCollider(225 world.createBody(226 Number.POSITIVE_INFINITY,227 Number.POSITIVE_INFINITY,228 vec2.fromValues(0.0, y - 1),229 0.0230 ),231 createRectShape(20, 1)232 )233 );234235 world.addCollider(236 new BodyCollider(237 world.createBody(238 Number.POSITIVE_INFINITY,239 Number.POSITIVE_INFINITY,240 vec2.fromValues(-8, y),241 0.0242 ),243 createQuadShape(1)244 )245 );246247 world.addCollider(248 new BodyCollider(249 world.createBody(250 Number.POSITIVE_INFINITY,251 Number.POSITIVE_INFINITY,252 vec2.fromValues(8, y),253 0.0254 ),255 createQuadShape(1)256 )257 );258259 spawn();260};261262export const createGaussianScene = () => {263 const n = 512;264 let columns = 9;265 let band = 2.0;266 const colW = 0.25;267 const sinkSlope = Math.PI * 0.35;268 let obstacleBands = 10;269 let obstacleMarginX = 2.0;270 let obstacleMarginY = 0.75;271 let obstacleSize = 0.25;272 let ballR = 0.2;273274 world.restitution = 0.5;275 world.pushFactor = 0.4;276 world.friction = 0.3;277278 // floor279 world.addCollider(280 new BodyCollider(281 world.createBody(282 Number.POSITIVE_INFINITY,283 Number.POSITIVE_INFINITY,284 vec2.fromValues(0.0, -10),285 0.0286 ),287 createRectShape(20, 1)288 )289 );290291 // left wall292 world.addCollider(293 new BodyCollider(294 world.createBody(295 Number.POSITIVE_INFINITY,296 Number.POSITIVE_INFINITY,297 vec2.fromValues(-10, -3.5),298 0.0299 ),300 createRectShape(0.5, 12)301 )302 );303304 // right wall305 world.addCollider(306 new BodyCollider(307 world.createBody(308 Number.POSITIVE_INFINITY,309 Number.POSITIVE_INFINITY,310 vec2.fromValues(10, -3.5),311 0.0312 ),313 createRectShape(0.5, 12)314 )315 );316317 // columns318 let x = 0.0;319 while (columns--) {320 if (columns % 2 == 1) {321 x += band + 0.0;322 }323 world.addCollider(324 new BodyCollider(325 world.createBody(326 Number.POSITIVE_INFINITY,327 Number.POSITIVE_INFINITY,328 vec2.fromValues(columns % 2 ? x : -x, -6.0),329 0.0330 ),331 createRectShape(colW, 7)332 )333 );334 }335336 // sink337 world.addCollider(338 new BodyCollider(339 world.createBody(340 Number.POSITIVE_INFINITY,341 Number.POSITIVE_INFINITY,342 vec2.fromValues(3, 10),343 sinkSlope344 ),345 createRectShape(10, 0.5)346 )347 );348349 world.addCollider(350 new BodyCollider(351 world.createBody(352 Number.POSITIVE_INFINITY,353 Number.POSITIVE_INFINITY,354 vec2.fromValues(-3, 10),355 -sinkSlope356 ),357 createRectShape(10, 0.5)358 )359 );360361 // obstacles362 let u = 0.0;363 let v = 5.0;364365 for (let i = 0; i < obstacleBands; i++) {366 u = -i * obstacleMarginX * 0.5;367368 for (let j = 0; j <= i; j++) {369 world.addCollider(370 new BodyCollider(371 world.createBody(372 Number.POSITIVE_INFINITY,373 Number.POSITIVE_INFINITY,374 vec2.fromValues(u, v),375 Math.PI * 0.25376 ),377 createQuadShape(obstacleSize)378 )379 );380381 u += obstacleMarginX;382 }383384 v -= obstacleMarginY;385 }386387 // balls388 const r = Math.floor(Math.sqrt(n));389390 u = 0.0;391 v = 14.0;392393 for (let i = r; i > 0; i--) {394 u = -i * ballR;395396 for (let j = i; j >= 0; j--) {397 world.addCollider(398 new BodyCollider(399 world.createBody(1.0, 1.0, vec2.fromValues(u, v), 0.0),400 new Circle(ballR)401 )402 );403404 u += 2.0 * ballR;405 }406407 v -= 2.0 * ballR;408 }409};410411export const createJointScene = () => {412 world.restitution = 0.35;413 world.pushFactor = 0.65;414 world.friction = 0.55;415416 const wheel = world.createBody(417 Number.POSITIVE_INFINITY,418 1.0,419 vec2.fromValues(-10.0, 0.0),420 0.0421 );422 world.addCollider(new BodyCollider(wheel, new Circle(2)));423424 setTimeout(() => {425 world.addCollider(426 new BodyCollider(427 world.createBody(10, 10.0, vec2.fromValues(-10.0, 0.0), 0.0),428 new Circle(1)429 )430 );431 }, 2000);432433 const bar = world.createBody(434 Number.POSITIVE_INFINITY,435 Number.POSITIVE_INFINITY,436 vec2.fromValues(0.0, -1.5),437 0.0438 );439 world.addCollider(new BodyCollider(bar, createRectShape(10, 0.1)));440441 const slider = world.createBody(1, 1, vec2.fromValues(0.0, -1), 0.0);442 world.addCollider(new BodyCollider(slider, createRectShape(3, 0.5)));443444 world.addPrismaticJoint(445 bar,446 vec2.fromValues(0, 0.45),447 slider,448 vec2.fromValues(0, 0),449 vec2.fromValues(1.0, 0)450 );451452 world.addDistanceJoint(453 wheel,454 vec2.fromValues(0, 1.75),455 slider,456 vec2.fromValues(0, 0),457 6458 );459460 world.addMotor(wheel, 2, 75.0);461462 // stack463 world.addCollider(464 new BodyCollider(465 world.createBody(466 Number.POSITIVE_INFINITY,467 Number.POSITIVE_INFINITY,468 vec2.fromValues(-3, 3.5),469 0.0470 ),471 createRectShape(0.1, 8)472 )473 );474475 world.addCollider(476 new BodyCollider(477 world.createBody(478 Number.POSITIVE_INFINITY,479 Number.POSITIVE_INFINITY,480 vec2.fromValues(-4, 3.5),481 0.0482 ),483 createRectShape(0.1, 8)484 )485 );486487 let n = 10;488 while (n--) {489 world.addCollider(490 new BodyCollider(491 world.createBody(1, 1, vec2.fromValues(-3.5, n), 0.0),492 createRectShape(0.85, 0.85)493 )494 );495 }496497 // swing498 const swing = world.createBody(499 Number.POSITIVE_INFINITY,500 1,501 vec2.fromValues(5.0, -5.5),502 0.0503 );504 world.addCollider(new BodyCollider(swing, createRectShape(5.5, 0.1)));505506 const ball = world.createBody(1.1, 0.1, vec2.fromValues(5.0, -8.0), 0.0);507 world.addCollider(new BodyCollider(ball, new Circle(0.5)));508509 const cube = world.createBody(1.1, 0.1, vec2.fromValues(3.0, -8.0), 0.0);510 world.addCollider(new BodyCollider(cube, createRectShape(1.0, 1.0)));511512 world.addSpring(513 ball,514 vec2.fromValues(0.5, 0.0),515 cube,516 vec2.fromValues(0.0, 0.0),517 1.0,518 50.0,519 20520 );521522 // floor523 world.addCollider(524 new BodyCollider(525 world.createBody(526 Number.POSITIVE_INFINITY,527 Number.POSITIVE_INFINITY,528 vec2.fromValues(0.0, -9),529 0.0530 ),531 createRectShape(16, 1)532 )533 );534535 // chain536 {537 const links = 40;538 const chain = new Array<Body>(links);539 const size = 0.5;540 const o = vec2.fromValues(-10.0, 0.0);541 const m = 1.0;542 const r = 4;543 const dPhi = (2 * Math.PI) / links;544 let phi = 0.0;545546 for (let i = 0; i < links; i++) {547 const x = o[0] + r * Math.cos(phi);548 const y = o[1] + r * Math.sin(phi);549550 const body = world.createBody(m, m, vec2.fromValues(x, y), phi);551 world.addCollider(552 new BodyCollider(body, createRectShape(size, size * 0.5))553 );554555 if (i > 0) {556 const bodyA = chain[i - 1];557 const pointA = vec2.fromValues(size * 0.65, 0.0);558 const pointB = vec2.fromValues(-size * 0.65, 0.0);559 world.addRevoluteJoint(bodyA, pointA, body, pointB);560 }561562 if (i === links - 1) {563 const bodyA = body;564 const bodyB = chain[0];565 const pointA = vec2.fromValues(size * 0.65, 0.0);566 const pointB = vec2.fromValues(-size * 0.65, 0.0);567 world.addRevoluteJoint(bodyA, pointA, bodyB, pointB);568 }569570 chain[i] = body;571572 phi += dPhi;573 }574 }575};576577export const createSuspensionScene = () => {578 world.restitution = 0.35;579 world.pushFactor = 0.65;580 world.friction = 0.55;581582 const stiffness = 25;583 const exstinction = 1;584585 let length = 6;586 const hull = world.createBody(1.0, 1.0, vec2.fromValues(10.0, -4.0), 0.0);587 world.addCollider(new BodyCollider(hull, createRectShape(length, 1.0)));588589 let wheels = 4;590 for (let i = 0; i < wheels; i++) {591 const wheel = world.createBody(1.1, 1.1, vec2.fromValues(8.5, -6.0), 0.0);592 world.addCollider(new BodyCollider(wheel, new Circle(0.5)));593594 world.addWheelJonit(595 hull,596 vec2.fromValues((length / (wheels - 1)) * i - length * 0.5, -0.5),597 wheel,598 vec2.fromValues(0.0, 0.0),599 vec2.fromValues(0.0, 1.0),600 1,601 3602 );603604 world.addSpring(605 hull,606 vec2.fromValues((length / (wheels - 1)) * i - length * 0.5, -0.5),607 wheel,608 vec2.fromValues(0.0, 0.0),609 2,610 stiffness,611 exstinction612 );613614 world.addMotor(wheel, Math.PI, 55);615 }616617 // left wall618 world.addCollider(619 new BodyCollider(620 world.createBody(621 Number.POSITIVE_INFINITY,622 Number.POSITIVE_INFINITY,623 vec2.fromValues(-14, 0),624 0.0625 ),626 createRectShape(0.25, 16)627 )628 );629630 // right wall631 world.addCollider(632 new BodyCollider(633 world.createBody(634 Number.POSITIVE_INFINITY,635 Number.POSITIVE_INFINITY,636 vec2.fromValues(14, 0),637 0.0638 ),639 createRectShape(0.25, 16)640 )641 );642643 // floor644 world.addCollider(645 new BodyCollider(646 world.createBody(647 Number.POSITIVE_INFINITY,648 Number.POSITIVE_INFINITY,649 vec2.fromValues(0.0, -9),650 0.0651 ),652 createRectShape(30, 1)653 )654 );655656 // obstacles657 let n = 8;658 while (n--) {659 world.addCollider(660 new BodyCollider(661 world.createBody(662 Number.POSITIVE_INFINITY,663 Number.POSITIVE_INFINITY,664 vec2.fromValues(n * 2 - 12.0, -8.5),665 Math.PI * 0.25666 ),667 new Circle(0.2)668 )669 );670 }671};672673export const createHelixScene = () => {674 world.restitution = 0.25;675 world.pushFactor = 0.65;676 world.friction = 0.75;677678 world.addCollider(679 new BodyCollider(680 world.createBody(10, 1.0, vec2.fromValues(0.0, 0.5), Math.PI * 0.25),681 new Circle(0.5)682 )683 );684685 const collection = loadObj(HELIX);686687 for (const object in collection) {688 world.addCollider(689 new BodyCollider(690 world.createBody(691 Number.POSITIVE_INFINITY,692 10,693 vec2.fromValues(0, 0),694 0695 ),696 new MeshShape(collection[object])697 )698 );699 }700};701702export const createPinballScene = () => {703 world.restitution = 0.75;704 world.pushFactor = 0.65;705 world.friction = 0.75;706707 world.addCollider(708 new BodyCollider(709 world.createBody(10, 1, vec2.fromValues(0.0, 6.5), Math.PI * 0.25),710 new Circle(0.25)711 )712 );713714 const collection = loadObj(PINTBALL);715716 for (const object in collection) {717 world.addCollider(718 new BodyCollider(719 world.createBody(720 Number.POSITIVE_INFINITY,721 Number.POSITIVE_INFINITY,722 vec2.fromValues(0, 0),723 0724 ),725 new MeshShape(collection[object])726 )727 );728 }729};730731export const createMeshScene = () => {732 world.restitution = 0.25;733 world.pushFactor = 0.65;734 world.friction = 0.75;735736 world.addCollider(737 new BodyCollider(738 world.createBody(10, 1, vec2.fromValues(0.0, 6.5), Math.PI * 0.25),739 new Circle(0.5)740 )741 );742743 const collection = loadObj(MESH);744745 for (const object in collection) {746 world.addCollider(747 new BodyCollider(748 world.createBody(10, 100, vec2.fromValues(0, 0), 0),749 new MeshShape(collection[object])750 )751 );752 }753754 // left wall755 world.addCollider(756 new BodyCollider(757 world.createBody(758 Number.POSITIVE_INFINITY,759 Number.POSITIVE_INFINITY,760 vec2.fromValues(-14, 0),761 0.0762 ),763 createRectShape(0.25, 16)764 )765 );766767 // right wall768 world.addCollider(769 new BodyCollider(770 world.createBody(771 Number.POSITIVE_INFINITY,772 Number.POSITIVE_INFINITY,773 vec2.fromValues(14, 0),774 0.0775 ),776 createRectShape(0.25, 16)777 )778 );779780 // floor781 world.addCollider(782 new BodyCollider(783 world.createBody(784 Number.POSITIVE_INFINITY,785 Number.POSITIVE_INFINITY,786 vec2.fromValues(0.0, -9),787 0.0788 ),789 createRectShape(30, 1)790 )791 );792};793794export const pistonScene = () => {795 world.restitution = 0.25;796 world.pushFactor = 0.65;797 world.friction = 0.75;798799 world.addCollider(800 new BodyCollider(801 world.createBody(1, 0.1, vec2.fromValues(0.0, 10.0), Math.PI * 0.25),802 new Circle(1.5)803 )804 );805806 const collection = loadObj(PISTON);807808 const cylinder = world.createBody(809 Number.POSITIVE_INFINITY,810 Number.POSITIVE_INFINITY,811 vec2.fromValues(0, 0),812 0813 );814 world.addCollider(815 new BodyCollider(cylinder, new MeshShape(collection['cylinder']))816 );817818 const piston = world.createBody(1, 1, vec2.fromValues(0, -1), 0);819 world.addCollider(820 new BodyCollider(piston, new MeshShape(collection['piston']))821 );822823 world.addPrismaticJoint(824 cylinder,825 vec2.create(),826 piston,827 vec2.create(),828 vec2.fromValues(0.0, 1.0),829 0,830 0.05,831 4832 );833834 world.addSpring(835 cylinder,836 vec2.create(),837 piston,838 vec2.create(),839 1.0,840 1000.0,841 10.0842 );843};844845export const createGearScene = () => {846 world.restitution = 0.25;847 world.pushFactor = 0.65;848 world.friction = 0.75;849850 const collection = loadObj(GEARS);851852 // for (const object in collection) {853 const motor = world.createBody(854 Number.POSITIVE_INFINITY,855 10,856 vec2.fromValues(0, 0),857 0858 );859 world.addMotor(motor, 10.0, 1.0);860 world.addCollider(861 new BodyCollider(motor, new MeshShape(collection['gear_o_049']))862 );863864 const gear0 = world.createBody(865 Number.POSITIVE_INFINITY,866 10,867 vec2.fromValues(-6.4191, 0),868 0869 );870 world.addCollider(871 new BodyCollider(gear0, new MeshShape(collection['gear_051']))872 );873874 const gear1 = world.createBody(875 Number.POSITIVE_INFINITY,876 10,877 vec2.fromValues(-0.8335, 9.7032),878 0879 );880 world.addCollider(881 new BodyCollider(gear1, new MeshShape(collection['gear_052']))882 );883884 const gear2 = world.createBody(885 Number.POSITIVE_INFINITY,886 10,887 vec2.fromValues(6.3478, 6.1935),888 0889 );890 world.addCollider(891 new BodyCollider(gear2, new MeshShape(collection['gear_049']))892 );893894 const gear3 = world.createBody(895 Number.POSITIVE_INFINITY,896 10,897 vec2.fromValues(9.0431, -1.3321),898 0899 );900901 world.addCollider(902 new BodyCollider(gear3, new MeshShape(collection['gear_o_052']))903 );904905 const gear4 = world.createBody(906 Number.POSITIVE_INFINITY,907 10,908 vec2.fromValues(1.7793, -7.6031),909 0910 );911912 world.addCollider(913 new BodyCollider(gear4, new MeshShape(collection['gear_o_050']))914 );915};916917export const createWarmScene = () => {918 world.restitution = 0.50;919 world.pushFactor = 0.95;920 world.friction = 0.0;921922923 // floor924 let body = world.createBody(925 Number.POSITIVE_INFINITY,926 Number.POSITIVE_INFINITY,927 vec2.fromValues(0.0, -9),928 0.0929 );930 world.addCollider(new BodyCollider(body, createRectShape(20, 1)));931932 // left wall933 body = world.createBody(934 Number.POSITIVE_INFINITY,935 Number.POSITIVE_INFINITY,936 vec2.fromValues(-10, 0),937 0.0938 );939 world.addCollider(new BodyCollider(body, createRectShape(1, 16)));940941 // right wall942 body = world.createBody(943 Number.POSITIVE_INFINITY,944 Number.POSITIVE_INFINITY,945 vec2.fromValues(10, 0),946 0.0947 );948 world.addCollider(new BodyCollider(body, createRectShape(1, 16)));949950 body = world.createBody(1.0, 1.0, vec2.fromValues(0, -8), 0.0);951 world.addCollider(new BodyCollider(body, createRectShape(3, 1)));952953 body = world.createBody(1.0, 1.0, vec2.fromValues(0, -7.0), 0.0);954 world.addCollider(new BodyCollider(body, createRectShape(1, 1))); ...

Full Screen

Full Screen

websocket.ts

Source:websocket.ts Github

copy

Full Screen

1import each from 'lodash-es/each';2import keys from 'lodash-es/keys';3import { OrderTemplate, makeOrder, makeAdvancedOrder, AdvancedOrderTemplate, makeCancelAdvancedOrder, CancelAdvancedOrderTemplate } from 'utils/trading';4let back: string;5if (process.env.NEXT_PUBLIC_LOCAL_DEV === '1') {6 back = 'ws://127.0.0.1:8084/';7} else if (process.env.NEXT_PUBLIC_LOCAL_DEV === '2') {8 back = 'ws://api.test.kollider.internal/v1/ws/';9} else if (process.env.NEXT_PUBLIC_LOCAL_DEV === '3') {10 back = 'ws://api.test.kollider.internal/v1/ws/';11} else {12 if (process.env.NEXT_PUBLIC_LOCAL_PROD === '1') {13 back = 'ws://10.0.2.213/v1/ws/';14 } else if (process.env.NEXT_PUBLIC_BACK_ENV === 'production') {15 back = 'wss://api.kollider.xyz/v1/ws/';16 // back = 'ws://api.staging.kollider.internal/v1/ws/';17 } else {18 back = 'ws://api.staging.kollider.internal/v1/ws/';19 // back = 'wss://api.kollider.xyz/v1/ws/';20 }21}22export const SOCKET_END_POINTS = Object.freeze({ BACK: back });23const UMBREL_URL = {24 DEV: 'ws://localhost:8080',25 // PROD: 'ws://localhost:8080',26 PROD: 'ws://umbrel.local:4345',27};28export const WS_UMBREL = {29 BASE: process.env.NEXT_PUBLIC_BACK_ENV === 'production' ? UMBREL_URL.PROD : UMBREL_URL.DEV,30 MESSAGES: {31 CREATE_INVOICE: {32 type: 'createInvoice',33 returnType: 'createInvoice',34 createBody: (params: any) => ({ ...params }),35 },36 SEND_PAYMENT: {37 type: 'sendPayment',38 returnType: 'sendPayment',39 createBody: (params: any) => ({ ...params }),40 },41 AUTHENTICATION: {42 type: 'authentication',43 returnType: 'authentication',44 createBody: (params: any) => ({ ...params }),45 },46 GET_NODE_INFO: {47 type: 'getNodeInfo',48 returnType: 'getNodeInfo',49 },50 GET_CHANNEL_BALANCE: {51 type: 'getChannelBalances',52 returnType: 'getChannelBalances',53 },54 GET_WALLET_BALANCE: {55 type: 'getWalletBalances',56 returnType: 'getWalletBalances',57 },58 AUTH_LNURL: {59 type: 'lnurlAuth',60 returnType: 'lnurlAuth',61 },62 GET_SYNTH_WALLETS: {63 type: 'getSynthWallets',64 returnType: 'getSynthWallets',65 },66 MAKE_CONVERSION: {67 type: 'makeConversion',68 returnType: 'makeConversion',69 createBody: (params: any) => ({ ...params }),70 },71 AUTH_HEDGER: {72 type: 'authHedger',73 returnType: 'authHedger',74 createBody: (params: any) => ({ ...params }),75 },76 CLOSE_ACCOUNT: {77 type: 'closeAccount',78 returnType: 'closeAccount',79 createBody: (params: any) => ({ ...params }),80 },81 GET_HISTORICAL_TRADES: {82 type: 'getHistoricalTrades',83 returnType: 'historicalTrades',84 createBody: (params: any) => ({ ...params }),85 },86 LOGOUT: {87 type: 'logout',88 returnType: 'logout',89 createBody: (params: any) => ({ ...params }),90 }91 },92};93const UMBREL_MESSAGE_TYPES = {} as Record<string, any>;94each(keys(WS_UMBREL.MESSAGES), v => (UMBREL_MESSAGE_TYPES[v] = v));95export { UMBREL_MESSAGE_TYPES };96export const CHANNEL_OPTIONS = {97 ORDERBOOK_LEVEL2: {98 customType: 'level2state',99 },100};101export enum CHANNELS {102 TICKER = 'ticker',103 ORDERBOOK_LEVEL2 = 'orderbook_level2',104 INDEX_VALUES = 'index_values',105 FUNDING_RATES = 'funding_rates',106 MARK_PRICE = 'mark_prices',107 POSITION_STATES = 'position_states',108 BALANCES = 'balances', // not really a channel but processed at the same place109}110export enum TRADING_TYPES {111 FILL = 'fill',112 TRADE = 'trade',113 ORDER_REJECTION = 'order_rejection',114 LIQUIDITY_BUILDING = 'liquidity_building',115 DONE = 'done',116 LIQUIDATIONS = 'liquidations',117 RECEIVED = 'received',118 ORDER_INVOICE = 'order_invoice',119 SETTLEMENT_REQUEST = 'settlement_request',120 DEPOSIT_REJECTION = 'deposit_rejection',121 DEPOSIT_SUCCESS = 'deposit_success',122 RAW_DEPOSIT = 'raw_deposit',123 WITHDRAWAL_SUCCESS = 'withdrawal_success',124 WITHDRAWAL_REJECTION = 'withdrawal_rejection',125 LNURL_WITHDRAWAL_REQUEST = 'lnurl_withdrawal_request',126 RAW_WITHDRAWAL = 'raw_withdrawal',127 ADL_NOTICE = 'adl_notice',128 WITHDRAWAL_LIMIT_INFO = 'withdrawal_limit_info',129 ADVANCED_ORDER_OPEN = 'advanced_order_open',130 ADVANCED_ORDER_DONE = 'advanced_order_done',131 USER_ADVANCED_ORDERS = 'user_advanced_orders',132}133export enum WS_CUSTOM_TYPES {134 LNURL_AUTH_CREDENTIALS = 'lnurl_auth_credentials',135 SUSPENDED_SYMBOL = 'suspended_symbol',136 SERVICE_STATUS_REPORT = 'service_status_report',137}138interface IWS {139 END_POINTS: typeof SOCKET_END_POINTS;140 MESSAGES: Record<141 string,142 {143 type: string;144 createBody?: (params: any) => any;145 refineType?: string;146 requiredBodyParams?: string[];147 }148 >;149 CHANNELS: typeof CHANNELS;150}151export enum UNUSED_TRADING_TYPES {152 OPEN_ORDERS = 'open_orders',153 USER_ADVANCED_ORDERS = 'user_advanced_orders', // also in advanced orders154}155export const WS: IWS = Object.freeze({156 END_POINTS: SOCKET_END_POINTS,157 MESSAGES: {158 ORDER: {159 type: 'order',160 createBody: (input: OrderTemplate) => ({ ...makeOrder(input) }),161 },162 ADVANCED_ORDER: {163 type: 'order',164 createBody: (input: AdvancedOrderTemplate) => ({ ...makeAdvancedOrder(input) }),165 },166 CANCEL_ADVANCED_ORDER: {167 type: 'cancel_advanced_order',168 createBody: (input: CancelAdvancedOrderTemplate) => ({ ...makeCancelAdvancedOrder(input) }),169 },170 SUBSCRIBE: {171 type: 'subscribe',172 createBody: (params: any) => ({ ...params }),173 requiredBodyParams: ['channels', 'symbols'],174 },175 UNSUBSCRIBE: {176 type: 'unsubscribe',177 createBody: (params: any) => ({ ...params }),178 requiredBodyParams: ['channels', 'symbols'],179 },180 AUTHENTICATE: {181 type: 'authenticate',182 createBody: (params: any) => ({ ...params }),183 requiredBodyParams: ['token'],184 },185 POSITIONS: {186 type: 'fetch_positions',187 createBody: (params: any) => ({ ...params }),188 refineType: 'positions',189 },190 BALANCES: {191 type: 'fetch_balances',192 createBody: (params: any) => ({ ...params }),193 },194 PRICE_TICKER: {195 type: 'fetch_price_ticker',196 createBody: (params: any) => ({ ...params }),197 },198 SETTLEMENT_REQUEST: {199 type: 'settlement_request',200 },201 WITHDRAWAL_REQUEST: {202 type: 'withdrawal_request',203 createBody: (params: any) => {204 if (params?.invoice)205 return {206 withdrawal_request: {207 Ln: {208 payment_request: params?.invoice,209 amount: params?.amount,210 },211 },212 };213 else214 return {215 withdrawal_request: {216 Ln: {217 amount: params?.amount,218 },219 },220 };221 },222 },223 SYMBOLS: {224 type: 'fetch_tradable_symbols',225 createBody: (params: any) => ({ ...params }),226 refineType: 'tradable_symbols',227 },228 LOGOUT: {229 type: 'logout',230 createBody: () => ({}),231 },232 WITHDRAWAL_LIMIT_INFO: {233 type: 'fetch_withdrawal_limit_info',234 createBody: () => ({}),235 },236 OPEN_ORDERS: {237 type: 'fetch_open_orders',238 createBody: params => ({ ...params }),239 },240 ADVANCED_ORDERS: {241 type: 'fetch_user_advanced_orders',242 createBody: () => ({}),243 refineType: 'user_advanced_orders',244 },245 },246 CHANNELS,247});248const MESSAGE_TYPES = {} as Record<string, string>;249each(keys(WS.MESSAGES), v => (MESSAGE_TYPES[v] = v));...

Full Screen

Full Screen

system.ts

Source:system.ts Github

copy

Full Screen

...21 resources = (userResources as Resource[]).map((res) => res.method + '-' + res.url)22 } else {23 resources = userResources24 }25 ctx.body = createBody({user, auth: {resources, menus: auth.menus}})26}27// 用户28async function searchUser(ctx) {29 const re = await Dao.User.findPaged(ctx.query)30 ctx.body = createBody(re)31}32async function saveUser(ctx) {33 const user = ctx.request.body34 await Dao.User.save(user)35 ctx.body = createBody()36}37async function delUser(ctx) {38 await Dao.User.delete(ctx.params.id)39 ctx.body = createBody()40}41async function getUser(ctx) {42 const id = ctx.params.id43 const re = await Dao.User.findOne({id})44 if (re) {45 ctx.body = createBody(re)46 } else {47 ctx.body = createBody(null, false, '暂无数据')48 }49}50async function viewUser(ctx) {51 const id = ctx.params.id52 const re = await Dao.User.viewUser({id})53 if (re) {54 ctx.body = createBody(re)55 } else {56 ctx.body = createBody(null, false, '暂无数据')57 }58}59// 菜单60async function menuTree(ctx) {61 const re = await Dao.Menu.findTrees()62 addParentId(re, null, 'sort')63 ctx.body = createBody(re)64}65async function saveMenu(ctx) {66 const menu = ctx.request.body67 const re = await Dao.Menu.saveMenu(menu)68 ctx.body = createBody(re)69}70async function delMenu(ctx) {71 await Dao.Menu.delete(ctx.params.id)72 ctx.body = createBody()73}74async function getMenu(ctx) {75 const id = ctx.params.id76 const re = await Dao.Menu.findOne({id})77 if (re) {78 re['parentId'] = re._parentId79 ctx.body = createBody(re)80 } else {81 ctx.body = createBody(null, false, '暂无数据')82 }83}84// 角色85async function searchRole(ctx) {86 const re = await Dao.Role.findPaged({...ctx.query, parentId: null}, {relations: ['children']})87 re.rows = re.rows.filter((role: any) => role.code !== 'admin')88 re.total--89 ctx.body = createBody(re)90}91async function saveRole(ctx) {92 await Dao.Role.save(ctx.request.body)93 ctx.body = createBody()94}95async function delRole(ctx) {96 await Dao.Role.delete(ctx.params.id)97 ctx.body = createBody()98}99async function getRole(ctx) {100 const id = ctx.params.id101 const re = await Dao.Role.findOne({id})102 if (re) {103 ctx.body = createBody(re)104 } else {105 ctx.body = createBody(null, false, '暂无数据')106 }107}108async function getRoleGroup(ctx) {109 const re = await Dao.Role.find({where: {isGroup: 1}})110 console.log(re)111 ctx.body = createBody(re)112}113async function getRoleChildren(ctx) {114 const re = await Dao.Role.find({parentId: ctx.params.id})115 ctx.body = createBody(re)116}117// 资源118async function searchResource(ctx) {119 const re = await Dao.Resource.findPaged(ctx.query)120 ctx.body = createBody(re)121}122async function saveResource(ctx) {123 await Dao.Resource.save(ctx.request.body)124 ctx.body = createBody()125}126async function delResource(ctx) {127 await Dao.Resource.delete(ctx.params.id)128 ctx.body = createBody()129}130async function getResource(ctx) {131 const id = ctx.params.id132 const re = await Dao.Resource.findOne({id})133 if (re) {134 ctx.body = createBody(re)135 } else {136 ctx.body = createBody(null, false, '暂无数据')137 }138}139// Dashboard140async function searchDashboard(ctx) {141 const re = await Dao.Dashboard.findPaged(ctx.query)142 ctx.body = createBody(re)143}144async function saveDashboard(ctx) {145 await Dao.Dashboard.save(ctx.request.body)146 ctx.body = createBody()147}148async function delDashboard(ctx) {149 await Dao.Dashboard.delete(ctx.params.id)150 ctx.body = createBody()151}152async function getDashboard(ctx) {153 const id = ctx.params.id154 const re = await Dao.Dashboard.findOne({id})155 if (re) {156 ctx.body = createBody(re)157 } else {158 ctx.body = createBody(null, false, '暂无数据')159 }160}161async function sortMenu(ctx) {162 await Dao.Menu.sortMenu(ctx.request.body)163 ctx.body = createBody()164}165export default (routes, prefix) => {166 // 获取权限167 routes.get(prefix + '/system/auth', getAuth)168 // 用户169 routes.get(prefix + '/system/user', searchUser)170 routes.put(prefix + '/system/user', saveUser)171 routes.delete(prefix + '/system/user/:id', delUser)172 routes.get(prefix + '/system/user/:id', getUser)173 // 菜单174 routes.get(prefix + '/system/menuTree', menuTree)175 routes.get(prefix + '/system/menu', menuTree)176 routes.put(prefix + '/system/menu', saveMenu)177 routes.post(prefix + '/system/menu', saveMenu)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log('Data: ' + JSON.stringify(data));7 }8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org');11 if (err) {12 console.log('Error: ' + err);13 } else {14 console.log('Data: ' + JSON.stringify(data));15 }16});17var wpt = require('webpagetest');18var wpt = new WebPageTest('www.webpagetest.org');19wpt.getTestResults('140801_5J_1S', function(err, data) {20 if (err) {21 console.log('Error: ' + err);22 } else {23 console.log('Data: ' + JSON.stringify(data));24 }25});26var wpt = require('webpagetest');27var wpt = new WebPageTest('www.webpagetest

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5wpt.createBody(options, function(err, data) {6 console.log(data);7});8var wpt = require('webpagetest');9var wpt = new WebPageTest('www.webpagetest.org');10var options = {11};12wpt.getLocations(options, function(err, data) {13 console.log(data);14});15var wpt = require('webpagetest');16var wpt = new WebPageTest('www.webpagetest.org');17var options = {18};19wpt.getTesters(options, function(err, data) {20 console.log(data);21});22var wpt = require('webpagetest');23var wpt = new WebPageTest('www.webpagetest.org');24var options = {25};26wpt.getLocations(options, function(err, data) {27 console.log(data);28});29var wpt = require('webpagetest');30var wpt = new WebPageTest('www.webpagetest.org');31var options = {32};33wpt.getTesters(options, function(err, data) {34 console.log(data);35});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('wpt');10var wpt = new WebPageTest('www.webpagetest.org');11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = require('wpt');18var wpt = new WebPageTest('www.webpagetest.org');19var params = {20};21 if (err) {22 console.log(err);23 } else {24 console.log(data);25 }26});27var wpt = require('wpt');28var wpt = new WebPageTest('www.webpagetest.org');29wpt.getLocations(function(err, data) {30 if (err) {31 console.log(err);32 } else {33 console.log(data);34 }35});36var wpt = require('wpt');37var wpt = new WebPageTest('www.webpagetest.org');38wpt.getTesters(function(err, data) {39 if (err) {40 console.log(err);41 } else {42 console.log(data);43 }44});45var wpt = require('wpt');46var wpt = new WebPageTest('www.webpagetest.org');47 if (err) {48 console.log(err);49 } else {50 console.log(data);51 }52});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var wp = new wptoolkit();3wp.createBody('Hello World!', function(err, body) {4 if (err) {5 console.log(err);6 }7 else {8 console.log(body);9 }10});11Contributions are welcome! Please see the [Contributing Guide](

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var options = {3};4var wpt = new wpt('API_KEY');5wpt.createTest(url, options, function(err, data) {6 if (err) {7 console.log(err);8 } else {9 console.log(data);10 }11});12MIT License (MIT)13Copyright (c) 2014 Rohan Chandra

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('webpagetest');2const wpt = new WebPageTest('www.webpagetest.org', 'A.9b1c9d0b0c9d0b0c9d0b0c9d0b0c9d0b');3 if (err) {4 console.error(err);5 } else {6 console.log(data);7 }8});9const wpt = require('webpagetest');10const wpt = new WebPageTest('www.webpagetest.org', 'A.9b1c9d0b0c9d0b0c9d0b0c9d0b0c9d0b');11wpt.getLocations((err, data) => {12 if (err) {13 console.error(err);14 } else {15 console.log(data);16 }17});18const wpt = require('webpagetest');19const wpt = new WebPageTest('www.webpagetest.org', 'A.9b1c9d0b0c9d0b0c9d0b0c9d0b0c9d0b');20wpt.getTesters((err, data) => {21 if (err) {22 console.error(err);23 } else {24 console.log(data);25 }26});27const wpt = require('webpagetest');28const wpt = new WebPageTest('www.webpagetest.org', 'A.9b1c9d0b0c9d0b0c9d0b0c9d0b0c9d0b');29wpt.getTestStatus('170927_8Y_3c3d9f4c5fa0f5f8b2d6b1a6b3c0f8e8', (err, data) => {30 if (err) {31 console.error(err);32 } else {33 console.log(data);34 }35});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var fs = require('fs');3var createBody = function() {4 var body = new wpt.Body();5 var html = new wpt.Html();6 var htmlContent = fs.readFileSync('test.html', 'utf8');7 html.setContent(htmlContent);8 body.setHtml(html);9 var text = new wpt.Text();10 var textContent = fs.readFileSync('test.txt', 'utf8');11 text.setContent(textContent);12 body.setText(text);13 return body;14};15var body = createBody();16console.log(body.toJSON());

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