MQTT работает только в одном устройстве - PullRequest
0 голосов
/ 22 января 2020

Я сделал Ioni c PWA mqtt, который публикуется через веб-сокет, но когда я развертываю приложение (я использую AWS), оно работает только в Google Chrome, если я тестирую его в в окне Incognito оно не работает.

В консоли отображается эта ошибка на всех неработающих устройствах (ПК / моб.):

bSocket connection to ' ws: //test.mosquitto.org: 8081 / 'не удалось: ошибка во время рукопожатия WebSocket: net :: ERR_CONNECTION_RESET

Ниже мой javascript Иони c код

import { Component } from '@angular/core';
import { MQTTService } from 'ionic-mqtt';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {

  private _mqttClient: any;
  temp = 19;

  private MQTT_CONFIG: {
    host: string,
    port: number,
    clientId: string,
    path: string,
  } = {
    host: "test.mosquitto.org",
    port: 8081,
    clientId: "qeekljeqe" + Math.floor(Math.random()*100),
    path: "/",
  };

  private TOPIC: string[] = [];

  constructor(private _mqttService: MQTTService) {
  }

  ngOnInit() {
    this._mqttClient = this._mqttService.loadingMqtt(this._onConnectionLost, this._onMessageArrived, this.TOPIC, this.MQTT_CONFIG);
  }

  private _onConnectionLost(responseObject) {
    // connection listener
    // ...do actions when connection lost
    console.log('_onConnectionLost', responseObject);
  }

  private _onMessageArrived(message) {
    // message listener
    // ...do actions with arriving message
    console.log('message', message);  
}
public publishMessage(TOPICO : string, VALOR : string) {
  console.log('publishMessage')
  this._mqttService.publishMessage(TOPICO, VALOR);
}
...