ProductPromotion
Logo

Angular.JS

made by https://0x3d.site

GitHub - chrisguttandin/rxjs-broker: An RxJS message broker for WebRTC DataChannels and WebSockets.
An RxJS message broker for WebRTC DataChannels and WebSockets. - chrisguttandin/rxjs-broker
Visit Site

GitHub - chrisguttandin/rxjs-broker: An RxJS message broker for WebRTC DataChannels and WebSockets.

GitHub - chrisguttandin/rxjs-broker: An RxJS message broker for WebRTC DataChannels and WebSockets.

rxjs-broker

An RxJS message broker for WebRTC DataChannels and WebSockets.

version

This module is using the power of RxJS to wrap WebSockets or WebRTC DataChannels. It returns a Subject which can be used with all the operators that RxJS provides. But it also provides some additional functionality.

Usage

To install rxjs-broker via npm you can run the following command.

npm install rxjs-broker

rxjs-broker does provide two utility functions: connect() and wrap(). If you're using ES2015 modules you can import them like that.

import { connect, wrap } from 'rxjs-broker';

connect(url: string, subjectConfig?: { openObserver?: NextObserver<void> }): WebSocketSubject

The connect() function takes a URL as a parameter and returns a WebSocketSubject which extends the AnonymousSubject provided by RxJS. It also implements the IRemoteSubject interface which adds two additional methods. It gets explained in more detail below.

const webSocketSubject = connect('wss://super-cool-websock.et');

The second parameter can be used to specify an openObserver which works similar to the openObserver of the WebSocketSubject provided by RxJS. The next() method of it gets called when the underlying WebSocket emits an open event.

wrap(dataChannel: DataChannel, subjectConfig?: { openObserver?: NextObserver<void> }): DataChannelSubject

The wrap() function can be used to turn a WebRTC DataChannel into a DataChannelSubject which does also extend the AnonymousSubject and implements the IRemoteSubject interface.

// Let's imagine a variable called dataChannel exists and its value is a WebRTC DataChannel.
const dataChannelSubject = wrap(dataChannel);

The second parameter can be used to specify an openObserver. The next() method of it gets called when the underlying DataChannel emits an open event.

IRemoteSubject

As mentioned above the IRemoteSubject interface is used to describe the common behavior of the DataChannelSubject and the WebSocketSubject. In TypeScript it looks like this:

interface IRemoteSubject<T> {
    close(): void;

    send(message: T): Promise<void>;
}

close()

The close() method is meant to close the underlying WebSocket or WebRTC DataChannel.

send(message): Promise

The send() method is a supercharged version of next(). It will stringify a given JSON message before sending it and returns a Promise which resolves when the message is actually on it's way.

mask(mask, maskableSubject): IRemoteSubject

rxjs-broker does also provide another standalone function called mask(). It can be imported like that.

import { mask } from 'rxjs-broker';

The mask() function takes a JSON object which gets used to extract incoming data and to enhance outgoing data. If there is for example a DataChannel which receives two types of messages (control messages and measurement messages), they might look somehow like this:

{
    "type": "control",
    "message": {
        "heating": "off"
    }
}
{
    "type": "measurement",
    "message": {
        "temperature": "30°"
    }
}

In case you are not interested in the messages of type control and only want to receive and send messages of type measurement, you can use mask() to achieve exactly that.

const maskedSubject = mask({ type: 'measurement' }, dataChannelSubject);

// The callback will be called with unwrapped messages like { temperature: '30°' }.
maskedSubject.subscribe((message) => {
    // ...
});

When you call next() or send() on the returned IRemoteSubject it also wraps the message with the provided mask. Considering the example introduced above, the usage of the send() method will look like this:

const maskedSubject = mask({ type: 'measurement' }, dataChannelSubject);

// This will send wrapped messages like { type: 'measurement', message: { temperature: '30°' } }.
maskedSubject.send({ temperature: '30°' });

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory