How to use the network.on function in network

To help you get started, we’ve selected a few network examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / chicago-brick / demo_modules / particles / particles.js View on Github external
return peerNetwork.open(deadline).then((peer) => {
      debug('Connected to peer network.');
      this.peer_ = peer;
      const NeighborPersistence = require('client/network/neighbor_persistence');
      this.persistence_ = new NeighborPersistence(this.surface.virtualRectNoBezel, peer);
      network.on('newParticle', (newParticle) => {
        // When the server sends us something, it's definitely relevant.
        this.persistence_.addData(newParticle);
      });
    });
  }
github google / chicago-brick / demo_modules / hello_world / hello_world.js View on Github external
constructor(config) {
    super();
    
    debug('Hello, world!', config);
    this.color = config.color;
    this.nextColor = null;
    this.nextColorTime = 0;
    this.image = null;
    this.surface = null;

    var client = this;
    network.on('color', function handleColor(data) {
      debug('handle color', data);
      client.nextColor = data.color;
      client.nextColorTime = data.time;
    });
  }
github google / chicago-brick / demo_modules / tutorials / 03_colors / colors.js View on Github external
constructor() {
    super();
    this.color_ = 'black';
    this.nextColor_ = 'black';
    this.switchTime_ = Infinity;
    
    var self = this;
    network.on('colorChange', function handleColor(data) {
      self.nextColor_ = data.color;
      self.switchTime_ = data.time;
    });
  }