Skip to content

Commit

Permalink
Merge pull request #18 from alan-agius4/fix/token
Browse files Browse the repository at this point in the history
fix(socket io): cannot resolve all parameters in `WrappedSocket`
  • Loading branch information
Bougarfaoui El houcine authored Aug 6, 2017
2 parents d286330 + 4c286a0 commit 36f093c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,18 @@
"socket.io-client": "^2.0.2"
},
"devDependencies": {
"@angular/common": "^4.1.3",
"@angular/common": "^4.1.3",
"@angular/compiler": "^4.1.3",
"@angular/compiler-cli": "^4.1.3",
"@angular/core": "^4.1.3",
"@angular/platform-browser": "^4.1.3",
"@angular/platform-browser-dynamic": "^4.1.3",
"@types/socket.io-client": "^1.4.29",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.10",
"rxjs": "^5.0.1",
"socket.io": "^1.7.3",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2",
"@angular/compiler-cli": "^4.1.3",
"@types/jasmine": "2.5.38",
"@types/node": "^6.0.63",
"@types/socket.io": "^1.4.28",
"@types/socket.io-client": "^1.4.29",
"codelyzer": "~2.0.0-beta.1",
"core-js": "^2.4.1",
"es6-shim": "^0.35.3",
"jasmine": "^2.5.3",
"jasmine-core": "2.5.2",
Expand All @@ -50,10 +45,15 @@
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "~4.0.13",
"reflect-metadata": "^0.1.10",
"rxjs": "^5.0.1",
"server-destroy": "^1.0.1",
"socket.io": "^1.7.3",
"socket.io-client": "^2.0.2",
"ts-helpers": "^1.1.1",
"ts-node": "1.2.1",
"tslint": "^4.3.0",
"typescript": "^2.3.4"
"typescript": "^2.3.4",
"zone.js": "^0.8.16"
}
}
8 changes: 4 additions & 4 deletions socket-io.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NgModule, ModuleWithProviders } from '@angular/core';
import { NgModule, ModuleWithProviders, InjectionToken } from '@angular/core';

import { WrappedSocket } from './socket-io.service';
import { SocketIoConfig } from './socketIoConfig';
Expand All @@ -9,19 +9,19 @@ export function SocketFactory(config: SocketIoConfig) {
return new WrappedSocket(config);
}

export const socketConfig: string = "__SOCKET_IO_CONFIG__";
export const SOCKET_CONFIG_TOKEN = new InjectionToken<SocketIoConfig>('__SOCKET_IO_CONFIG__');

@NgModule({})
export class SocketIoModule {
static forRoot(config: SocketIoConfig): ModuleWithProviders {
return {
ngModule: SocketIoModule,
providers: [
{ provide: socketConfig, useValue: config },
{ provide: SOCKET_CONFIG_TOKEN, useValue: config },
{
provide: WrappedSocket,
useFactory: SocketFactory,
deps : [socketConfig]
deps : [SOCKET_CONFIG_TOKEN]
}
]
};
Expand Down
7 changes: 4 additions & 3 deletions socket-io.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { Injectable, EventEmitter } from '@angular/core';
import { Injectable, EventEmitter, Inject } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/share';

import * as io from 'socket.io-client';

import { SocketIoConfig } from './socketIoConfig';
import { SOCKET_CONFIG_TOKEN } from './socket-io.module';

@Injectable()
export class WrappedSocket {
subscribersCounter : number = 0;
subscribersCounter = 0;
ioSocket: any;

constructor(config: SocketIoConfig) {
constructor(@Inject(SOCKET_CONFIG_TOKEN) config: SocketIoConfig) {
const url: string = config.url || '';
const options: any = config.options || {};
this.ioSocket = io(url, options);
Expand Down

0 comments on commit 36f093c

Please sign in to comment.