Closed achasoft closed 4 years ago
Hello @achasoft Never had this issue before, let me check what maybe causing it.
Hi @achasoft
I try to reproduce your issue but i was unable.
Do the following
// imports
const config: SocketIoConfig = {
url: environment.socket.url,
options: {
query: (<any>window).MaxDuel.instance.userId
}
};
...
@NgModule({
declarations: [
...
],
imports: [
...
SocketIoModule.forRoot(config)
],
bootstrap: [AppComponent]
})
if this don't solve your issue, let me know
Have the same issue with query param.
Found only one working solution for me:
// app.module.ts
...
const config: SocketIoConfig = { url: '/', options: { autoConnect: false } };
...
// myCustomService.ts
...
import * as io from 'socket.io-client';
import { Socket } from 'ngx-socket-io';
...
@Injectable()
export class MyCustomService {
constructor(private socket: Socket) {}
...
socketConnect(){
this.socket.ioSocket.io.opts = {
query: { account: (<any>window).localStorage.getItem('account') },
path: '/socket.io/',
autoConnect: true,
reconnection: true,
reconnectionDelay: 1000,
reconnectionDelayMax : 5000,
reconnectionAttempts: 10,
transports: ['polling', 'websocket']
};
this.socket.ioSocket.io.uri = (<any>window).location.origin;
this.socket.connect();
}
...
}
// app.component.ts
...
ngOnInit() {
this.myCustomService.socketConnect();
}
...
If this issue is still relevant please open up a new one since it is 2 years old
hi, first thanks for your work :)
i have a angular application integrated with your package, it has the following configuration in root module:
SocketIoModule.forRoot({ url: environment.socket.url, options: { query: { userId: (<any>window).MaxDuel.instance.userId } } })
it works like charm only in development mode :D as soon as i ng build my app --prod the user id becomes null