I know its an old question , For me none of the solutions worked so I solved with below approach.
Do Not Waste your time if your socket connection polling is working fine and not getting any error , It might be due to the socket.io.client package conflict with your other setup
my application version are below.
Angular 12.x Socket.io.client 4.x Node 14.16.1
I also tried with ngx-socket-io package too that also didn't work. the strange part is socket.io poling works well hand shaking are correct but not able to listen the event on new messages.
So my final approach is adding socket.io manully to index.html of angular and dispatch and event to the compoent.
function RsCustomEvent ( event, message ) {
params = { bubbles: false, cancelable: false, detail: message };
var evt = document.createEvent( 'CustomEvent' );
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
return evt;
}
var socket = io('localhost:3000');
socket.on("channel-name", function (message) {
window.dispatchEvent(RsCustomEvent('socketEventListen',message));
});
then in the angular component I used below codes.
import { Observable , fromEvent} from 'rxjs';
fromEvent(window, 'socketEventListen').subscribe((data) =>{
});
manually download the socket.io client js file and place that in asset folder and use the above codes.