I am currently using a webSocket to receive data from my server. I have created an rx Subject called MessageEvent that allows me to retrieve the data.
However, although I can successfully log the JSON data in my observable, I am unable to access any properties as they return undefined.
export interface Message {
request: string;
subscription: string,
}
@Injectable()
export class SocketProvider {
public message: Subject<Message>;
constructor(private socket: WebsocketProvider) {
console.log('Hello SocketProvider Provider');
this.message = <Subject<Message>>socket
.connect('ws://192.168.0.110:8081')
.map((response: MessageEvent): Message => {
let data = response.data;
return data;
})
}
}
Here is how it is used:
ionViewDidEnter() {
console.log('ionViewDidEnter ConfigsInputsPage');
this.subscribtion = this.socket.message.subscribe(msg => {
this.message = msg;
console.log("Response From webSocket server: " + msg);
console.log(msg.request);
});
this.socket.message.next(this.enterMessage);
}
private enterMessage = {
request: 'configs',
subscription: 'suscribe'
}