How to use network - 10 common examples

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 samuelmaddock / metastream / packages / metastream-app / src / analytics / index.ts View on Github external
const state = store.getState()
  const { allowTracking } = state.settings
  if (!allowTracking) {
    console.debug('Analytics tracking disabled')
    window.ga = () => {}
    return
  }

  const clientId = process.env.GA_CLIENT_ID
  if (!clientId) return

  // https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
  const analytics = new Analytics(clientId, {
    appName: PRODUCT_NAME,
    appVersion: VERSION,
    clientId: localUserId()
  })

  window.ga = (...args: any[]) => {
    try {
      analytics.send(...args)
    } catch (e) {
      console.error(e)
    } finally {
      // Reset session heartbeat timer; keeps number of heartbeats sent only to
      // what's absolutely necessary to keep the session alive.
      startSession(store)
    }
  }
}
github lwmqn / qnode / lib / mqtt-node.js View on Github external
EventEmitter.call(this);

    var self = this,
        transId = 0;

    this.clientId = clientId;
    this.lifetime = Math.floor(devAttrs.lifetime) || 86400;      // seconds
    this.ip = devAttrs.ip || null;
    this.mac = devAttrs.mac || null;
    this.version = devAttrs.version || '0.0.1';

    this.mc = null;     // mqtt client
    this.so = null;     // smart object

    if (!this.ip || !this.mac) {
        network.get_active_interface(function(err, info) {
            if (err) {
                self.emit('error', err);
            } else {
                self.ip = self.ip || info.ip_address;
                self.mac = self.mac || info.mac_address;
            }
        });
    }

    //----------- protected properties ---------------------
    this._rspsToResolve = {};

    this._pubics = {
        register: `register/${this.clientId}`,
        deregister: `deregister/${this.clientId}`,
        notify: `notify/${this.clientId}`,
github soaple / stickyboard / src / components / base / Layout.js View on Github external
readUserPermissionsCallback = (statusCode, response) => {
        switch (statusCode) {
        case StatusCode.OK:
            // console.log('---------------------')
            // console.log(response)

            var permissionKeyArray = [];

            response.forEach((adminPermission) => {
                var key = adminPermission.permission.key;
                permissionKeyArray.push(key);
            });

            // console.log(permissionKeyArray)
            this.setState({ permissionKeyArray: permissionKeyArray });
            break;
        case StatusCode.NOT_FOUND:
            break;
        default:
github samuelmaddock / metastream / packages / metastream-app / src / lobby / actions / user-init.ts View on Github external
avatar,
      color: info.color,
      pending: shouldAwaitAuthorization
    })
  )

  if (shouldAwaitAuthorization) {
    const content = translateEscaped('noticeUserRequestJoin', { userId: id, username: name })
    dispatch(addChat({ content, html: true, timestamp: Date.now() }))
    return ClientInitResponse.Pending
  }

  dispatch(authorizeClient(client))
  return ClientInitResponse.Ok
}
const server_initClient = rpc('initClient', RpcRealm.Server, initClient, {
  allowUnauthed: true
})

const authorizeClient = (client: NetConnection): AppThunkAction => {
  return async (dispatch, getState) => {
    const id = client.id.toString()
    dispatch(multi_userJoined(id))

    // Client has been fully authorized
    client.auth()

    dispatch(client_authorized({ serverTime: Date.now() })(id))
  }
}

const answerClient = (userId: string, allow: boolean): RpcThunk => (
github samuelmaddock / metastream / packages / metastream-app / src / lobby / actions / chat.ts View on Github external
}
        : undefined,
      content: text,
      timestamp: Date.now()
    })
  )

  // Clear user typing immediately if we received a message from them
  const typingTimeout = userId && userTypingTimeouts[userId]
  if (typingTimeout) {
    clearTimeout(typingTimeout)
    userTypingTimeouts[userId!] = undefined
    dispatch(clearTyping(userId!))
  }
}
export const multi_broadcastChat = rpc('broadcastChat', RpcRealm.Multicast, broadcastChat)

const rpcAddChat = (text: string): RpcThunk => (dispatch, getState, context) => {
  text = text.trim()
  if (text.length === 0) return false

  if (text.length > CHAT_MAX_MESSAGE_LENGTH) {
    text = text.substr(0, CHAT_MAX_MESSAGE_LENGTH)
  }

  const userId = context.client.id.toString()
  dispatch(multi_broadcastChat(text, userId))
  return true
}
const server_addChat = rpc('rpcAddChat', RpcRealm.Server, rpcAddChat)

export const sendChat = (text: string): AppThunkAction => {
github samuelmaddock / metastream / packages / metastream-app / src / components / lobby / VideoPlayer.tsx View on Github external
private get isPermittedBySafeBrowse() {
    const media = this.props.current

    // Always playback self-requested media
    if (media && media.ownerId === localUserId()) {
      return true
    }

    return this.props.safeBrowseEnabled
      ? this.state.permitURLOnce || SafeBrowse.getInstance().isPermittedURL(this.mediaUrl)
      : true
  }
github prey / prey-node-client / lib / agent / providers / network / index.js View on Github external
common = require('../../common'),
    status = require('./../../triggers/status'),
    logger = common.logger.prefix('network'),
    config = common.config,
    needle = require('needle');

var ap_list_callbacks = [],
    getting_ap_list   = false;

/////////////////////////////////////////////////////////////////
// getters
/////////////////////////////////////////////////////////////////

exp.get_public_ip = network.get_public_ip;

exp.get_private_ip = network.get_private_ip;

exp.get_gateway_ip = network.get_gateway_ip;

exp.get_active_network_interface = network.get_active_interface;

/////////////////////////////////////////////////////////////////
// wifi getters
/////////////////////////////////////////////////////////////////

/**
 * Callsback an array of wireless interface names
 **/
exp.get_wireless_interfaces_list = os_functions.get_wireless_interfaces_list;

exp.get_active_access_point_mac = os_functions.get_active_access_point_mac;
github soaple / stickyboard / src / components / base / Layout.js View on Github external
type: Const.NOTI_TYPE_WARNING,
                    title: 'CCU is too big!',
                    time: new Date(currentTimeMillis - Const.TIME_MILLIS_3_DAYS),
                },
            ],
            // Permission
            permissionKeyArray: [],
            // Drawer
            menuDrawerOpen: false,
            notiDrawerOpen: false,
            // Theme menu
            themeMenuAnchorElem: null,
            // User menu
            userMenuAnchorElem: null,
            // Auth
            auth: CookieManager.getCookie('userId') !== undefined,
            isSuperuser: CookieManager.getCookie('isSuperuser') === 'true',
        }
    }
github soaple / stickyboard / src / components / base / Layout.js View on Github external
title: 'CCU is too big!',
                    time: new Date(currentTimeMillis - Const.TIME_MILLIS_3_DAYS),
                },
            ],
            // Permission
            permissionKeyArray: [],
            // Drawer
            menuDrawerOpen: false,
            notiDrawerOpen: false,
            // Theme menu
            themeMenuAnchorElem: null,
            // User menu
            userMenuAnchorElem: null,
            // Auth
            auth: CookieManager.getCookie('userId') !== undefined,
            isSuperuser: CookieManager.getCookie('isSuperuser') === 'true',
        }
    }
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);
      });
    });
  }