I am calling IO of socket.io-client in my angular project like below:
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable';
import * as io from 'socket.io-client';
@Injectable({
providedIn: 'root'
})
export class SocketclientService {
socket:any;
url:any="ws://localhost:8080"
constructor() {
this.socket = io(this.url);
}
listen(eventname:any,data:any){
return new Observable((subscriber)=>{
this.socket.on(eventname,(data:any)=>{
subscriber.next(data);
})
})
}
emit(eventname:string,data:any){
this.socket.emit(eventname,data);
}
}
But I am always getting an error like:
Error: src/app/services/socketclient.service.ts:11:19 - error TS2349: This expression is not callable.
Type 'typeof import("C:/somepathtoproject/node_modules/socket.io-client/build/index")' has no call signatures.
11 this.socket = io(this.url);
~~
I am not getting it why this is showing, even I have installed @types/socket.io-client