Closed paragsahu closed 6 years ago
I try to publishing message to subscriber to the topic but unable to establish connection getting error please help me
this is my .ts file
import { Component, OnInit } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import "rxjs/Rx"; import {ChatRoom} from './ChatRoom.model'; import {Paho} from 'ng2-mqtt/mqttws31';
@Component({ selector: 'app-chat-window', templateUrl: './chat-window.component.html', styleUrls: ['./chat-window.component.css'] }) export class ChatWindowComponent implements OnInit { msg:any; showMessage:any; // chatRoom:ChatRoom={topic_Id:'',startTime:'',endTime:'',customer_Id:'',customerCare_Id:''}; chatRoom:any; client;
constructor(private http: HttpClient) { this.client = new Paho.MQTT.Client('localhost', 1883, 'qwerty12345');
this.onMessage(); this.onConnectionLost(); this.client.connect({onSuccess: this.onConnected.bind(this)});
}
searchValue:string = '';
ngOnInit() {
onConnected() { console.log("Connected"); this.client.subscribe("123456"); this.sendMessage('HelloWorld'); /onSuccess: onConnect, useSSL: true;/ }
sendMessage(message: string) { let packet = new Paho.MQTT.Message(message); packet.destinationName = "123456"; this.client.send(packet); }
onMessage() { this.client.onMessageArrived = (message: Paho.MQTT.Message) => { console.log('Message arrived : ' + message.payloadString); }; }
onConnectionLost() { this.client.onConnectionLost = (responseObject: Object) => { console.log('Connection lost : ' + JSON.stringify(responseObject)); }; }
createChatRoom(){ this.http.get('http://localhost:8080/api/create-chatroom') .subscribe(data=>{ this.chatRoom=data this.http.get('http://localhost:8080/api/subscribe-message/' + '5b7551de1fc582297d78bf0a') .subscribe(data=>{data }); }); }
publishMessage(topic) { console.log(this.msg); this.http.get('http://localhost:8080/api/publish-message/' + topic + "/" + this.msg) .subscribe(data=>{ }); // this.showMessage=this.msg; // this.msg=''; }
Please try to reproduce the issue without any wrapping modules, only ws. This issue tracker is for ws only.
Closing due to inactivity.
I try to publishing message to subscriber to the topic but unable to establish connection getting error please help me
this is my .ts file
import { Component, OnInit } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import "rxjs/Rx"; import {ChatRoom} from './ChatRoom.model'; import {Paho} from 'ng2-mqtt/mqttws31';
@Component({ selector: 'app-chat-window', templateUrl: './chat-window.component.html', styleUrls: ['./chat-window.component.css'] }) export class ChatWindowComponent implements OnInit { msg:any; showMessage:any; // chatRoom:ChatRoom={topic_Id:'',startTime:'',endTime:'',customer_Id:'',customerCare_Id:''}; chatRoom:any; client;
constructor(private http: HttpClient) { this.client = new Paho.MQTT.Client('localhost', 1883, 'qwerty12345');
}
searchValue:string = '';
ngOnInit() {
}
onConnected() { console.log("Connected"); this.client.subscribe("123456"); this.sendMessage('HelloWorld'); /onSuccess: onConnect, useSSL: true;/ }
sendMessage(message: string) { let packet = new Paho.MQTT.Message(message); packet.destinationName = "123456"; this.client.send(packet); }
onMessage() { this.client.onMessageArrived = (message: Paho.MQTT.Message) => { console.log('Message arrived : ' + message.payloadString); }; }
onConnectionLost() { this.client.onConnectionLost = (responseObject: Object) => { console.log('Connection lost : ' + JSON.stringify(responseObject)); }; }
createChatRoom(){ this.http.get('http://localhost:8080/api/create-chatroom') .subscribe(data=>{ this.chatRoom=data this.http.get('http://localhost:8080/api/subscribe-message/' + '5b7551de1fc582297d78bf0a') .subscribe(data=>{data
}); }); }
publishMessage(topic) { console.log(this.msg); this.http.get('http://localhost:8080/api/publish-message/' + topic + "/" + this.msg) .subscribe(data=>{ }); // this.showMessage=this.msg; // this.msg=''; }
}