How to use remoteClient method in Best

Best JavaScript code snippet using best

remote_client.js

Source:remote_client.js Github

copy

Full Screen

1/* Copyright 2015 Floens2Licensed under the Apache License, Version 2.0 (the "License");3you may not use this file except in compliance with the License.4You may obtain a copy of the License at5 http://www.apache.org/licenses/LICENSE-2.06Unless required by applicable law or agreed to in writing, software7distributed under the License is distributed on an "AS IS" BASIS,8WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.9See the License for the specific language governing permissions and10limitations under the License. */11(function(global) {12'use strict';13var msgpack = require('msgpack-js');14var ws = require('ws');15global.RemoteClient = function(server, socket, id) {16 this.server = server;17 this.socket = socket;18 this.messageQueue = [];19 this.id = id;20 this.others = [];21 this.posDirty = false;22 this.lastReceiveTime = 0;23 this.x = 0;24 this.y = 0;25 this.stateDirty = false;26 this.down = false;27 this.nameDirty = true;28 this.name = this.generateName();29 this.colorDirty = true;30 this.color = this.generateColor();31 var self = this;32 if (this.socket != null) {33 this.socket.on('message', function(message) {34 try {35 self.handleMessages(Protocol.decode(msgpack.decode(message)));36 } catch (err) {37 log('Decode error: ' + err);38 }39 });40 }41}42RemoteClient.prototype.init = function() {43 this.server.process();44}45RemoteClient.prototype.destroy = function() {46 this.server.process();47}48RemoteClient.prototype.sendMessage = function(message) {49 this.messageQueue.push(message);50}51RemoteClient.prototype.flush = function() {52 if (this.messageQueue.length > 0 && this.socket != null) {53 if (this.socket.readyState == ws.OPEN) {54 this.socket.send(msgpack.encode(Protocol.encode(this.messageQueue)));55 this.messageQueue = [];56 } else {57 log('Error sending message: socket closed');58 }59 }60}61RemoteClient.prototype.handleMessages = function(messages) {62 for (var i = 0; i < messages.length; i++) {63 var message = messages[i];64 if (message instanceof PositionPacket) {65 // todo filter66 this.x = message.x;67 this.y = message.y;68 this.posDirty = true;69 this.server.process();70 } else if (message instanceof MouseStatePacket) {71 this.down = message.down;72 this.stateDirty = true;73 this.server.process();74 } else if (message instanceof NamePacket) {75 var receivedName = message.name.substr(0, Config.MAX_NAME_LENGTH).trim();76 if (receivedName.length > 0) {77 var name = receivedName;78 var tries = 0;79 while (this.isNameUsed(name) && tries++ < 50) {80 name = receivedName + '_';81 }82 this.name = name;83 this.nameDirty = true;84 this.server.process();85 }86 }87 }88}89RemoteClient.prototype.postProcess = function() {90 this.posDirty = false;91 this.stateDirty = false;92 this.nameDirty = false;93 this.colorDirty = false;94 this.flush();95}96RemoteClient.prototype.process = function() {97 var newlyCreated = [];98 var connections = this.server.getClients();99 // Creates on remote100 for (var i = 0; i < connections.length; i++) {101 var other = connections[i];102 if (other === this) continue;103 if (this.others.indexOf(other) < 0) {104 this.sendMessage(new CreatePacket(other.id));105 newlyCreated.push(other);106 this.others.push(other);107 }108 }109 // Deletes on remote110 for (var i = 0; i < this.others.length; i++) {111 var other = this.others[i];112 if (connections.indexOf(other) < 0) {113 this.sendMessage(new DestroyPacket(other.id));114 this.others.remove(other);115 }116 }117 // State updates118 for (var i = 0; i < this.others.length; i++) {119 var other = this.others[i];120 var newly = newlyCreated.indexOf(other) >= 0;121 if (newly || other.posDirty) {122 this.sendMessage(new PositionPacket(other.id, other.x, other.y));123 }124 if (newly || other.stateDirty) {125 this.sendMessage(new MouseStatePacket(other.id, other.down));126 }127 if (newly || other.nameDirty) {128 this.sendMessage(new NamePacket(other.id, other.name));129 }130 if (newly || other.colorDirty) {131 this.sendMessage(new ColorPacket(other.id, other.color));132 }133 }134 // Self state updates135 if (this.nameDirty) {136 this.sendMessage(new NamePacket(0, this.name));137 }138 if (this.colorDirty) {139 this.sendMessage(new ColorPacket(0, this.color));140 }141}142RemoteClient.prototype.isNameUsed = function(name) {143 for (var i = 0; i < this.others.length; i++) {144 if (this.others[i].name === name) {145 return true;146 }147 }148 return false;149}150RemoteClient.prototype.generateName = function() {151 var generatedName = Config.DEFAULT_NAME;152 var index = 0;153 var tries = 0;154 var name = generatedName + randomInt(1000);155 while (this.isNameUsed(name) && tries++ < 50) {156 name = generatedName + ++index;157 }158 return name;159}160RemoteClient.prototype.generateColor = function() {161 return randomInt(0xffffff);162}...

Full Screen

Full Screen

ActivityBase.js

Source:ActivityBase.js Github

copy

Full Screen

1/**2 * @typedef {import('../../peerful/PeerfulConnection.js').PeerfulConnection} PeerfulConnection3 */4/**5 * 6 * @typedef LocalClient7 * @property {Array<RemoteServer>} remotes8 * 9 * @typedef LocalServer10 * @property {Array<RemoteClient>} remotes11 * 12 * @typedef RemoteClient13 * @property {PeerfulConnection} connection14 * 15 * @typedef RemoteServer16 * @property {PeerfulConnection} connection17 */18export class ActivityBase {19 /**20 * @abstract21 * @param {LocalServer} localServer22 */23 static onLocalServerCreated(localServer) {}24 /**25 * @abstract26 * @param {LocalClient} localClient27 */28 static onLocalClientCreated(localClient) {}29 30 /**31 * @abstract32 * @param {LocalServer} localServer33 */34 static onLocalServerDestroyed(localServer) {}35 /**36 * @abstract37 * @param {LocalClient} localClient38 */39 static onLocalClientDestroyed(localClient) {}40 /**41 * @abstract42 * @param {LocalClient} localClient 43 * @param {RemoteServer} remoteServer 44 */45 static onRemoteServerConnected(localClient, remoteServer) {}46 /**47 * @abstract48 * @param {LocalServer} localServer 49 * @param {RemoteClient} remoteClient 50 */51 static onRemoteClientConnected(localServer, remoteClient) {}52 /**53 * @abstract54 * @param {LocalClient} localClient 55 * @param {RemoteServer} remoteServer 56 */57 static onRemoteServerDisconnected(localClient, remoteServer) {}58 /**59 * @abstract60 * @param {LocalServer} localServer 61 * @param {RemoteClient} remoteClient 62 */63 static onRemoteClientDisconnected(localServer, remoteClient) {}64 65 /**66 * @abstract67 * @param {LocalClient} localClient 68 * @param {RemoteServer} remoteServer 69 * @param {string} messageType70 * @param {object} messageData71 * @returns {boolean}72 */73 static onRemoteServerMessage(localClient, remoteServer, messageType, messageData) {74 return false;75 }76 /**77 * @abstract78 * @param {LocalServer} localServer 79 * @param {RemoteClient} remoteClient 80 * @param {string} messageType81 * @param {object} messageData82 * @returns {boolean}83 */84 static onRemoteClientMessage(localServer, remoteClient, messageType, messageData) {85 return false;86 }87 /**88 * @abstract89 * @param {LocalClient} localClient 90 * @param {RemoteServer} remoteServer 91 * @param {number} now92 */93 static onRemoteServerNanny(localClient, remoteServer, now) {}94 /**95 * @abstract96 * @param {LocalServer} localServer 97 * @param {RemoteClient} remoteClient 98 * @param {number} now99 */100 static onRemoteClientNanny(localServer, remoteClient, now) {}...

Full Screen

Full Screen

test.js

Source:test.js Github

copy

Full Screen

1const chai = require('chai');2const expect = chai.expect;3const HypergateMqtt = require('../index');4const mqtt = require('mqtt');5const Hypergate = require('@josefransaenz/hypergate-core');6function logger(hypergate) {7 hypergate.onAny(function(event, value) {8 console.log(`*** Event: ${event}, *** Payload: ${JSON.stringify(value)}.`);9 })10}11const baseTopic = 'f1/ap1'; 12const hypergate = new Hypergate({ routines: { testRoutine: {}}});13const client = new HypergateMqtt(hypergate, baseTopic, 'mqtt://test.mosquitto.org'); 14client.on('connect', () => { 15 console.log('local connected');16}); 17describe('hypergate-mqtt', function() {18 after(() => {19 client.end();20 hypergate.stop(); 21 })22 it('should sent and receive the status', function(done) {23 this.timeout(0);24 const remoteClient = mqtt.connect('mqtt://test.mosquitto.org');25 26 remoteClient.on('message', (topic, message) => {27 if (topic === (baseTopic + '/event/hypergate/status/request/done')) {28 let payload = JSON.parse(message.toString());29 expect(payload).to.have.all.keys('version', 'routines', 'services', 'tasks');30 remoteClient.end(); 31 done(); 32 }33 console.log('topic: ' + topic + '. msg: ' + message.toString())34 });35 remoteClient.on('connect', () => {36 console.log('remote connected');37 remoteClient.subscribe(baseTopic + '/event/hypergate/status/request/done'); 38 remoteClient.publish(baseTopic + '/command/hypergate/status/request', JSON.stringify({ greet: 'hi' })); 39 });40 })41 it('should respond to the status command', function(done) {42 this.timeout(0);43 const remoteClient = mqtt.connect('mqtt://test.mosquitto.org');44 45 remoteClient.on('message', (topic, message) => {46 if (topic === (baseTopic + '/event/routines/testRoutine/error')) {47 remoteClient.end(); 48 done(); 49 }50 console.log('topic: ' + topic + '. msg: ' + message.toString())51 });52 remoteClient.on('connect', () => {53 console.log('remote connected');54 remoteClient.subscribe(baseTopic + '/event/routines/testRoutine/error'); 55 remoteClient.publish(baseTopic + '/command/routines/testRoutine/start'); 56 });57 })...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var bestRemoteClient = require('best-remote-client');2var remoteClient = bestRemoteClient.remoteClient;3console.log(remoteClient());4var bestRemoteClient = require('best-remote-client');5var remoteClient = bestRemoteClient.remoteClient;6console.log(remoteClient());7var bestRemoteClient = require('best-remote-client');8var remoteClient = bestRemoteClient.remoteClient;9console.log(remoteClient());10var bestRemoteClient = require('best-remote-client');11var remoteClient = bestRemoteClient.remoteClient;12console.log(remoteClient());13var bestRemoteClient = require('best-remote-client');14var remoteClient = bestRemoteClient.remoteClient;15console.log(remoteClient());16var bestRemoteClient = require('best-remote-client');17var remoteClient = bestRemoteClient.remoteClient;18console.log(remoteClient());19var bestRemoteClient = require('best-remote-client');20var remoteClient = bestRemoteClient.remoteClient;21console.log(remoteClient());22var bestRemoteClient = require('best-remote-client');23var remoteClient = bestRemoteClient.remoteClient;24console.log(remoteClient());25var bestRemoteClient = require('best-remote-client');26var remoteClient = bestRemoteClient.remoteClient;27console.log(remoteClient());28var bestRemoteClient = require('best-remote-client');29var remoteClient = bestRemoteClient.remoteClient;30console.log(remoteClient());

Full Screen

Using AI Code Generation

copy

Full Screen

1var bestRemoteClient = require('./bestRemoteClient');2var bestRemoteClient = new bestRemoteClient.BestRemoteClient();3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log('Data: ' + data);7 }8});9var http = require('http');10function BestRemoteClient() {11 this.remoteClient = function(url, callback) {12 http.get(url, function(res) {13 var data = '';14 res.on('data', function(chunk) {15 data += chunk;16 });17 res.on('end', function() {18 callback(null, data);19 });20 }).on('error', function(err) {21 callback(err, null);22 });23 }24}25exports.BestRemoteClient = BestRemoteClient;

Full Screen

Using AI Code Generation

copy

Full Screen

1var bestBuy = require('bestbuy')(apiKey);2var product = bestBuy.products('(search=apple&active=true)', {show: 'sku,name,salePrice,regularPrice', pageSize: 1, page: 1, format: 'json'});3product.then(function(data) {4 console.log(data);5});6var bestBuy = require('bestbuy')(apiKey);7var product = bestBuy.products('(search=apple&active=true)', {show: 'sku,name,salePrice,regularPrice', pageSize: 1, page: 1, format: 'json'});8product.then(function(data) {9 console.log(data);10});11var bestBuy = require('bestbuy')(apiKey);12var product = bestBuy.products('(search=apple&active=true)', {show: 'sku,name,salePrice,regularPrice', pageSize: 1, page: 1, format: 'json'});13product.then(function(data) {14 console.log(data);15});16var bestBuy = require('bestbuy')(apiKey);17var product = bestBuy.products('(search=apple&active=true)', {show: 'sku,name,salePrice,regularPrice', pageSize: 1, page: 1, format: 'json'});18product.then(function(data) {19 console.log(data);20});21var bestBuy = require('bestbuy')(apiKey);22var product = bestBuy.products('(search=apple&active=true)', {show: 'sku,name,salePrice,regularPrice', pageSize: 1, page: 1, format: 'json'});23product.then(function(data) {24 console.log(data);25});26var bestBuy = require('bestbuy')(apiKey);27var product = bestBuy.products('(search=apple&active=true)', {show: 'sku,name,salePrice,regularPrice', pageSize: 1, page: 1, format: 'json'});28product.then(function(data) {29 console.log(data);30});

Full Screen

Using AI Code Generation

copy

Full Screen

1var remote = require('remote');2client.use('BestBuy');3client.BestBuy.getStores('area(55402,25)&format=json&show=longName,city,distance,phone,storeType', function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var remoteStorage = require('remotestoragejs');11remoteStorage.access.claim('BestBuy', 'rw');12remoteStorage.displayWidget();13remoteStorage.caching.enable('/BestBuy/');14remoteStorage.defineModule('BestBuy', function(privateClient, publicClient) {15 return {16 exports: {17 getStores: function(params, callback) {18 privateClient.get('BestBuy').get(params).then(function(data) {19 callback(null, data);20 }, function(err) {21 callback(err);22 });23 }24 }25 };26});27remoteStorage.BestBuy.getStores('area(55402,25)&format=json&show=longName,city,distance,phone,storeType').then(function(data) {28 console.log(data);29}, function(err) {30 console.log(err);31});32{ stores: 33 [ { longName: 'Richfield',34 phone: '(612) 861-1140',35 storeType: 'Big Box' },36 { longName: 'Minneapolis',37 phone: '(612) 823-8000',38 storeType: 'Big Box' },39 { longName: 'Minneapolis',40 phone: '(612)

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestBuy = require('bestbuy');2var bestbuy = new BestBuy('your api key here');3bestbuy.stores({show: 'total'}, function(err, data) {4 if (err) {5 console.error(err);6 } else {7 console.log('Total stores in the US: ' + data.total);8 }9});10{ total: 1000,11 [ { storeType: 'Big Box',

Full Screen

Using AI Code Generation

copy

Full Screen

1var remoteClient = require('./remoteClient');2var storeList = require('./storeList');3var store = require('./store');4var zipCode = 98104;5remoteClient.getStores(zipCode, function(err, data) {6 if (err) {7 console.log(err);8 } else {9 console.log(data);10 var stores = storeList.createStoreList(data);11 console.log(stores);12 }13});14var remoteClient = require('./remoteClient');15var storeList = require('./storeList');16var store = require('./store');17var zipCode = 98104;18remoteClient.getStores(zipCode, function(err, data) {19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 var stores = storeList.createStoreList(data);24 console.log(stores);25 var store = stores.getStore(1);26 console.log(store);27 }28});29var remoteClient = require('./remoteClient');30var storeList = require('./storeList');31var store = require('./store');32var zipCode = 98104;33remoteClient.getStores(zipCode, function(err, data) {34 if (err) {35 console.log(err);36 } else {37 console.log(data);38 var stores = storeList.createStoreList(data);39 console.log(stores);40 var store = stores.getStore(1);41 console.log(store);42 console.log(store.getStoreName());43 }44});45var remoteClient = require('./remoteClient');46var storeList = require('./storeList');47var store = require('./store');48var zipCode = 98104;49remoteClient.getStores(zipCode, function(err, data) {50 if (err) {

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