Best JavaScript code snippet using best
index.js
Source:index.js
...409function onSocketDisconnection(client) {410 util.log('socket disconnected: ' + client.id);411 onRemovedPlayer(this.broadcast, client.id)412}413function onDisconnectedClient() {414 util.log('player has disconnected: ' + this.id);415 onRemovedPlayer(this.broadcast, this.id)416}417function onJoinedNewPlayer({name, tourType}) {418 if (existsPlayer(this.id)) {419 util.log('this user has been logined.', {id: this.id});420 return;421 }422 util.log(`[New Player]`, {id: this.id, name, tourType});423 const _newPlayer = new Player({id: this.id, name, tourType});424 // å
¨å¡ã«ãã®ãã¬ã¤ã¤ã¼ã®ãã¨ãæãã425 this.broadcast.emit(events.JOIN_PLAYER, _newPlayer);426 // ãã¬ã¤ã¤ã¼ã«ä»ã®ãã¬ã¤ã¤ã¼ã®ãã¨ãæãã427 players.forEach(player => {...
game.js
Source:game.js
1// Snake by Patrick OReilly and Richard Davey2// Twitter: @pato_reilly Web: http://patricko.byethost9.com3var game = new Phaser.Game(4 window.screen.availWidth * window.devicePixelRatio,5 window.screen.availHeight * window.devicePixelRatio, 6 Phaser.CANVAS, 7 '#game', 8 { preload: preload, create: create, update: update,render : render }9 );10var players = {};11var num = 100;12var icon_index = 1;13var snakeSpacer = 10;14var socket;15var backgroundMusic;16var battleMusic;17var captureSound;18var SPAWN_PLAYER_SEPERATION = 200;19 20var ballColors = {1 : 'assets/pokomon/azumarill.png',21 2: 'assets/pokomon/charizard.png',22 3: 'assets/pokomon/pikachu.png',23 4: 'assets/pokomon/bulbasaur.png',24 5: 'assets/pokomon/camerupt.png',25 6: 'assets/pokomon/chansey.png',26 7: 'assets/pokomon/clefable.png',27 8: 'assets/pokomon/croconaw.png',28 9: 'assets/pokomon/dedenne.png',29 10: 'assets/pokomon/deoxys.png',30 11: 'assets/pokomon/gengar.png',31 12: 'assets/pokomon/golduck.png',32 13: 'assets/pokomon/golem.png',33 14: 'assets/pokomon/grotle.png',34 15: 'assets/pokomon/growlithe.png',35 16: 'assets/pokomon/ivysaur.png',36 17: 'assets/pokomon/purugly.png',37 18: 'assets/pokomon/quiladin.png',38 19: 'assets/pokomon/shiftry.png',39 20: 'assets/pokomon/slurpuff.png',40 21: 'assets/pokomon/snorlax.png',41 22: 'assets/pokomon/squirtle.png',42 23: 'assets/pokomon/teddiursa.png',43 24: 'assets/pokomon/wartortle.png',44 25: 'assets/pokomon/whirlipede.png',45 26: 'assets/pokomon/zhubat.png',46 27: 'assets/pokomon/starmie.png',47 28: 'assets/pokomon/mewtwo.png',48 29: 'assets/pokomon/gyarados.png',49 30: 'assets/pokomon/zapdos.png',50 31: 'assets/pokomon/electabuzz.png',51 32: 'assets/pokomon/caterpie.png',52 33: 'assets/pokomon/diglett.png',53 34: 'assets/pokomon/kecleon.png',54 35: 'assets/pokomon/dwebble.png',55 36: 'assets/pokomon/mew.png',56 37: 'assets/pokomon/swalot.png',57 38: 'assets/pokomon/slowpoke.png',58 39: 'assets/pokomon/simisage.png',59 40: 'assets/pokomon/onix.png',60 41: 'assets/pokomon/burmy.png',61 42: 'assets/pokomon/pansear.png',62 43: 'assets/pokomon/kangaskhan.png',63 44: 'assets/pokomon/tympole.png',64 45: 'assets/pokomon/seaking.png',65 46: 'assets/pokomon/goodra.png',66 47: 'assets/pokomon/dewott.png',67 48: 'assets/pokomon/riolu.png',68 49: 'assets/pokomon/hoppip.png',69 50: 'assets/pokomon/magby.png'70 71};72var targets = new LinkedList();73function preload() {74 // game.load.image(ballColors[1],'assets/orb-blue.png');75 // game.load.image(ballColors[2],'assets/orb-green.png');76 // game.load.image(ballColors[3],'assets/orb-red.png');77 // game.load.image(ballColors[4],'assets/orb-blue.png');78 // game.load.image(ballColors[5],'assets/orb-green.png');79 // game.load.image(ballColors[6],'assets/orb-red.png');80 // game.load.image(ballColors[7],'assets/orb-blue.png');81 // game.load.image(ballColors[8],'assets/orb-green.png');82 // game.load.image(ballColors[9],'assets/orb-red.png');83 // game.load.image(ballColors[10],'assets/orb-red.png');84 // game.load.image(ballColors[11],'assets/orb-blue.png');85 // game.load.image(ballColors[12],'assets/orb-green.png');86 // game.load.image(ballColors[13],'assets/orb-red.png');87 game.load.image(ballColors[1],'assets/pokomon/azumarill.png');88 game.load.image(ballColors[2],'assets/pokomon/charizard.png');89 game.load.image(ballColors[3],'assets/pokomon/pikachu.png');90 game.load.image(ballColors[4],'assets/pokomon/bulbasaur.png');91 game.load.image(ballColors[5],'assets/pokomon/camerupt.png');92 game.load.image(ballColors[6],'assets/pokomon/chansey.png');93 game.load.image(ballColors[7],'assets/pokomon/clefable.png');94 game.load.image(ballColors[8],'assets/pokomon/croconaw.png');95 game.load.image(ballColors[9],'assets/pokomon/dedenne.png');96 game.load.image(ballColors[10],'assets/pokomon/deoxys.png');97 game.load.image(ballColors[11],'assets/pokomon/gengar.png');98 game.load.image(ballColors[12],'assets/pokomon/golduck.png');99 game.load.image(ballColors[13],'assets/pokomon/golem.png');100 game.load.image(ballColors[14],'assets/pokomon/grotle.png');101 game.load.image(ballColors[15],'assets/pokomon/growlithe.png');102 game.load.image(ballColors[16],'assets/pokomon/ivysaur.png');103 game.load.image(ballColors[17],'assets/pokomon/purugly.png');104 game.load.image(ballColors[18],'assets/pokomon/quiladin.png');105 game.load.image(ballColors[19],'assets/pokomon/shiftry.png');106 game.load.image(ballColors[20],'assets/pokomon/slurpuff.png');107 game.load.image(ballColors[21],'assets/pokomon/snorlax.png');108 game.load.image(ballColors[22],'assets/pokomon/squirtle.png');109 game.load.image(ballColors[23],'assets/pokomon/teddiursa.png');110 game.load.image(ballColors[24],'assets/pokomon/wartortle.png');111 game.load.image(ballColors[25],'assets/pokomon/whirlipede.png');112 game.load.image(ballColors[26],'assets/pokomon/zhubat.png');113 game.load.image(ballColors[27],'assets/pokomon/starmie.png');114 game.load.image(ballColors[28],'assets/pokomon/mewtwo.png');115 game.load.image(ballColors[29],'assets/pokomon/gyarados.png');116 game.load.image(ballColors[30],'assets/pokomon/zapdos.png');117 game.load.image(ballColors[31],'assets/pokomon/electabuzz.png');118 game.load.image(ballColors[32],'assets/pokomon/caterpie.png');119 game.load.image(ballColors[33],'assets/pokomon/diglett.png');120 game.load.image(ballColors[34],'assets/pokomon/kecleon.png');121 game.load.image(ballColors[35],'assets/pokomon/dwebble.png');122 game.load.image(ballColors[36],'assets/pokomon/mew.png');123 game.load.image(ballColors[37],'assets/pokomon/swalot.png');124 game.load.image(ballColors[38],'assets/pokomon/slowpoke.png');125 game.load.image(ballColors[39],'assets/pokomon/simisage.png');126 game.load.image(ballColors[40],'assets/pokomon/onix.png');127 game.load.image(ballColors[41],'assets/pokomon/burmy.png');128 game.load.image(ballColors[42],'assets/pokomon/pansear.png');129 game.load.image(ballColors[43],'assets/pokomon/kangaskhan.png');130 game.load.image(ballColors[44],'assets/pokomon/tympole.png');131 game.load.image(ballColors[45],'assets/pokomon/seaking.png');132 game.load.image(ballColors[46],'assets/pokomon/goodra.png');133 game.load.image(ballColors[47],'assets/pokomon/dewott.png');134 game.load.image(ballColors[48],'assets/pokomon/riolu.png');135 game.load.image(ballColors[49],'assets/pokomon/hoppip.png');136 game.load.image(ballColors[50],'assets/pokomon/magby.png');137 game.load.audio('backgroundMusic', 'assets/music/PokemonMainTheme.mp3');138 game.load.audio('captureSoundEffect', 'assets/music/PokemonCapture.mp3');139 game.load.audio('battleMusic', 'assets/music/PokemonBattle.mp3');140 game.load.image('background', 'assets/mario.jpg');141 142}143function getAlivePlayers() 144{145 var alivePlayers = Object.keys(players).map(function(playerKey) {146 if(players[playerKey].snakeHead.alive === true);147 return(playerKey);148 });149 return(alivePlayers);150}151function createNewPlayer(id,name,ballColorString,location)152{153 var snakeHead = generateSnakeHeadForPlayer(location,ballColorString, name);154 var snakeSection = new Array();155 var snakePath = new Array();156 var playerObject = createPlayerObject(name,ballColorString,snakeHead,snakeSection,snakePath);157 // var playerObject = createPlayerObject(name,ballColorString);158 players[id] = playerObject;159}160function generateSnakeHeadForPlayer(location,ballColorString, name)161{162 var snakeHead = game.add.sprite(location.x, location.y, ballColorString);163 var playerLabelStyle = { font: "30px Arial", fill: "#ffffff", align: "center" }; 164 var label_name = game.add.text(0, -42, name, playerLabelStyle);165 label_name.anchor.set(0.5);166 snakeHead.addChild(label_name);167 snakeHead.anchor.setTo(0.5, 0.5);168 game.physics.enable(snakeHead, Phaser.Physics.ARCADE);169 snakeHead.body.collideWorldBounds = true;170 //snakeHead.body.bounce.set(2);171 return snakeHead;172}173function createPlayerObject(name,ballColorString,snakeHead,snakeSection,snakePath)174{175 return({name: name, ballColor: ballColorString, snakeHead: snakeHead, snakeSection: snakeSection, snakePath: snakePath});176}177function createCollisionDetection()178{179 var playerKeyArray = Object.keys(players);180 for(x=0; x < playerKeyArray.length; x+=1)181 {182 for(y=(x+1); y < playerKeyArray.length; y+=1)183 {184 game.physics.arcade.collide(players[playerKeyArray[x]].snakeHead, players[playerKeyArray[y]].snakeHead, collisionCallback,null,this);185 }186 }187}188function getAllPlayers(playerObj) {189 var allplayers = {};190 for(var id in playerObj){191 var playertemp = playerObj[id];192 var player = {name: playertemp.name, ballColor: playertemp.ballColor};193 allplayers[id] = player;194 // console.log(newplayers);195 }196return allplayers;197 198}199function create() {200 backgroundMusic = this.game.add.audio('backgroundMusic');201 captureSound = this.game.add.audio('captureSoundEffect');202 battleMusic = this.game.add.audio('battleMusic');203 backgroundMusic.volume = 0.3;204 captureSound.volume = 2;205 backgroundMusic.loop = true;206 battleMusic.loop = true;207 backgroundMusic.play();208 background = game.add.tileSprite(0, 0, 1920, 1200, "background");209 socket = io.connect();210 game.physics.startSystem(Phaser.Physics.ARCADE);211 game.world.setBounds(0, 0,212 window.screen.availWidth * window.devicePixelRatio, 213 window.screen.availHeight * window.devicePixelRatio);214 cursors = game.input.keyboard.createCursorKeys();215 216 //console log all of the players in the game217 Object.keys(players).forEach(key => { 218 console.log(players[key].name);219 });220 setEventHandlers();221}222var setEventHandlers = function () {223 // socket.emit('player created', onNewPlayerfunction); 224 socket.on('new player', onNewPlayerfunction);225 socket.on('move', onMove);226 socket.on('disconnected client',onDisconnectedClient);227}228var onDisconnectedClient = function (data) {229 // console.log(data.client_id); 230 // console.log("client id: ",targets.findNode(data.client_id));231 // if (targets.findNode(data.client_id) !== undefined)232 // {233 targets.deleteNode(data.client_id);234 var snakeBodySprites = players[data.client_id].snakeSection;235 snakeBodySprites.forEach(body => { 236 body.kill();237 });238 var snakeHead = players[data.client_id].snakeHead.kill();239 var trg = targets.flattenTargets(); 240 var allplayerobj = getAllPlayers(players);241 242 socket.emit('targets', {trg: trg, allplayerobj: allplayerobj}); 243 // }244}245var onMove = function (movement_data) {246 //debugger;247 // console.log('controller id from game: ' + movement_data.controller_id);248 // console.log('controller x from game: ' + movement_data.deltaX);249 // console.log('controller y from game: ' + movement_data.deltaY);250 players[movement_data.controller_id].snakeHead.body.velocity.setTo(movement_data.deltaX*5,movement_data.deltaY*5);251} 252function generateRandomPointGivenSeperation(x,y,seperation)253{254 do {255 genRandX = game.world.randomX;256 genRandY = game.world.randomY;257 } while(((Math.abs(genRandX - x) < seperation) && (Math.abs(genRandX - x) < seperation)))258 return new Phaser.Point(genRandX, genRandY);259}260function generatePlayerSpawnPoint()261{262 if(targets._length == 0) {263 return new Phaser.Point(game.world.randomX, game.world.randomY);264 }else if(targets._length == 1) {265 // console.log(players[targets.head.data].snakeHead.x);266 // console.log(players[targets.head.data].snakeHead.y);267 return(generateRandomPointGivenSeperation(players[targets.head.data].snakeHead.x,players[targets.head.data].snakeHead.y,SPAWN_PLAYER_SEPERATION));268 } else {269 var phaserPoint;270 do {271 phaserPoint = generateRandomPointGivenSeperation(players[targets.head.data].snakeHead.x,players[targets.head.data].snakeHead.y,SPAWN_PLAYER_SEPERATION);272 } while( (Math.abs((players[targets.tail.data].snakeHead.x - phaserPoint.x)) < SPAWN_PLAYER_SEPERATION) && (Math.abs((players[targets.tail.data].snakeHead.y - phaserPoint.y)) < SPAWN_PLAYER_SEPERATION));273 // console.log(players[targets.head.data].snakeHead.x);274 // console.log(players[targets.head.data].snakeHead.y);275 // console.log(players[targets.head.data].snakeHead.x);276 // console.log(players[targets.head.data].snakeHead.y);277 return(phaserPoint);278 } 279 280 281}282var onNewPlayerfunction = function(data) {283 console.log("new player socket called");284 var spawnPoint = generatePlayerSpawnPoint();285 console.log(spawnPoint.x,spawnPoint.y);286 //createNewPlayer(data.game_player_id, data.game_player_name, ballColors[icon_index],new Phaser.Point(game.world.randomX, game.world.randomY));287 createNewPlayer(data.game_player_id, data.game_player_name, ballColors[icon_index],spawnPoint);288 targets.insertNodeAtTail(data.game_player_id);289 290 var trg = targets.flattenTargets(); 291 var allplayerobj = getAllPlayers(players);292 socket.emit('targets', {trg: trg, allplayerobj: allplayerobj});293 if(targets._length > 2) {294 if (backgroundMusic.isPlaying) {295 backgroundMusic.stop();296 battleMusic.play();297 }298 }299 // num += 50;300 icon_index += 1;301}302function update() {303 Object.keys(players).forEach(key => { 304 //players[key].snakeHead.body.velocity.setTo(0, 0);305 //players[key].snakeHead.body.angularVelocity = 0;306 //players[key].snakeHead.body.velocity.copyFrom(game.physics.arcade.velocityFromAngle(players[key].snakeHead.angle, 300));307 //Part of the slither animation308 if (players[key].snakeSection.length > 0 && players[key].snakeHead.alive === true) {309 310 var part = players[key].snakePath.pop();311 part.setTo(players[key].snakeHead.x, players[key].snakeHead.y);312 players[key].snakePath.unshift(part);313 for (var i = 0; i < players[key].snakeSection.length; i++)314 {315 players[key].snakeSection[i].x = (players[key].snakePath[(i+1) * snakeSpacer]).x;316 players[key].snakeSection[i].y = (players[key].snakePath[(i+1) * snakeSpacer]).y;317 }318 }319 });320 321 createCollisionDetection();322}323function getPlayerKeyFromSnakeHead(snakeHead)324{325 var playerKey;326 Object.keys(players).forEach(key => {327 if (players[key].snakeHead === snakeHead) {328 playerKey = key;329 }330 });331 return playerKey;332}333function appendSnakeSection(sectionKey, sectionToAppendKey)334{335 //Ugly code need to clean up336 var snakePathToAppend = [];337 var snakePathToAppend2 = [];338 var sectionObj = players[sectionKey];339 var sectionToAppendObj = players[sectionToAppendKey];340 captureSound.play();341 //-----duplicate sectionTobeAppended-----342 //add the snake head343 var copyOfSnakeHead = game.add.sprite(sectionToAppendObj.snakeHead.x,sectionToAppendObj.snakeHead.y,sectionToAppendObj.snakeHead.key);344 copyOfSnakeHead.scale.setTo(0.6, 0.6);345 copyOfSnakeHead.anchor.setTo(0.2,0.2);346 347 sectionObj.snakeSection.push(copyOfSnakeHead);348 for(var i = 0; i <= (snakeSpacer*(1+sectionToAppendObj.snakeSection.length)); i++)349 {350 snakePathToAppend[i] = new Phaser.Point(sectionToAppendObj.snakeHead.x,sectionToAppendObj.snakeHead.y);351 }352 sectionObj.snakePath = sectionObj.snakePath.concat(snakePathToAppend);353 for(var x = 0; x < sectionToAppendObj.snakeSection.length; x++)354 {355 var section = game.add.sprite(sectionToAppendObj.snakeHead.x, sectionToAppendObj.snakeHead.y,sectionToAppendObj.snakeSection[x].key);356 snakePathToAppend2[x] = new Phaser.Point(sectionToAppendObj.snakeHead.x,sectionToAppendObj.snakeHead.y);357 section.scale.setTo(0.6, 0.6);358 section.anchor.setTo(0.2,0.2);359 sectionObj.snakeSection.push(section);360 sectionToAppendObj.snakeSection[x].kill();361 }362 sectionObj.snakePath = sectionObj.snakePath.concat(snakePathToAppend2);363 sectionToAppendObj.snakeHead.kill();364}365function collisionCallback(snakeHead1, snakeHead2) 366{367 var game_player_id_one = getPlayerKeyFromSnakeHead(snakeHead1);368 var game_player_id_two = getPlayerKeyFromSnakeHead(snakeHead2);369 game_player_one_node = targets.findNode(game_player_id_one);370 game_player_two_node = targets.findNode(game_player_id_two);371 if(targets._length > 2) {372 if(game_player_one_node.next.data == game_player_id_two)373 {374 targets.deleteNode(game_player_id_two);375 appendSnakeSection(game_player_id_one, game_player_id_two);376 // var trg = targets.flattenTargets(); 377 // socket.emit('targets', trg);378 var trg = targets.flattenTargets(); 379 var allplayerobj = getAllPlayers(players);380 socket.emit('targets', {trg: trg, allplayerobj: allplayerobj});381 }else if(game_player_two_node.next.data == game_player_id_one) {382 targets.deleteNode(game_player_id_one);383 appendSnakeSection(game_player_id_two, game_player_id_one)384 385 // var trg = targets.flattenTargets(); 386 // socket.emit('targets', trg);387 var trg = targets.flattenTargets(); 388 var allplayerobj = getAllPlayers(players);389 socket.emit('targets', {trg: trg, allplayerobj: allplayerobj}); 390 }391 } 392 if(targets._length < 3) {393 if (battleMusic.isPlaying) {394 battleMusic.stop();395 backgroundMusic.play();396 }397 }398}399function render() {...
dashboard.ts
Source:dashboard.ts
...90 if (!this.clients.find((client) => client.clientId === clientId)) {91 this.clients.push({ ...newClient });92 }93 }94 onDisconnectedClient(clientId: string) {95 const pos = this.clients.findIndex((c: any) => c.id === clientId);96 this.clients.splice(pos, 1);97 const jobIndex = this.jobs.findIndex(j => j.clientId === clientId);98 if (jobIndex > -1) {99 this.jobs.splice(jobIndex, 1);100 }101 }102 onQueuedClient(...args: any) {103 console.log(BEST_RPC.AGENT_QUEUED_CLIENT, args);104 }105 onBenchmarkStart(bStart: BenchmarkStartEnd) {106 console.log(BEST_RPC.BENCHMARK_START, bStart);107 const agent = this.agents.find(a => a.agentId === bStart.agentId);108 const client = this.clients.find(c => c.clientId === bStart.clientId);...
Using AI Code Generation
1importClass(Packages.java.io.File);2importClass(Packages.java.io.FileInputStream);3importClass(Packages.java.io.FileOutputStream);4importClass(Packages.java.io.IOException);5importClass(Packages.java.io.InputStream);6importClass(Packages.java.io.OutputStream);7importClass(Packages.java.io.RandomAccessFile);8importClass(Packages.java.io.Serializable);9importClass(Packages.java.lang.ClassNotFoundException);10importClass(Packages.java.lang.Integer);11importClass(Packages.java.lang.Object);12importClass(Packages.java.lang.String);13importClass(Packages.java.lang.System);14importClass(Packages.java.lang.Thread);15importClass(Packages.java.net.InetAddress);16importClass(Packages.java.net.InetSocketAddress);17importClass(Packages.java.net.Socket);18importClass(Packages.java.net.SocketAddress);19importClass(Packages.java.net.SocketException);20importClass(Packages.java.net.SocketTimeoutException);21importClass(Packages.java.net.UnknownHostException);22importClass(Packages.java.util.ArrayList);23importClass(Packages.java.util.HashMap);24importClass(Packages.java.util.Iterator);25importClass(Packages.java.util.Map);26importClass(Packages.java.util.Set);27importClass(Packages.java.util.Vector);28importClass(Packages.org.bestpeer.cache.Cache);29importClass(Packages.org.bestpeer.cache.CacheEntry);30importClass(Packages.org.bestpeer.cache.CacheException);31importClass(Packages.org.bestpeer.cache.CacheFactory);32importClass(Packages.org.bestpeer.cache.CacheManager);33importClass(Packages.org.bestpeer.cache.CacheManagerFactory);34importClass(Packages.org.bestpeer.cache.CacheManagerListener);35importClass(Packages.org.bestpeer.cache.CacheManagerListenerAdapter);36importClass(Packages.org.bestpeer.cache.CacheManagerListenerException);37importClass(Packages.org.bestpeer.cache.CacheManagerListenerFactory);38importClass(Packages.org.bestpeer.cache.CacheManagerListenerType);39importClass(Packages.org.bestpeer.cache.CacheType);40importClass(Packages.org.bestpeer.cache.FileCache);41importClass(Packages.org.bestpeer.cache.FileCacheEntry);42importClass(Packages.org.bestpeer.cache.FileCacheFactory);43importClass(Packages.org.bestpeer.cache.FileCacheManager);44importClass(Packages.org.bestpeer.cache.FileCacheManagerFactory);45importClass(Packages.org.bestpeer.cache.FileCacheManagerListener);46importClass(Packages.org.bestpeer.cache.FileCacheManagerListenerAdapter);47importClass(Packages.org.bestpeer.cache.FileCacheManagerListenerException);48importClass(Packages.org.bestpeer.cache.FileCacheManagerListenerFactory);49importClass(Packages.org.bestpeer.cache.File
Using AI Code Generation
1var BestPeerServer = require('bestpeer').BestPeerServer;2var server = new BestPeerServer();3server.onDisconnectedClient(function(client) {4 console.log("Client " + client.peerId + " disconnected");5});6server.start();7var BestPeerServer = require('bestpeer').BestPeerServer;8var server = new BestPeerServer();9server.onConnectedClient(function(client) {10 console.log("Client " + client.peerId + " connected");11});12server.start();13var BestPeerServer = require('bestpeer').BestPeerServer;14var server = new BestPeerServer();15server.onReceivedMessage(function(client, message) {16 console.log("Client " + client.peerId + " sent " + message);17});18server.start();19var BestPeerServer = require('bestpeer').BestPeerServer;20var server = new BestPeerServer();21server.onReceivedMessage(function(client, message) {22 console.log("Client " + client.peerId + " sent " + message);23});24server.start();25var BestPeerServer = require('bestpeer').BestPeerServer;26var server = new BestPeerServer();27server.onReceivedMessage(function(client, message) {28 console.log("Client " + client.peerId + " sent " + message);29});30server.start();31var BestPeerServer = require('bestpeer').BestPeerServer;32var server = new BestPeerServer();33server.onReceivedMessage(function(client, message) {34 console.log("Client " + client.peerId + " sent " + message);35});36server.start();37var BestPeerServer = require('bestpeer').BestPeerServer;
Using AI Code Generation
1var BestPeer = require('./bestpeer').BestPeer;2var bp = new BestPeer();3bp.onDisconnectedClient(function (client) {4 console.log('Client disconnected: ' + client.id);5});6bp.start();7var BestPeer = require('./bestpeer').BestPeer;8var bp = new BestPeer();9bp.onNewClient(function (client) {10 console.log('New client connected: ' + client.id);11});12bp.start();13var BestPeer = require('./bestpeer').BestPeer;14var bp = new BestPeer();15bp.onNewClient(function (client) {16 console.log('New client connected: ' + client.id);17});18bp.start();19var BestPeer = require('./bestpeer').BestPeer;20var bp = new BestPeer();21bp.onNewClient(function (client) {22 console.log('New client connected: ' + client.id);23});24bp.start();25var BestPeer = require('./bestpeer').BestPeer;26var bp = new BestPeer();27bp.onNewClient(function (client) {28 console.log('New client connected: ' + client.id);29});30bp.start();31var BestPeer = require('./bestpeer').BestPeer;32var bp = new BestPeer();33bp.onNewClient(function (client) {34 console.log('New client connected: ' + client.id);35});36bp.start();37var BestPeer = require('./bestpeer').BestPeer;38var bp = new BestPeer();39bp.onNewClient(function (client) {40 console.log('New client connected: ' + client.id);41});42bp.start();43var BestPeer = require('./bestpeer').BestPeer;44var bp = new BestPeer();45bp.onNewClient(function (client) {46 console.log('New client connected: ' + client.id);47});48bp.start();
Using AI Code Generation
1var BestPeer = require('bestpeer');2var peer = new BestPeer();3peer.onDisconnectedClient(function(client) {4 console.log('Client disconnected: ' + client);5});6peer.connect(9000);7var BestPeer = require('bestpeer');8var peer = new BestPeer();9peer.onNewClient(function(client) {10 console.log('New client: ' + client);11});12peer.connect(9000);13var BestPeer = require('bestpeer');14var peer = new BestPeer();15peer.onNewMessage(function(message) {16 console.log('New message: ' + message);17});18peer.connect(9000);19var BestPeer = require('bestpeer');20var peer = new BestPeer();21peer.onNewMessageFromClient(function(message, client) {22 console.log('New message from client: ' + message);23});24peer.connect(9000);25var BestPeer = require('bestpeer');26var peer = new BestPeer();27peer.onNewMessageFromGroup(function(message, group) {28 console.log('New message from group: ' + message);29});30peer.connect(9000);31var BestPeer = require('bestpeer');32var peer = new BestPeer();33peer.onNewMessageFromTopic(function(message, topic) {34 console.log('New message from topic: ' + message);35});36peer.connect(9000);37var BestPeer = require('bestpeer');38var peer = new BestPeer();39peer.onNewMessageFromTopicGroup(function(message, topic, group) {
Using AI Code Generation
1var BestClient = require('./BestClient.js');2var client = new BestClient();3client.onDisconnectedClient = function() {4 console.log('Disconnected from the server');5}6client.onConnectedClient = function() {7 console.log('Connected to the server');8}9client.onMessageReceived = function(message) {10 console.log('Received message: ' + message);11}12client.connect('localhost', 1337);13client.send('Hello from client');14var net = require('net');15var BestClient = function() {16 this._client = null;17 this._onConnectedClient = null;18 this._onDisconnectedClient = null;19 this._onMessageReceived = null;20}21BestClient.prototype.connect = function(host, port) {22 this._client = net.connect(port, host, function() {23 if (this._onConnectedClient) {24 this._onConnectedClient();25 }26 }.bind(this));27 this._client.on('data', function(data) {28 if (this._onMessageReceived) {29 this._onMessageReceived(data.toString());30 }31 }.bind(this));32 this._client.on('end', function() {33 if (this._onDisconnectedClient) {34 this._onDisconnectedClient();35 }36 }.bind(this));37}38BestClient.prototype.send = function(message) {39 this._client.write(message);40}41BestClient.prototype.onConnectedClient = function(callback) {42 this._onConnectedClient = callback;43}44BestClient.prototype.onDisconnectedClient = function(callback) {45 this._onDisconnectedClient = callback;46}47BestClient.prototype.onMessageReceived = function(callback) {48 this._onMessageReceived = callback;49}50module.exports = BestClient;
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!