Giter Site home page Giter Site logo

ng-socket-io's Introduction

ng-socket-io

Build Status npm version npm downloads

Socket.IO module for Angular 2 and 4

Install

npm install ng-socket-io

How to use

Import and configure SocketIoModule

//...
import { SocketIoModule, SocketIoConfig } from 'ng-socket-io';

const config: SocketIoConfig = { url: 'http://localhost:8988', options: {} };

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    SocketIoModule.forRoot(config) 
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

We need to configure SocketIoModule module using the object config of type SocketIoConfig, this object accepts two optional properties they are the same used here io(url[, options]).

Now we pass the configuration to the static method forRoot of SocketIoModule

Using your socket Instance

The SocketIoModule provides now a configured Socket service that can be injected anywhere inside the AppModule.

import { Injectable } from '@angular/core';
import { Socket } from 'ng-socket-io';

@Injectable()
export class ChatService {

    constructor(private socket: Socket) { }

    sendMessage(msg: string){
        this.socket.emit("message", msg);
    }
    
    getMessage() {
        return this.socket
            .fromEvent("message")
            .map( data => data.msg );
    }
}

Using multiple sockets with different end points

In this case we do not configure the SocketIoModule directly using forRoot. What we have to do is: extend the Socket service, and call super() with the SocketIoConfig object type (passing url & options if any).

import { Injectable, NgModule } from '@angular/core';
import { Socket } from 'ng-socket-io';

@Injectable()
export class SocketOne extends Socket {

    constructor() {
        super({ url: 'http://url_one:portOne', options: {} });
    }

}

@Injectable()
export class SocketTwo extends Socket {

    constructor() {
        super({ url: 'http://url_two:portTwo', options: {} });
    }

}

@NgModule({
  declarations: [
    //components
  ],
  imports: [
    SocketIoModule,
    //...
  ],
  providers: [SocketOne, SocketTwo],
  bootstrap: [/** AppComponent **/]
})
export class AppModule { }
 

Now you can inject SocketOne, SocketTwo in any other services and / or components.

API

Most of the functionalities here you are already familiar with.

The only addition is the fromEvent method, which returns an Observable that you can subscribe to.

socket.on(eventName: string)

Takes an event name and callback. Works the same as in Socket.IO.

socket.removeListener(eventName: string, callback: Function)

Takes an event name and callback. Works the same as in Socket.IO.

socket.removeAllListeners(eventName: string)

Takes an event name. Works the same as in Socket.IO.

socket.emit(eventName:string, message: any, [callback: Function])

Sends a message to the server. Optionally takes a callback. Works the same as in Socket.IO.

socket.fromEvent<T>(eventName: string): Observable<T>

Takes an event name and returns an Observable that you can subscribe to.

socket.fromEventOnce(eventName: string): Promise

Takes an event name, and returns a Promise instead of an Observable. Works the same as once in Socket.IO.

You should keep a reference to the Observable subscription and unsubscribe when you're done with it. This prevents memory leaks as the event listener attached will be removed (using socket.removeListener) ONLY and when/if you unsubscribe.

If you have multiple subscriptions to an Observable only the last unsubscription will remove the listener.

Example

You can also see this example with express.js.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';

import { SocketIoModule, SocketIoConfig, Socket} from 'ng-socket-io';

const config: SocketIoConfig = { url: 'http://localhost:8988', options: {} };

@Injectable()
class ChatService {

    constructor(private socket: Socket) { }

    sendMessage(msg: string){
        this.socket.emit("message", msg);
    }

    getMessage() {
        return this.socket
            .fromEvent<any>("message")
            .map(data => data.msg );
    }
    
    close() {
      this.socket.disconnect()
    }
}


@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    SocketIoModule.forRoot(config) 
  ],
  providers: [ChatService],
  bootstrap: [AppComponent]
})
export class AppModule { }

LICENSE

MIT

ng-socket-io's People

Contributors

alan-agius4 avatar bluzi avatar css-ianm avatar embarq avatar ffreitasit avatar sensui7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ng-socket-io's Issues

'once' method is missing

Hi,

I've noticed your module is missing the 'once' method from the original socket.io
Any chance you'll be adding it anytime soon? Can I make the change and create a pull request?

Can't resolve all parameters for Myservice

When I use multiple sockets, I receive this error message:
Can't resolve all parameters for MyService: ([object Object], ?).

This is my app.module
`...

import {Socket, SocketIoModule} from 'ng-socket-io';

@Injectable()
export class SocketOne extends Socket {

constructor() {
super({ url: 'http://url_one:portOne', options: {} });
}
}
@NgModule({
declarations: [...],
imports: [
BrowserModule,
SocketIoModule
...
],
providers: [
..
SocketOne
]`

And this is my service:
`
...

import {SocketOne} from '../app.module';

@Injectable()

export class MyService {

constructor( private socket: SocketOne ){

  this.socket.connect()   

}   

}`

What could be happening?

Error of Unexpected value '[object Object]' imported by the module 'AppModule'

    import { SocketIoModule, SocketIoConfig } from 'ng-socket-io';

   const config: SocketIoConfig = { url: 'http://localhost:8988', options: {} };

   @NgModule({
       declarations: [
           AppComponent
       ],
       imports: [
          BrowserModule,
         SocketIoModule.forRoot(config) 
       ],

    })
       export class AppModule { }

Am now getting an error of
Unexpected value '[object Object]' imported by the module 'AppModule'. Please add a @NgModule annotation

In the latest release of angular2 only modules can be imported in the imports area , please fix this

Add a parameter to the constructor to set URL

Hey !!!

I try to find a way to put a parameter to the URL to have somethings like that:

export class SocketRasp extends Socket
{
ipAddress: String;
constructor(ipAddress: String)
{
super({ url: 'http://'+ ipAddress + ':8080', options: {} });
}
}

it's Possible ???

Because, i try and i have this error:

Error: Can't resolve all parameters for SocketRasp: (?).
at syntaxError (http://localhost:8100/build/vendor.js:80840:34)
at CompileMetadataResolver._getDependenciesMetadata (http://localhost:8100/build/vendor.js:94915:35)
at CompileMetadataResolver._getTypeMetadata (http://localhost:8100/build/vendor.js:94783:26)
at CompileMetadataResolver._getInjectableMetadata (http://localhost:8100/build/vendor.js:94769:21)
at CompileMetadataResolver.getProviderMetadata (http://localhost:8100/build/vendor.js:95060:40)
at http://localhost:8100/build/vendor.js:94989:49
at Array.forEach ()
at CompileMetadataResolver._getProvidersMetadata (http://localhost:8100/build/vendor.js:94949:19)
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:8100/build/vendor.js:94604:50)
at JitCompiler._loadModules (http://localhost:8100/build/vendor.js:105945:70)

Emit parameters

Emit parameters should allow void, all but eventName should be optional.

multiple states(Routes) when an event fire many times (multiple times)

I am connecting Angular2 application having multiple states(Routes) with Node server(Socket) running on the back-end. When I visit some other state and come back to the previous state where socket code is written in service file on the angular application created with fromEvent. the service called by subscribe() in multiple components which is called in ngoninit() { } . How often I move on routes gets a component view and event emit when an event fire, So many times (multiple times) the subscribed service gets called (multiple time show console.log("get message")), which affects the performance.

'EventEmitter' is declared but never used.

Hi! I have ts compiler error:
ERROR in C:/../node_modules/ng-socket-io/socket-io.service.ts (1,22): 'EventEmitter' is declared but never used.
And.. Yes its declared and never used )

ERROR in Error encountered resolving symbol values statically

how i can fix this ?

ERROR in Error encountered resolving symbol values statically. Calling function 'makeDecorator', function 
calls are not supported. Consider replacing the function or lambda with a reference to an exported 
function, resolving symbol Injectable in D:/PROJECTS/O4P/node_modules/ng2-socket-
io/node_modules/@angular/core/src/di/metadata.d.ts, resolving symbol OpaqueToken in 
D:/PROJECTS/O4P/node_modules/ng2-socket-io/node_modules/@angular/core/src/di/opaque_token.d.ts, 
resolving symbol OpaqueToken in D:/PROJECTS/O4P/node_modules/ng2-socket-
io/node_modules/@angular/core/src/di/opaque_token.d.ts

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'D:\PROJECTS\O4P\src'
@ ./src/main.ts 5:0-74
@ multi ./src/main.ts

NPM update ng-socket-io

Hi,
I'm a little bit confused about ng-socket-io versions. npm outdated says I have installed 0.1.91 but the latest version is lower - 0.1.11. Releases page displays 0.1.7 as latest version.

image

Here is /<my_project>/node_modules/ng-socket-io/package.json

...,
"tags": [
    "angular2",
    "socket.io",
    "typescript",
    "angular2-socket.io"
  ],
  "version": "0.1.91"  <---
  ...

Add support for rxjs > 6

When I update my angular project from 5.x to 6.x with rxjs 6.x I get following error:

ERROR in node_modules/ng-socket-io/dist/src/socket-io.service.d.ts(1,10): error TS2305: Module '"..../project/node_modules/rxjs/Observable"' has no exported member 'Observable'.
node_modules/rxjs/Observable.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/Observable'.

WebSocket is already in CLOSING or CLOSED state.

For some reason, after a couple minutes of inactivity, websockets.js prints "WebSocket is already in CLOSING or CLOSED state." to the console repeatedly. I'm not entirely sure what's going on but I would love if anyone has any idea how to fix this.

image

АОТ Warning: Can't resolve all parameters for WrappedSocket

Hello,

Building AOT using angular/[email protected] gives me a warning:

Warning: Can't resolve all parameters for WrappedSocket in <my_project_path>/node_modules/ng-socket-io/socket-io.service.ts: (?). This will become an error in Angular v5.x

Here is my app.module.ts

...
const ioConfig: SocketIoConfig = { url : CONFIG.io.url, options : CONFIG.io.options };

@NgModule({
  declarations : [ ... ],
  imports      : [
    ...
    SocketIoModule.forRoot(ioConfig),
    ...
  ],
  bootstrap    : [ ... ],
  providers    : [ ... ]
})
export class AppModule {
}

Compilation on Ionic

Compiling my Ionic application with your plugin in production mode I always get the following error:

Error: Error encountered resolving symbol values statically. 
Calling function 'makeDecorator', function calls are not supported. 
Consider replacing the function or lambda with a reference to an exported function, 
resolving symbol Injectable in 

node_modules/ng2-socket-io/node_modules/@angular/core/src/di/metadata.d.ts,

resolving symbol OpaqueToken in 

node_modules/ng2-socket-io/node_modules/@angular/core/src/di/opaque_token.d.ts, 

resolving symbol OpaqueToken in 

node_modules/ng2-socket-io/node_modules/@angular/core/src/di/opaque_token.d.ts

Undefined provider + module has no member exported

Hello everyone !!
I work on Ionic Project.
I'm trying to use multiple sockets with different end points, but i have those errors:

Error: Encountered undefined provider! Usually this means you have a circular dependencies (might be caused by using 'barrel' index.ts files.
at syntaxError (http://localhost:8100/build/vendor.js:80958:34)
at http://localhost:8100/build/vendor.js:95082:40
at Array.forEach ()
at CompileMetadataResolver._getProvidersMetadata (http://localhost:8100/build/vendor.js:95067:19)
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:8100/build/vendor.js:94722:50)
at JitCompiler._loadModules (http://localhost:8100/build/vendor.js:106063:70)
at JitCompiler.compileModuleAndComponents (http://localhost:8100/build/vendor.js:106036:36)
at JitCompiler.compileModuleAsync (http://localhost:8100/build/vendor.js:105965:37)
at PlatformRef
.bootstrapModuleWithZone (http://localhost:8100/build/vendor.js:4894:25)
at PlatformRef
.bootstrapModule (http://localhost:8100/build/vendor.js:4880:21)

and:

Module "C:/Users/TheLLspectre/documents/Visual studio 2017/Projects/webAppRaspberry/webAppRaspberry/src/assets/typescript/SocketRasp" has no exported member 'SocketRasp'.

SocketRasp.ts

import { Injectable, NgModule } from '@angular/core';
import { Socket } from 'ng-socket-io';
@Injectable()
export class SocketOne extends Socket
{
constructor(private ipAddress: String)
{
super({ url: 'http://' + ipAddress + ':8080', options: {} });
}
}

app.module.ts

import { NgModule, ErrorHandler } from '@angular/core';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { BrowserModule } from '@angular/platform-browser';
import { MyApp } from './app.component';
import { HttpClientModule } from '@angular/common/http';
import { SocketIoModule, SocketIoConfig } from 'ng-socket-io';
import { SocketRasp } from '../assets/typescript/SocketRasp';
//pages
import { HomePage } from '../pages/home/home';
import { viewerPage } from '../pages/viewer/viewer';
@NgModule({
declarations: [
MyApp,
HomePage,
viewerPage
],
imports: [
IonicModule.forRoot(MyApp),
HttpClientModule,
BrowserModule,
SocketIoModule
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
viewerPage
],
providers: [{ provide: ErrorHandler, useClass: IonicErrorHandler },
SocketRasp
]
})
export class AppModule {}

It's working with SocketIoModule and SocketIoConfig, so i don't understand why this doesn't work....

Property 'fromEvent' does not exists

After upgrading to angular5 and ng-socket-io 2.0.0 I've got a compilation error stating that fromEvents doesn't exists in a class that subclasses from Socket:

ERROR in xxxx/xxx-component.ts(24,27): error TS2339: Property 'fromEvent' does not exist on type 'WebSocketService'.

If I edit that file and save it without changing anything, then the error is raised again, but finally it compiles and the app runs. I'm running ng serve.

It looks like some kind of packaging issue that prevents the module from being imported the at the first time.

Same behavior using both ng serve and ng serve --aot.

Warning: Can't resolve all parameters for WrappedSocket...

Whenever I execute "ng build . . .", I get the following error

Warning: Can't resolve all parameters for WrappedSocket in /home/steve/Desktop/alias/node_modules/ng-socket-io/socket-io.service.ts: (?). This will become an error in Angular v5.x

Could somebody look into this issue?

Strange error where index.js has a bad reference.

I ran into an issue today where I kept getting an unable to resolve 'SocketIoConfig'.
I went round and round. Reinstalled: npm cache clean; npm install;
Did my webpack build and again... hit this issue...
I looked deeper and I found that the installed index.js had on LINE::5

 var SocketIoConfig_1 = require("./SocketIoConfig");

Which was killing the build. I changed the code in the module to:

 var SocketIoConfig_1 = require("./socketIoConfig");

And all works.
Did you ever release a version where you had a

 require("./SocketIoConfig")

Or did I just run into some other npm bug or something like that???

connect event

hello, how can I take on connect event, when I try this, it is not emit...

this.socket.on( 'connect', function () {
that.showToast("connect")
} );

I want to pass an option with the URL but only after I login

Hi,

So this is the thing. I would like to pass the userID as an option while connecting to socket server. So I won't be able to implement this in app.module.ts. So, I tried creating a separate provider extending socket. But there also you have to do it in the constructor(), where I am not able to do anything else such as getting the id from another provider since I have to use super() and can't use this..

What are my options?

node_modules\ng2-socket-io\socket-io.service.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.

When trying to compile my app, I get the following error:

...node_modules\ng2-socket-io\socket-io.service.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
The missing file seems to be part of a third party library. TS files in published libraries are often a sign of a badly packaged library. Please open an issue in the library repository to alert its author and ask them to package the library using the Angular Package Format (https://goo.gl/jB3GVv).

I have done everything according to the 'How to use' section, what am I doing wrong?

Support: v 0.2.0

As I can see the latest version on npm is 0.2.0 - https://www.npmjs.com/package/ng-socket-io
Also it has some fixes/updates in socket-io.service for fromEvent() method in comparison with the version 0.1.11.

But I don't see any tag, changelog and even the source code with these fixes/updates in this repo.
Is the v. 0.2.0 safe for upgrading from 0.1.11 ?

my project tslinter fails on ng-socket-io folder

Hello

I try to run tslint via command and it's failing on ng-socket-io

Failed to load /www/sites/angular2/streaming/node_modules/ng-socket-io/tslint.json: Could not find custom rule directory: node_modules/codelyzer

Removing rulesDirectory solved problem. I tried to exclude ng-socket-io folder from command tslint --project tsconfig.json without success.

Does anybody else have this issue?

No provider for WrappedSocket

I am getting this error. I am trying to implement multiple sockets with different end points. Can anyone please help me

  1. Here is main module (that one my shared module)
    `import {NgModule} from '@angular/core';
    import {SocketIoModule} from 'ng-socket-io';
    import {SocketService} from '../helpers/socket/socket.service';
    import {NotificationSocket} from '../helpers/socket/notification.socket';
    @NgModule({
    declarations: [ ],
    imports: [
    SocketIoModule
    ],
    exports: [

    ],
    providers: [
    NotificationSocket,
    SocketService
    ]
    })
    export class SharedModule {
    }
    `

  2. NotificationSocket file
    import {Injectable} from '@angular/core'; import {Socket} from 'ng-socket-io'; @Injectable() export class NotificationSocket extends Socket { constructor() { super({url: 'http://127.0.0.1:3000', options: {}}); } }

  3. SocketService file
    `import {Injectable} from '@angular/core';
    import 'rxjs/add/operator/map';
    import {Socket} from 'ng-socket-io';

@Injectable()
export class SocketService {
constructor(private socket: Socket) {
}

sendMessage(event_name: string, data: any) {
    this.socket.emit(event_name, data);
}

getMessage(event_name: string) {
    return this.socket.fromEvent(event_name).map(
        response => response
    );
}

}`

Pass parameters in the socket configuration

Hi, I have to create a chat application using socket in ionic. while configuring the socket in my app.module.ts I have to pass the user token which is to be obtained only after the user login. is there any way to configure the socket? Please see the below code. If my question is not clear please revert me back.

`import { SocketIoConfig, SocketIoModule } from 'ng-socket-io';`
const config: SocketIoConfig = {
  url: 'http://192.168.1.102:3000', options: {
    transportOptions: {
      polling: {
        extraHeaders: {
          'x-access-token': localStorage.getItem('token'),
          'council_key': 'seos'
        }
      }
    }
  }
};

not able to run angular2 project which is public

I have successfully run the server project but when I am trying to run the angular2 project it gives me below error-

You have to be inside an angular-cli project in order to use the build command.

for more details I have attached snapshot.
error socket io with angularjs

Thanks in Advance,
Mohinesh

Listening for server messages not working

Hi,
I followed exacly the example but it is not working. When i have a look inside the Browsers Network Monitoring i see that the socket message is sent by the server (and of course reaches at the client). But my Angular does not notice it:

module:

const config: SocketIoConfig = { url: 'http://localhost:80', options: {} }
//...
imports: [
    HttpModule,
    BrowserModule,
    FormsModule,
    SocketIoModule.forRoot(config),
    RouterModule.forRoot([

service:

public getTest() {
    return this.socket
        .fromEvent<any>('test')
        .map( (data: any) => {
          console.log(data);
          return data
        } )
  }

module:

  constructor(private httpService: HttpService, private websocketService: WebsocketService) { }

  private ngOninit() {
    this.httpService.getProjects().subscribe((res: any) => {
      this.projects = JSON.parse(res._body)
    })
    this.websocketService.getTest().subscribe((res: any) => {
      console.log(res)
    })
  }

just like i said...the connection DOES establish and it does also send the data to the client....only angular will not notice it....

No compilation output

(I'm using last version 0.2.0 of ng-socket-io)

Since I update to angular5 and angular-cli 1.5, I have this error when starting my app:

ERROR in ./node_modules/ng-socket-io/socket-io.module.ts
Module build failed: Error: /usr/src/app/node_modules/ng-socket-io/socket-io.module.ts is not part of the compilation output. Please check the other error messages for details.
at AngularCompilerPlugin.getCompiledFile (/usr/src/app/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:629:23)
at plugin.done.then (/usr/src/app/node_modules/@ngtools/webpack/src/loader.js:467:39)
at process._tickCallback (internal/process/next_tick.js:109:7)
@ ./node_modules/ng-socket-io/index.js 3:25-54
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts

Re-connect to a new host set by the user

Is it possible to disconnect the client, change the host/port (by the user, from the app), and then connect to that new host? I haven't found a way to setup that behavior.

Thanks!

bad reference to SocketIoConfig

When trying to build my project with angular-cli I got the following error:

ERROR in <myproject>/node_modules/ng2-socket-io/index.ts (4,32): Cannot find module './SocketIoConfig'.

index.ts references SocketIoConfig.ts but the actual file has the name socketIoConfig.ts

replacing line 4 in index.ts:
export { SocketIoConfig } from './SocketIoConfig';
to
export { SocketIoConfig } from './socketIoConfig';

solved the problem

Catch initial connection error

Hi,
How can I catch initial connection error (eg. server down)?
I am using ng-socket-io just like in README:

@NgModule({
  imports      : [
    SocketIoModule.forRoot(ioConfig)
  ]
})
export class AppModule {
}

My service

@Injectable()
export class MyIoService {
  constructor(protected socket: Socket) {  }
  ...
}

I want to retry connecting few seconds later.
Can you give me a suggestion how to do it?
Greetings,

How do I connect to different namespaces?

If I set the config in an @NgModule to be to a given namespace, all modules wind up trying to use that same namespace (last one registered seems to win).

I would like to have different Services able to connect to different namespaces. Or even a single service that connects to a bunch of different namespaces (though that would be rare).

How can I do that?

tslint warn about *.ts files

npm run lint got:

[17:40:08] tslint: .../node_modules/ng-socket-io/socket-io.service.ts, line: 57
Expected indentation of 18 spaces but found 20.
L56: if (this.subscribersCounter === 1) {
L57: this.ioSocket.removeListener(eventName);

my tslint.json:

{
  .....,
  "rulesDirectory": [
    "node_modules/tslint-eslint-rules/dist/rules"
  ]
}

There's no warning if i remove "rulesDirectory", or remove all ts file (not include d.ts) under node_modules/ng-socket-io , such as index.d.ts, socket-io.service.d.ts.

I prefer to put project into src folder and build output to dist folder. and set .npmignore:

src/
node_modules/
node_modules*/
npm-shrinkwrap.json
tsconfig.json
tslint.json
.eslintignore
.eslintrc.json
.travis.yml
appveyor.yml
*.swp
*.bak
demo/
test/
coverage/
.nyc_output/ 

so there's no ts files in the npm package

ERROR Error: No provider for WrappedSocket!

I am getting this error:
StackComponent.html:59 ERROR Error: No provider for WrappedSocket!
at injectionError (core.es5.js:1231)
at noProviderError (core.es5.js:1269)
at ReflectiveInjector_.throwOrNull (core.es5.js:2770)
at ReflectiveInjector
.getByKeyDefault (core.es5.js:2809)
at ReflectiveInjector
.getByKey (core.es5.js:2741)
at ReflectiveInjector
.get (core.es5.js:2610)
at AppModuleInjector.NgModuleInjector.get (core.es5.js:3578)
at resolveDep (core.es5.js:11039)
at createClass (core.es5.js:10892)
at _createProviderInstance (core.es5.js:10862)

change ip in app

Hi, someone can help me to change the config ip and reconnect the socket after that ?

In other words, my app boot and try to connect to socket, but the ip is a default one so the user go to "settings" of my app and can change ip without changing it in the code and it could reload the socket

Thanks for replys
Arthur

How to listen data from subscribe channel?

I can connect then subscribe to server.

    this.socket.emit('subscribe', {
      channel: channel,
      auth: this.options.auth || {}
    });

But i can't listen data from this subscribe channel.

    this.socket.on('UserSendMessage', (data) => {
      console.log('Data : ', data);
    })

But it have no response.

What wrong?

Update 0.1.11 on npmjs hosting.

I see that the version 0.1.11 is not available on npmjs. BY this way "ng-socket-io": "git+ssh://[email protected]/bougarfaoui/ng-socket-io.git#0.1.11", TS compiler is not able to find module ng2-socket-io. I see It has been loaded on the file system.

Angular 4 Warning, Error in Angular 5

Hey there, I am using Angular CLI and recently updated it.

I'm receiving the following warning.,
Warning: Can't resolve all parameters for WrappedSocket in /home/karthik/workspace/clinxapp/node_modules/ng-socket-io/socket-io.service.ts: (?). This will become an error in Angular v5.x

Angular: 4.2.4
Angular CLI: 1.5.2
ng-socket-io: 0.1.11

Example(angular side) not working

The example code is not working.
When I run "ng build" it will shown
ERROR in c:/Users/LuxProtoss/Desktop/ngsocket/ng-socket-io/examples/chat-app/public/node_modules/ng-socket-io/socket-service.ts (5,21): Cannot find module 'socket.io-client'.)

ERROR in ./~/ng-socket-io/socket-io.service.ts
Module not found: Error: Can't resolve 'socket.io-client' in 'c:\Users\LuxProtoss\Desktop\ngsocket\ng-socket-io\examp\chat-app\public\node_modules\ng-socket-io'

Update Config

Hi!

I have some problem with using this library. In my app.module.ts file i'm initializing the module in the way, like this

// app.module.ts

const SOCKETIO_CONFIG: SocketIoConfig = {
        options: {
            query: `token=${localStorage.getItem('token')}`
        }
}

@NgModule({
    imports: [SocketIoModule.forRoot(SOCKETIO_CONFIG)]
})

I have a login page, where I don't need to connect to the SocketServer, and user doesn't have a token in the localStorage. When user receive a token from the API, app will update the localStorage. But when the user is not signed in, app initialize with the NULL value of the token, and after user sign in, app trying to connect to the server using the empty token

Please help me find a way to update the token in the configuration or describe more right way to avoid this problem

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.