Issue
I have set up a simple WebSocket server in go, and when i try to connect to the server in postman: (ws://localhost:3000/ws), it works without any problems. But when i do the same in angular:
import { HttpClient } from '@angular/common/http';
import { Injectable, signal } from '@angular/core';
import { Observable } from 'rxjs';
import { io } from 'socket.io-client';
import { environment } from 'src/environments/environment.development';
import { userdata } from 'src/interfaces/interfaces';
import { webSocket, WebSocketSubject } from 'rxjs/webSocket';
@Injectable({
providedIn: 'root'
})
export class CheckloginService {
private socket$ = webSocket(`${environment.websocket_url}/ws`);
constructor(private http: HttpClient) {
console.log("Connect to WebSocket")
}
socket = io(`${environment.api_url}/user`) // this remained from an old api, will be removed later
isLoggedIn() {
...
}
getUserData() {
...
}
}
I checked the network tab, nothing,
Checked the console, nothing
Help would be appreciated, thanks!
Solution
Observable are lazy most of the time, you need to subscribe to them to fire the connection.
webSocket(`${environment.websocket_url}/ws`).subscribe(...);
Answered By - Matthieu Riegler
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.