Skip to content

Commit

Permalink
Add function to create custom namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigo committed Nov 29, 2018
1 parent a087e29 commit 4f3f376
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 33 deletions.
41 changes: 8 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,6 @@ We need to configure ```SocketIoModule``` module using the object ```config``` o
Now we pass the configuration to the static method ```forRoot``` of ```SocketIoModule```


### For Angular 6 Project in version 1.0.8

To be sure that you are using Angular 6, check your version:

```bash

ng -v

```

If you are using Angular 6 you need change two thing

1. Install rxjs-compat

```bash

npm install rxjs-compat

```

2. Change polyfills.ts

Add this code in the first line of the file:

```ts

(window as any).global = window;

```

### Using your socket Instance

The ```SocketIoModule``` provides now a configured ```Socket``` service that can be injected anywhere inside the ```AppModule```.
Expand Down Expand Up @@ -143,17 +113,22 @@ 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)`
### `socket.of(namespace: string)`

Takes an namespace.
Works the same as in Socket.IO.

### `socket.on(eventName: string, callback: Function)`

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

### `socket.removeListener(eventName: string, callback: Function)`
### `socket.removeListener(eventName: string, callback?: Function)`

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

### `socket.removeAllListeners(eventName: string)`
### `socket.removeAllListeners(eventName?: string)`

Takes an event name.
Works the same as in Socket.IO.
Expand Down
4 changes: 4 additions & 0 deletions src/socket-io.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export class WrappedSocket {
this.ioSocket = ioFunc(url, options);
}

of(namespace: string) {
this.ioSocket.of(namespace);
}

on(eventName: string, callback: Function) {
this.ioSocket.on(eventName, callback);
}
Expand Down

0 comments on commit 4f3f376

Please sign in to comment.