initClient()

in client/src/lib/iot-client.js [52:85]


  initClient(options) {
    const clientId = `chat-user-${Math.floor((Math.random() * 1000000) + 1)}`;

    this.client = DeviceSdk.device({
      region: options.region || Config.awsRegion,

      // AWS IoT Host endpoint
      host: options.host || Config.awsIotHost,

      // clientId created earlier
      clientId: options.clientId || clientId,

      // Connect via secure WebSocket
      protocol: options.protocol || 'wss',

      // Set the maximum reconnect time to 500ms; this is a browser application
      // so we don't want to leave the user waiting too long for reconnection after
      // re-connecting to the network/re-opening their laptop/etc...
      baseReconnectTimeMs: options.baseReconnectTimeMs || 250,
      maximumReconnectTimeMs: options.maximumReconnectTimeMs || 500,

      // Enable console debugging information
      debug: (typeof options.debug === 'undefined') ? true : options.debug,

      // AWS access key ID, secret key and session token must be
      // initialized with empty strings
      accessKeyId: options.accessKeyId || '',
      secretKey: options.secretKey || '',
      sessionToken: options.sessionToken || '',

      // Let redux handle subscriptions
      autoResubscribe: (typeof options.debug === 'undefined') ? false : options.autoResubscribe,
    });
  }