Skip to content

Commit

Permalink
feat(socketio): add support for Socket.IO to expose WebSocket endpoints
Browse files Browse the repository at this point in the history
Signed-off-by: Raymond Feng <enjoyjava@gmail.com>
  • Loading branch information
raymondfeng authored and hacksparrow committed Oct 30, 2020
1 parent 065a5d1 commit 29aab5c
Show file tree
Hide file tree
Showing 18 changed files with 1,169 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -334,6 +334,13 @@
# - Standby owner(s): n/a
/bodyparsers/rest-msgpack @achrinza

# WebSocket/SockIO
#
# - Issue label: WebSocket
# - Primary owner(s): @raymondfeng
# - Standby owner(s): n/a
/extensions/socketio @raymondfeng

#
# Build & internal tooling
#
Expand Down
1 change: 1 addition & 0 deletions docs/site/MONOREPO.md
Expand Up @@ -50,6 +50,7 @@ one in the monorepo: `npm run update-monorepo-file`
| [extensions/logging](https://github.com/strongloop/loopback-next/tree/master/extensions/logging) | @loopback/logging | An extension exposes logging for Winston and Fluentd with LoopBack 4 |
| [extensions/metrics](https://github.com/strongloop/loopback-next/tree/master/extensions/metrics) | @loopback/metrics | An extension exposes metrics for Prometheus with LoopBack 4 |
| [extensions/pooling](https://github.com/strongloop/loopback-next/tree/master/extensions/pooling) | @loopback/pooling | Resource pooling service for LoopBack 4 |
| [extensions/socketio](https://github.com/strongloop/loopback-next/tree/master/extensions/socketio) | @loopback/socketio | LoopBack's WebSocket server based on socket.io |
| [extensions/typeorm](https://github.com/strongloop/loopback-next/tree/master/extensions/typeorm) | @loopback/typeorm | Adds support for TypeORM in LoopBack |
| [fixtures/mock-oauth2-provider](https://github.com/strongloop/loopback-next/tree/master/fixtures/mock-oauth2-provider) | @loopback/mock-oauth2-provider | An internal application to mock the OAuth2 authorization flow login with a social app like facebook, google etc |
| [fixtures/tsdocs-monorepo](https://github.com/strongloop/loopback-next/tree/master/fixtures/tsdocs-monorepo) | _(private)_ | A monorepo for tsdocs testing |
Expand Down
1 change: 1 addition & 0 deletions extensions/socketio/.npmrc
@@ -0,0 +1 @@
package-lock=true
27 changes: 27 additions & 0 deletions extensions/socketio/LICENSE
@@ -0,0 +1,27 @@
Copyright (c) IBM Corp. 2020.
Node module: @loopback/socketio
This project is licensed under the MIT License, full text below.

--------

MIT License

MIT License Copyright (c) IBM Corp. 2020

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
66 changes: 66 additions & 0 deletions extensions/socketio/README.md
@@ -0,0 +1,66 @@
# @loopback/socketio

This module uses [socket.io](http://socket.io) to expose controllers as
WebSocket friendly endpoints.

## Use Cases

1. A real time application would like to use WebSocket friendly APIs to manage
subscriptions, participants (rooms) and message exchanges.

2. Make it easy for API developers to expose WebSocket friendly APIs without
learning a lot of low level concepts.

3. Use it as a step stone to explore messaging oriented API paradigms and
programming models, such as pub/sub, eventing, streaming, and reactive.

## High Level Design

The package will provide the following key constructs:

- SocketIOServer: A new server type that listens on incoming WebSocket
connections and dispatches messages to controllers that subscribe to the
namespace. Each server is attached to an http/https endpoint.

- SocketIO controller: A controller class that is decorated with SocketIO
related metadata, including:

- Map to a namespace
- Connect/disconnect events
- Subscribe/consume messages
- Publish/produce messages

- SocketIO middleware or sequence
- Allow common logic to intercept/process WebSocket messages

## Basic Use

1. Create a SocketIOServer
2. Define a controller to handle socket.io events/messages
3. Register the controller
4. Discover socket.io controllers and mount them to the SocketIOServer
namespaces.

## Installation

```sh
npm install --save @loopback/socketio
```

## Contributions

- [Guidelines](https://github.com/strongloop/loopback-next/blob/master/docs/CONTRIBUTING.md)
- [Join the team](https://github.com/strongloop/loopback-next/issues/110)

## Tests

Run `npm test` from the root folder.

## Contributors

See
[all contributors](https://github.com/strongloop/loopback-next/graphs/contributors).

## License

MIT

0 comments on commit 29aab5c

Please sign in to comment.