Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3 from soketi/feature/extra-features
Browse files Browse the repository at this point in the history
[1.x] Extra features
  • Loading branch information
rennokki authored Jun 1, 2021
2 parents 48c0739 + f570583 commit 01de8f9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ on:
push:
tags:
- "*"
branches-ignore:
- "*"
pull_request:
tags: []
branches: []

jobs:
build:
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ window.Soketi = new Soketi({
});
```

## Catching any event

You can catch any event using `.onAny()`:

```js
Soketi.onAny((event, ...args) => {
//
});
```

## Catching errors

Sometimes the connection might throw errors:

```js
Soketi.error(({ message, code }) => {
//
});
```

## 🐛 Testing

``` bash
Expand Down
20 changes: 20 additions & 0 deletions src/connector/soketi-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ export class SoketiConnector extends Connector {
}
}

/**
* Register a callback to be called on any event.
*/
onAny(callback: Function): SoketiConnector {
this.socket.onAny((event, ...args) => {
callback(event, ...args);
});

return this;
}

/**
* Register a callback to be called on any event.
*/
error(callback: Function): SoketiConnector {
this.socket.on('socket:error', callback);

return this;
}

/**
* Get the socket ID for the connection.
*/
Expand Down
14 changes: 14 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,18 @@ export default class Soketi extends Echo {
connect(): void {
this.connector = new SoketiConnector(this.options);
}

/**
* Register a callback to be called on any event.
*/
onAny(callback: Function): SoketiConnector {
return this.connector.onAny(callback);
}

/**
* Register a callback to catch errors.
*/
error(callback: Function): SoketiConnector {
return this.connector.error(callback);
}
}

0 comments on commit 01de8f9

Please sign in to comment.