How to use onClientConnect method in Best

Best JavaScript code snippet using best

player-connections-tests.js

Source:player-connections-tests.js Github

copy

Full Screen

...46 getByDevice.restore();47 });48 describe('when a player connects', function () {49 beforeEach(done => {50 onClientConnect(undefined, player1, save1)51 .then(() => done())52 .catch(() => done());53 });54 it('should send an error if no player found');55 it('should send an error if more than one player per device');56 it('should send the device number', function () {57 expect(player1.emit.secondCall.args).toEqual(['deviceNumber', 1]);58 });59 it('should add a new player connection', function () {60 expect(connectedCount(save1.id)).toEqual(1);61 });62 it('should not emit a OnNewPlayer connection', function () {63 expect(fakeOn.newPlayer.called).toEqual(true);64 expect(fakeOn.newPlayer.firstCall.args).toEqual([save1, 1]);65 });66 it('should publish the players and their status in the game', function () {67 expect(fakeOn.playerGroupChange.firstCall.args).toEqual([[{ number: 1, status: 'online', playerId: 1, devices: [1], onSameSubnet: true}, {number: 2, status: 'not-joined', devices: [], onSameSubnet: true}, {number: 3, status: 'not-joined', devices: [], onSameSubnet: true}], 1]);68 });69 it('should partion players into games', function (done) {70 onClientConnect(undefined, player2, save1)71 .then(() => {72 expect(connectedCount(save1.id)).toEqual(2);73 })74 .then(() => onClientConnect(undefined, player1, save2) )75 .then(() => {76 expect(connectedCount(save2.id)).toEqual(1);77 })78 .then(() => done() )79 .catch(() => done() );80 });81 it('should start the update loop', function () {82 expect(startStatePusher.called).toEqual(true);83 });84 describe('when the same player connects again on a different client', function () {85 beforeEach(function (done) {86 fakeOn.playerGroupChange.reset();87 player1Device2.emit.reset();88 onClientConnect(undefined, player1Device2, save1)89 .then(() => done())90 .catch(() => done());91 });92 it('should not add a new player connection', function () {93 expect(connectedCount(save1.id)).toEqual(1);94 });95 it('should send a new device number', function () {96 expect(player1Device2.emit.secondCall.args).toEqual(['deviceNumber', 2]);97 });98 it('should indicate the player has two devices', function () {99 expect(fakeOn.playerGroupChange.firstCall.args[0][0].devices).toEqual([1, 11]);100 });101 it.skip('should determine if the clients are on the same subnet');102 it('should publish the players and their status in the game', function () {103 var callArgs = fakeOn.playerGroupChange.firstCall.args;104 expect(callArgs[0][0].number).toEqual(1);105 expect(callArgs[0][0].status).toEqual('online');106 expect(callArgs[0][0].playerId).toEqual(1);107 expect(callArgs[0][1]).toEqual(108 {number: 2, status: 'not-joined', devices: [], onSameSubnet: true}109 );110 expect(callArgs[0][2]).toEqual(111 {number: 3, status: 'not-joined', devices: [], onSameSubnet: true}112 );113 });114 describe('when the player disconnects their first device and then then tries to reconnect it', function () {115 beforeEach(function (done) {116 onClientDisconnect(undefined, player1, save1)117 .then(() => {118 fakeOn.playerGroupChange.reset();119 player1.emit.reset();120 })121 .then(() => onClientConnect(undefined, player1, save1))122 .then(() => done())123 .catch(() => done());124 });125 it('should not reuse the first connections device number', function () {126 expect(player1.emit.secondCall.args).toEqual(['deviceNumber', 3]);127 });128 });129 });130 describe('when a player disconnects', function () {131 beforeEach(function (done) {132 fakeOn.playerGroupChange.reset();133 onClientDisconnect(undefined, player1, save1)134 .then(() => done());135 });136 it('should publish the players and their status in the game', function () {137 expect(fakeOn.playerGroupChange.firstCall.args).toEqual([[{ number: 1, status: 'offline', playerId: 1, devices: [], onSameSubnet: true}, {number: 2, status: 'not-joined', devices: [], onSameSubnet: true}, {number: 3, status: 'not-joined', devices: [], onSameSubnet: true}], 1]);138 });139 it('should stop pushing state to that device', () => {140 expect(stopStatePusher.firstCall.args).toEqual([save1, 1, 1]);141 })142 it('should set the device to spare');143 });144 describe('when a player disconnects one of their devices', function () {145 beforeEach(function (done) {146 onClientConnect(undefined, player1Device2, save1)147 .then(() => {148 fakeOn.playerGroupChange.reset();149 return onClientDisconnect(undefined, player1, save1);150 })151 .then(() => done());152 });153 it('should not mark players as "offline" if they have at least one device connected', function () {154 expect(fakeOn.playerGroupChange.firstCall.args[0][0].number).toEqual(1);155 expect(fakeOn.playerGroupChange.firstCall.args[0][0].status).toEqual('online');156 expect(fakeOn.playerGroupChange.firstCall.args[0][0].playerId).toEqual(1);157 expect(fakeOn.playerGroupChange.firstCall.args[0][0].devices).toEqual([11]);158 expect(fakeOn.playerGroupChange.firstCall.args[0][1]).toEqual(159 {number: 2, status: 'not-joined', devices: [], onSameSubnet: true}160 );161 expect(fakeOn.playerGroupChange.firstCall.args[0][2]).toEqual(162 {number: 3, status: 'not-joined', devices: [], onSameSubnet: true}163 );164 });165 });166 describe('when the same player reconnects after disconnecting', function () {167 beforeEach(function (done) {168 fakeOn.newPlayer.reset();169 onClientDisconnect(undefined, player1, save1)170 .then(() => fakeOn.playerGroupChange.reset())171 .then(() => onClientConnect(undefined, player1, save1))172 .then(() => done())173 .catch(() => done());174 });175 it('should not add a new player connection', function () {176 expect(connectedCount(save1.id)).toEqual(1);177 });178 it('should not emit a OnNewPlayer connection', function () {179 expect(fakeOn.newPlayer.called).toEqual(false);180 });181 it('should publish the players and their status in the game', function () {182 expect(fakeOn.playerGroupChange.firstCall.args).toEqual([[183 { number: 1, status: 'online', playerId: 1, devices: [1], onSameSubnet: true},184 {number: 2, status: 'not-joined', devices: [], onSameSubnet: true},185 {number: 3, status: 'not-joined', devices: [], onSameSubnet: true}186 ], 1]);187 });188 });189 describe('when the maxPlayers is exceeded', function () {190 beforeEach(function (done) {191 onClientConnect(undefined, player1, save1)192 .then(() => getByDevice.returns(Bluebird.resolve([{id: 2}])))193 .then(() => onClientConnect(undefined, player2, save1))194 .then(() => getByDevice.returns(Bluebird.resolve([{id: 3}])))195 .then(() => onClientConnect(undefined, player3, save1))196 .then(() => done())197 .catch(() => done() );198 });199 it('should not add a new player connection', function () {200 expect(connectedCount(save1.id)).toEqual(3);201 });202 });203 });204 describe('when a second player connects', function () {205 beforeEach(function (done) {206 getByDevice.returns(Bluebird.resolve([{id: 1}]));207 onClientConnect(undefined, player1, save1)208 .then(() => fakeOn.playerGroupChange.reset())209 .then(() => getByDevice.returns(Bluebird.resolve([{id: 2}])))210 .then(() => onClientConnect(undefined, player2, save1))211 .then(() => done())212 .catch(() => done());213 });214 it('should publish the players and their status in the game', function () {215 expect(fakeOn.playerGroupChange.firstCall.args).toEqual([[{ number: 1, status: 'online', playerId: 1, devices: [1], onSameSubnet: true}, {number: 2, status: 'online', playerId: 2, devices: [2], onSameSubnet: true}, {number: 3, status: 'not-joined', devices: [], onSameSubnet: true}], 1]);216 });217 });218 describe('when the number of connected players gets above the minimum', function () {219 it('should set waitingForPlayers to false', function (done) {220 onClientConnect(undefined, player1, save1)221 .then(result => {222 expect(result).toEqual(['ensemble.waitingForPlayers', true]);223 })224 .then(() => onClientConnect(undefined, player2, save1) )225 .then(result => {226 expect(result).toEqual(['ensemble.waitingForPlayers', false]);227 })228 .then(() => done())229 .catch(() => done() );230 });231 });232 describe('when the number of connected players falls below the minimum', function () {233 it('should set waitingForPlayers to true', function (done) {234 onClientConnect(undefined, player1, save1)235 .then(result => {236 expect(result).toEqual(['ensemble.waitingForPlayers', true]);237 })238 .then(() => onClientConnect(undefined, player2, save1) )239 .then(result => {240 expect(result).toEqual(['ensemble.waitingForPlayers', false]);241 })242 .then(() => onClientDisconnect(undefined, player2, save1) )243 .then(result => {244 expect(result).toEqual(['ensemble.waitingForPlayers', true]);245 })246 .then(() => done())247 .catch(() => done());248 });249 });250 describe('connectedCount', function () {251 it('should count the number of online player connections', done => {252 onClientConnect(undefined, player1, save1)253 .then(() => onClientConnect(undefined, player2, save1) )254 .then(() => expect(connectedCount(save1.id)).toEqual(2))255 .then(() => done() )256 .catch(() => done() );257 });258 it('should keep each games player count separate', done => {259 onClientConnect(undefined, player1, save1)260 .then(() => onClientConnect(undefined, player1, save2))261 .then(() => onClientConnect(undefined, player2, save2))262 .then(() => {263 expect(connectedCount(save1.id)).toEqual(1);264 expect(connectedCount(save2.id)).toEqual(2);265 })266 .then(() => done() )267 .catch(() => done() );268 });269 });...

Full Screen

Full Screen

brokerSpec.js

Source:brokerSpec.js Github

copy

Full Screen

1// ## brokerSpec2// usage: $ DEBUG=brokerSpec mocha3const debug = require('debug')('mqtt-reqres-broker');4const assert = require('assert');5const MqttReqResBroker = require('../lib/mqtt-reqres-broker.js');6const mqtt = require('mqtt');7const serverOptions = {8 hostname: 'localhost',9 port: 999910};11const wsBroker = new MqttReqResBroker();12var mqttClientA, mqttClientB;13const clientAId = 'client-a', 14 clientBId = 'client-b';15const clientAChannelId = 'client-a-channel-id';16function pcatch (reason) {17 debug(reason);18 assert(!reason, reason);19}20function startServer (callback) {21 debug('startServer()');22 wsBroker.initialize(serverOptions, err => {23 if (err) {24 console.error(err.stack);25 callback(err);26 }27 else {28 29 wsBroker.start(null, err => {30 if (err) {31 console.error(err.stack);32 } 33 else {34 console.log(`broker running at http://${wsBroker.hostname}:${wsBroker.port}/`);35 } 36 callback(err);37 });38 39 }40 });41}42function connectClient (clientId) {43 return mqtt.connect({ 44 protocol: 'ws',45 host: serverOptions.hostname, 46 port: serverOptions.port,47 clientId: clientId || Math.random().toString(36).substr(2, 23)48 });49}50function onClientConnect (brokerClient) {51 assert.strictEqual(brokerClient.clientId, onClientConnect.mqttClient.clientId);52 setTimeout(() => {53 assert(onClientConnect.mqttClient.connected, 'mqtt client should be connected');54 onClientConnect.callbackFn();55 }, 100);56}57onClientConnect.configure = function (mqttClient, callbackFn) {58 onClientConnect.mqttClient = mqttClient;59 onClientConnect.callbackFn = callbackFn;60};61describe('broker', function () {62 before(done => {63 startServer(err => {64 wsBroker.mqtt.on('client', onClientConnect);65 done();66 });67 });68 after(done => {69 wsBroker.close(done);70 });71 describe('connecting mqtt clients to broker via websockets', () => {72 it('should connect to mqtt client A', done => {73 mqttClientA = connectClient(clientAId);74 onClientConnect.configure(mqttClientA, done);75 });76 it('should connect to mqtt client B', done => {77 mqttClientB = connectClient(clientBId);78 onClientConnect.configure(mqttClientB, done);79 });80 });81 describe('client subscriptions on topic "connect/<device-id>/+"', () => {82 it('should client A subscribe on topic "connect/' + clientAId + '/+"', done => {83 mqttClientA.subscribe(84 `connect/${clientAId}/+`, 85 {qos: 0}, 86 function (err, granted) {87 assert(!err);88 assert.strictEqual(granted[0].qos, 0);89 done();90 }91 );92 });93 it('should client B subscribe on topic "connect/' + clientBId + '/+"', done => {94 mqttClientA.subscribe(95 `connect/${clientBId}/+`, 96 {qos: 0}, 97 function (err, granted) {98 assert(!err);99 assert.strictEqual(granted[0].qos, 0);100 done();101 }102 );103 });104 it('should refuse to subscribe -t connect on invalid topics', done => {105 function promiseTest (topic) {106 return new Promise(function (resolve) {107 mqttClientA.subscribe(108 topic, 109 {qos: 0}, 110 function (err, granted) {111 assert(!err);112 assert(granted[0].qos > 2, 'should not have subscribed -t connect on topic ' + topic);113 resolve();114 }115 );116 }); 117 }118 Promise.all(119 [120 // `connect/${clientBId}/+`, 121 `invalid/${clientBId}/+`, 122 `connect`, 123 `connect/`, 124 `connect//`, 125 `connect/+`, 126 `connect/#`, 127 `connect/${clientBId}/#`, 128 `connect/${clientBId}/`, 129 `connect/${clientBId}`, 130 `connect/${clientBId}/+/invalid`,131 `connect/${clientBId}/invalid/+`132 ].map(promiseTest)133 )134 .then(() => done())135 .catch(pcatch);136 });137 });138 describe('connecting client A to client B', () => {139 it('should subscribe -t message/' + clientBId + '/' + clientAChannelId + '/# ', done => {140 /*141 open a message channel to enable client-a to send messages:142 143 subscribe -t message/<client-b-id>/<client-a-channel-id>/# 144 */145 mqttClientA.subscribe(146 `message/${clientBId}/${clientAChannelId}/#`, 147 {qos: 0}, 148 function (err, granted) {149 assert(!err);150 assert.strictEqual(granted[0].qos, 0);151 done();152 }153 );154 });155 it('should refuse to subscribe -t message on invalid topics', done => {156 function promiseTest (topic) {157 return new Promise(function (resolve) {158 mqttClientA.subscribe(159 topic, 160 {qos: 0}, 161 function (err, granted) {162 assert(!err);163 assert(granted[0].qos > 2, 'should not have subscribed -t message on topic ' + topic);164 resolve();165 }166 );167 }); 168 }169 Promise.all(170 [171 // `message/${clientBId}/${clientAChannelId}/#`, 172 `invalid/${clientBId}/${clientAChannelId}/#`, 173 `message`, 174 `message/`, 175 `message//`, 176 `message//+`, 177 `message/#`, 178 `message/${clientBId}/#`, 179 `message/${clientBId}/${clientAChannelId}/+`,180 `message/${clientBId}/${clientAChannelId}/+/bar`,181 `message/${clientBId}/${clientAChannelId}/foo/bar`,182 `message/from-client-id/`, 183 `message/from-client-id`, 184 `message/from-client-id/+`,185 `message/from-client-id/invalid/+`186 ].map(promiseTest)187 )188 .then(() => done())189 .catch(pcatch);190 });191 it(`should publish -t connect/${clientBId}/${clientAId} -m ${clientAChannelId}`, done => {192 /*193 client-a publishes client-a-channel-id as message to client-b:194 195 publish -t connect/<client-b-id>/<client-a-id> -m <client-a-channel-id> 196 */197 mqttClientA.publish(198 // topic199 `connect/${clientBId}/${clientAId}`, 200 // message201 clientAChannelId,202 // options203 {qos: 0}, 204 // callback205 function (err) {206 assert(!err);207 done();208 }209 );210 });211 });212 describe('sending messages between clients', () => {213 /*214 sending messages215 publish -t message/<from>/<to>216 publish -t message/<from-device-id>/<to-channel-id>217 publish -t message/<client-b-id>/<client-a-channel-id>/foo -m '{packetId:123}' 218 */219 it('should enable client B to send messages to client A', done => {220 mqttClientA.on('message', function (topic, payload) {221 if (topic === `message/${clientBId}/${clientAChannelId}/foo`) {222 assert.strictEqual(payload.toString(), 'bar'); 223 done();224 }225 });226 mqttClientB.publish(227 // topic228 `message/${clientBId}/${clientAChannelId}/foo`, 229 // message230 'bar',231 // options232 {qos: 0}233 );234 });235 });236 describe('unsubscription of clients', () => {237 it('should unsubscribe client A', done => {238 assert(mqttClientA.connected);239 mqttClientA.end(false, () => {240 241 assert(!mqttClientA.connected);242 243 mqttClientB.end(false, () => {244 done();245 });246 });247 });248 });...

Full Screen

Full Screen

BlokdotsSocketIOServer.js

Source:BlokdotsSocketIOServer.js Github

copy

Full Screen

1import { Server } from "socket.io";2import WebSocket from "ws";3import { networkInterfaces } from "os";4import setupHttpServer from "./setupHttpServer";5export const BLOKDOTS_SOCKET_IO_SERVER_DEFAULT_PORT = 8777;6export const getBlokdotsSocketIOServerAddress = () => {7 const currentIP = Object.values(networkInterfaces())8 .flat()9 .find((i) => i.family === "IPv4" && !i.internal).address;10 return `http://${currentIP}:${BLOKDOTS_SOCKET_IO_SERVER_DEFAULT_PORT}`;11};12class BlokdotsSocketIOServer {13 constructor() {14 this.activeIntegrations = {};15 this.io = null;16 }17 // Init is a separate function, because the constructor can18 // not be async19 async init() {20 return new Promise((resolve) => {21 this.start();22 resolve();23 });24 }25 start() {26 const httpServer = setupHttpServer();27 this.io = new Server(httpServer, {28 wsEngine: WebSocket.Server,29 pingInterval: 5000,30 pingTimeout: 5000,31 allowEIO3: true, // support older websocket clients32 cors: {33 origin: "*",34 methods: ["GET", "POST"],35 },36 });37 httpServer.listen(BLOKDOTS_SOCKET_IO_SERVER_DEFAULT_PORT, "0.0.0.0");38 // Sockets can connect to the general namespace to get updates about39 // all available integrations40 this.io.on("connection", (socket) => {41 // Updates are emitted whenever something about an integration changes,42 // but they can also be explicitely requested43 socket.on("requestInfo", () => {44 this.emitInfo(socket);45 });46 this.emitInfo(socket);47 });48 }49 emitInfo(socket) {50 // If no specific socket requested it, we send it to all51 // sockets in the general namespace52 if (!socket) socket = this.io.sockets;53 socket.emit("info", {54 url: getBlokdotsSocketIOServerAddress(),55 integrations: Object.values(this.activeIntegrations).map((i) => ({56 id: i.id,57 url: i.url,58 connections: i.ioNamespace.sockets.size,59 })),60 });61 }62 stop(callback) {63 this.io.closeServer(callback);64 }65 registerIntegration({66 integrationName,67 handlers = [],68 onClientConnect,69 onClientDisconnect,70 }) {71 let integration = this.activeIntegrations[integrationName];72 // The namespace already exists73 if (integration) {74 // Add the new handlers to the list of handlers to register for new connections75 integration.handlers = integration.handlers.concat(handlers);76 onClientConnect && integration.onClientConnect.push(onClientConnect);77 onClientDisconnect &&78 integration.onClientDisconnect.push(onClientDisconnect);79 // Register the new handlers on the already existing connections80 for (let [, socket] of integration.ioNamespace.sockets) {81 handlers.forEach(({ eventName, callback }) => {82 socket.on(eventName, callback);83 });84 }85 } else {86 // Initialize the namespace for the first time87 this.activeIntegrations[integrationName] = {88 id: integrationName,89 url: `${getBlokdotsSocketIOServerAddress()}/${integrationName}`,90 handlers: [...handlers],91 ioNamespace: this.io.of("/" + integrationName),92 onClientConnect: onClientConnect ? [onClientConnect] : [],93 onClientDisconnect: onClientDisconnect ? [onClientDisconnect] : [],94 };95 integration = this.activeIntegrations[integrationName];96 // When a new socket connects to this namespace97 integration.ioNamespace.on("connection", (socket) => {98 // console.info("🕹 Client connected to", integrationName);99 // We register all existing handlers to this new socket100 integration.handlers.forEach(({ eventName, callback }) => {101 socket.on(eventName, callback);102 });103 // We emit a message to all other sockets …104 integration.ioNamespace.emit("client-connect", {105 integration: integrationName,106 connections: integration.ioNamespace.sockets.size,107 });108 // … as well as to the integration registerers109 integration.onClientConnect.forEach((h) => {110 h({111 integration: integrationName,112 connections: integration.ioNamespace.sockets.size,113 });114 });115 this.emitInfo();116 socket.on("disconnect", (reason) => {117 // We emit a message to all other sockets …118 integration.ioNamespace.emit("client-disconnect", {119 reason: reason,120 integration: integrationName,121 connections: integration.ioNamespace.sockets.size,122 });123 // … as well as to the integration registerers124 integration.onClientDisconnect.forEach((h) => {125 h({126 reason: reason,127 integration: integrationName,128 connections: integration.ioNamespace.sockets.size,129 });130 });131 this.emitInfo();132 });133 });134 this.emitInfo();135 }136 return {137 ...integration,138 connections: integration.ioNamespace.sockets.size,139 };140 }141 unregisterIntegration({142 integrationName,143 handlers = [],144 onClientConnect,145 onClientDisconnect,146 }) {147 let integration = this.activeIntegrations[integrationName];148 if (!integration) {149 return;150 }151 // Remove the handlers from the list of handlers to register for new connections152 integration.handlers = integration.handlers.filter((h) =>153 handlers.some(154 (hU) => hU.eventName === h.eventName && hU.callback === h.callback155 )156 );157 integration.onClientConnect = integration.onClientConnect.filter(158 (h) => h !== onClientConnect159 );160 integration.onClientDisconnect = integration.onClientDisconnect.filter(161 (h) => h !== onClientDisconnect162 );163 // Remove the handlers from the existing connections164 for (let [, socket] of integration.ioNamespace.sockets) {165 handlers.forEach(({ eventName, callback }) => {166 socket.off(eventName, callback);167 });168 }169 // Nobody is listening anymore, remove the integration170 if (integration.handlers.length === 0) {171 integration.ioNamespace.disconnectSockets();172 delete this.activeIntegrations[integrationName];173 this.emitInfo();174 }175 }176}177let blokdotsSocketIOServer = null;178const getBlokdotsSocketIOServer = async () => {179 return new Promise((resolve) => {180 // If the server hasn’t been setup yet, do that, then resolve the promise181 if (blokdotsSocketIOServer === null) {182 blokdotsSocketIOServer = new BlokdotsSocketIOServer();183 blokdotsSocketIOServer.init().then(() => {184 resolve(blokdotsSocketIOServer);185 });186 } else {187 // Else resolve the promise with the existing server immediately188 resolve(blokdotsSocketIOServer);189 }190 });191};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1socket.OnConnect += (s, e) =>2{3 s.Emit("TestMessage", "Hello from the client");4};5socket.Open();6socket.OnConnect += (s, e) =>7{8 s.Emit("TestMessage", "Hello from the client");9};10socket.Open();11socket.OnConnect += (s, e) =>12{13 s.Emit("TestMessage", "Hello from the client");14};15socket.Open();16socket.OnConnect += (s, e) =>17{18 s.Emit("TestMessage", "Hello from the client");19};20socket.Open();21socket.OnConnect += (s, e) =>22{23 s.Emit("TestMessage", "Hello from the client");24};25socket.Open();26socket.OnConnect += (s, e) =>27{28 s.Emit("TestMessage", "Hello from the client");29};30socket.Open();

Full Screen

Using AI Code Generation

copy

Full Screen

1socket.OnConnect += (s) => {2 s.Emit("message", "hello from client");3};4socket.On("message", (s, p) => {5 Debug.Log(p.Json.Args[0].ToString());6});7socket.OnDisconnect += (s, e) => {8 Debug.Log("Disconnected: " + e.Message);9};10socket.OnError += (s, e) => {11 Debug.Log("Error: " + e.Message);12};13socket.OnReconnect += (s, e) => {14 Debug.Log("Reconnected!");15};16socket.OnReconnectAttempt += (s, e) => {17 Debug.Log("Reconnect attempt: " + e.Attempt);18};19socket.OnReconnectFailed += (s, e) => {20 Debug.Log("Reconnect failed: " + e.Message);21};22socket.OnReconnectError += (s, e) => {23 Debug.Log("Reconnect error: " + e.Message);24};25socket.OnReconnecting += (s, e) => {26 Debug.Log("Reconnecting: " + e.Attempt);27};

Full Screen

Using AI Code Generation

copy

Full Screen

1var ip = request.Headers["X-Forwarded-For"];2if (string.IsNullOrEmpty(ip))3{4 ip = request.UserHostAddress;5}6client.Send(ip);7var ip = request.Headers["X-Forwarded-For"];8if (string.IsNullOrEmpty(ip))9{10 ip = request.UserHostAddress;11}12client.Send(ip);13var ip = request.Headers["X-Forwarded-For"];14if (string.IsNullOrEmpty(ip))15{16 ip = request.UserHostAddress;17}18client.Send(ip);

Full Screen

Using AI Code Generation

copy

Full Screen

1function Start () {2 socket.onClientConnect += OnClientConnect;3 socket.onClientDisconnect += OnClientDisconnect;4 socket.onClientReconnect += OnClientReconnect;5}6function OnClientConnect() {7 socket.Emit("playerName", playerName);8}9function OnClientDisconnect() {10 socket.Emit("playerName", playerName);11}12function OnClientReconnect() {13 socket.Emit("playerName", playerName);14}15function Start () {16 socket.onClientConnect += OnClientConnect;17 socket.onClientDisconnect += OnClientDisconnect;18 socket.onClientReconnect += OnClientReconnect;19}20function OnClientConnect() {21 socket.Emit("playerName", playerName);22}23function OnClientDisconnect() {

Full Screen

Using AI Code Generation

copy

Full Screen

1using UnityEngine;2using System.Collections;3using BestHTTP.SocketIO;4using BestHTTP.SocketIO.Events;5public class test4 : MonoBehaviour {6 public SocketManager manager;7 void Start () {8 manager.Socket.On(SocketIOEventTypes.Connect, OnConnect);9 manager.Socket.On("message", OnMessage);10 manager.Socket.Open();11 }12 void OnConnect(Socket socket, Packet packet, params object[] args) {13 socket.Emit("message", "hello");14 }15 void OnMessage(Socket socket, Packet packet, params object[] args) {16 Debug.Log(args[0]);17 socket.Disconnect();18 }19}

Full Screen

Using AI Code Generation

copy

Full Screen

1function OnClientConnect(socketManager)2{3 socketManager.On("chat message", OnChatMessage);4 socketManager.On("user joined", OnUserJoined);5 socketManager.On("user left", OnUserLeft);6 socketManager.On("typing", OnTyping);7 socketManager.On("stop typing", OnStopTyping);8 socketManager.On("login", OnLogin);9 socketManager.On("num users", OnNumUsers);10}11function OnClientConnect(socketManager)12{13 socketManager.On("chat message", OnChatMessage);14 socketManager.On("user joined", OnUserJoined);15 socketManager.On("user left", OnUserLeft);16 socketManager.On("typing", OnTyping);17 socketManager.On("stop typing", OnStopTyping);18 socketManager.On("login", OnLogin);19 socketManager.On("num users", OnNumUsers);20}21function OnClientConnect(socketManager)22{23 socketManager.On("chat message", OnChatMessage);24 socketManager.On("user joined", OnUserJoined);25 socketManager.On("user left", OnUserLeft);26 socketManager.On("typing", OnTyping);27 socketManager.On("stop typing", OnStopTyping);28 socketManager.On("login", OnLogin);29 socketManager.On("num users", OnNumUsers);30}

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 Best 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