From 5d8967c02a6da9d3a3842aee5851ce5982e2b7e6 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Sat, 5 Aug 2017 11:32:49 +0200 Subject: [PATCH 1/2] fix(socket io): cannot resolve all parameters in `WrappedSocket` --- package.json | 20 ++++++++++---------- socket-io.module.ts | 8 ++++---- socket-io.service.ts | 7 ++++--- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index ea4f9ec..46c14fe 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } } diff --git a/socket-io.module.ts b/socket-io.module.ts index 288ffe2..4c1053f 100644 --- a/socket-io.module.ts +++ b/socket-io.module.ts @@ -1,4 +1,4 @@ -import { NgModule, ModuleWithProviders } from '@angular/core'; +import { NgModule, ModuleWithProviders, InjectorToken } from '@angular/core'; import { WrappedSocket } from './socket-io.service'; import { SocketIoConfig } from './socketIoConfig'; @@ -9,7 +9,7 @@ export function SocketFactory(config: SocketIoConfig) { return new WrappedSocket(config); } -export const socketConfig: string = "__SOCKET_IO_CONFIG__"; +export const SOCKET_CONFIG_TOKEN = new InjectorToken('__SOCKET_IO_CONFIG__'); @NgModule({}) export class SocketIoModule { @@ -17,11 +17,11 @@ export class SocketIoModule { return { ngModule: SocketIoModule, providers: [ - { provide: socketConfig, useValue: config }, + { provide: SOCKET_CONFIG_TOKEN, useValue: config }, { provide: WrappedSocket, useFactory: SocketFactory, - deps : [socketConfig] + deps : [SOCKET_CONFIG_TOKEN] } ] }; diff --git a/socket-io.service.ts b/socket-io.service.ts index bcfa713..acf4947 100644 --- a/socket-io.service.ts +++ b/socket-io.service.ts @@ -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); From 4c286a0a7ac2f266bc5a66f2994b423739ddfbe5 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Sat, 5 Aug 2017 11:43:28 +0200 Subject: [PATCH 2/2] socket io: fix typo in module --- socket-io.module.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/socket-io.module.ts b/socket-io.module.ts index 4c1053f..ec3715e 100644 --- a/socket-io.module.ts +++ b/socket-io.module.ts @@ -1,4 +1,4 @@ -import { NgModule, ModuleWithProviders, InjectorToken } from '@angular/core'; +import { NgModule, ModuleWithProviders, InjectionToken } from '@angular/core'; import { WrappedSocket } from './socket-io.service'; import { SocketIoConfig } from './socketIoConfig'; @@ -9,7 +9,7 @@ export function SocketFactory(config: SocketIoConfig) { return new WrappedSocket(config); } -export const SOCKET_CONFIG_TOKEN = new InjectorToken('__SOCKET_IO_CONFIG__'); +export const SOCKET_CONFIG_TOKEN = new InjectionToken('__SOCKET_IO_CONFIG__'); @NgModule({}) export class SocketIoModule {