I do not know why you need the connect
method , but here is one approach
export class WebsocketService {
getSocket() {
// this function should only return this.socket when it is available
if (!this.socket || (this.socket && this.socket.disconnected)) {
this.socket = new Promise((resolve, reject) => {
const token = sessionStorage.getItem('token');
const s = io('http://localhost:3000', { query: { token: token } });
s.on('connect', () => {
console.log(socket.connected); // true
resolve(s);
});
s.on('disconnect', () => {
console.log(socket.disconnect); // true
reject(s);
});
});
}
return this.socket;
}
}
Then, usage is:
service.getSocket().then(socket => {
// Use the socket
});
Or with async/await:
const socket = await service.getSocket();
// Use the socket
I have 5 high charts on my page and I need series label in only one of the charts. But the moment I include series-label.js , it adds series label to all charts. Also how do I change the color of ...
I have 5 high charts on my page and I need series label in only one of the charts. But the moment I include series-label.js , it adds series label to all charts. Also how do I change the color of ...
Is it possible to have facet to return as an object instead of an array? It seems a bit counter intuitive to need to access result[0].total instead of just result.total code (using mongoose): ...
Is it possible to have facet to return as an object instead of an array? It seems a bit counter intuitive to need to access result[0].total instead of just result.total code (using mongoose): ...
So i have a object like this: let obj = {'0': {x: 25, y: 12}, '1': {x:55, y:6} ,...} Now How can I push an other object like {x: 12, y: 15} in to this object?
So i have a object like this: let obj = {'0': {x: 25, y: 12}, '1': {x:55, y:6} ,...} Now How can I push an other object like {x: 12, y: 15} in to this object?
I have a small bug in my small coding playground and I just can't find any solution to my error after hours of struggling. I simply want to create an object of a Post class in a app.js file (required ...
I have a small bug in my small coding playground and I just can't find any solution to my error after hours of struggling. I simply want to create an object of a Post class in a app.js file (required ...