forked from bougarfaoui/ng-socket-io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket-io.module.ts
29 lines (24 loc) · 875 Bytes
/
socket-io.module.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { NgModule, ModuleWithProviders, InjectionToken } from '@angular/core';
import { WrappedSocket } from './socket-io.service';
import { SocketIoConfig } from './socketIoConfig';
/** Socket factory */
export function SocketFactory(config: SocketIoConfig) {
return new WrappedSocket(config);
}
export const SOCKET_CONFIG_TOKEN = new InjectionToken<SocketIoConfig>('__SOCKET_IO_CONFIG__');
@NgModule({})
export class SocketIoModule {
static forRoot(config: SocketIoConfig): ModuleWithProviders<any> {
return {
ngModule: SocketIoModule,
providers: [
{ provide: SOCKET_CONFIG_TOKEN, useValue: config },
{
provide: WrappedSocket,
useFactory: SocketFactory,
deps : [SOCKET_CONFIG_TOKEN]
}
]
};
}
}