All Projects → afrad → Angular2 Websocket

afrad / Angular2 Websocket

Licence: apache-2.0
Websocket wrapper for angular2 based on angular-websocket

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Angular2 Websocket

Dotnetify React Template
Real-time React SPA template using dotNetify.
Stars: ✭ 191 (-12.39%)
Mutual labels:  websockets
Hexnut
🔩 Hexnut is a middleware based, express/koa like framework for web sockets
Stars: ✭ 204 (-6.42%)
Mutual labels:  websockets
Isomorphic Ws
Isomorphic implementation of WebSocket (https://www.npmjs.com/package/ws)
Stars: ✭ 215 (-1.38%)
Mutual labels:  websockets
Vertx Mqtt Broker
Vert.x based MQTT Broker
Stars: ✭ 193 (-11.47%)
Mutual labels:  websockets
Simple Vpn
A simple VPN allowing mesh-like communication between nodes, over websockets
Stars: ✭ 201 (-7.8%)
Mutual labels:  websockets
Async Tungstenite
Async binding for Tungstenite, the Lightweight stream-based WebSocket implementation
Stars: ✭ 207 (-5.05%)
Mutual labels:  websockets
Platypus
Large-scale server monitoring application written in Golang
Stars: ✭ 190 (-12.84%)
Mutual labels:  websockets
Node Red Contrib Uibuilder
Easily create data-driven web UI's for Node-RED using any (or no) front-end library. VueJS and bootstrap-vue included but change as desired.
Stars: ✭ 215 (-1.38%)
Mutual labels:  websockets
Djangochannelsgraphqlws
Django Channels based WebSocket GraphQL server with Graphene-like subscriptions
Stars: ✭ 203 (-6.88%)
Mutual labels:  websockets
Arduinowebsockets
A library for writing modern websockets applications with Arduino (ESP8266 and ESP32)
Stars: ✭ 213 (-2.29%)
Mutual labels:  websockets
Bolt Python
A framework to build Slack apps using Python
Stars: ✭ 190 (-12.84%)
Mutual labels:  websockets
Pgdeltastream
Streaming Postgres logical replication changes atleast-once over websockets
Stars: ✭ 197 (-9.63%)
Mutual labels:  websockets
Aleph
Asynchronous communication for Clojure
Stars: ✭ 2,389 (+995.87%)
Mutual labels:  websockets
Esp8266 React
A framework for ESP8266 & ESP32 microcontrollers with a React UI
Stars: ✭ 193 (-11.47%)
Mutual labels:  websockets
Wok
A cherrypy framework for multi-purpose plug-ins
Stars: ✭ 215 (-1.38%)
Mutual labels:  websockets
Speechtotext Websockets Javascript
SDK & Sample to do speech recognition using websockets in Javascript
Stars: ✭ 191 (-12.39%)
Mutual labels:  websockets
Ixwebsocket
websocket and http client and server library, coming with ws, a command line swiss army knife utility
Stars: ✭ 204 (-6.42%)
Mutual labels:  websockets
Pont
An online board game in Rust and WebAssembly
Stars: ✭ 218 (+0%)
Mutual labels:  websockets
Webwire Go
A transport independent asynchronous duplex messaging library for Go
Stars: ✭ 216 (-0.92%)
Mutual labels:  websockets
Lgwebosremote
Command line webOS remote for LGTVs
Stars: ✭ 211 (-3.21%)
Mutual labels:  websockets

angular2websocket

Based on https://github.com/AngularClass/angular-websocket and migrated to Angular2

Installation

npm install angular2-websocket

Usage:

import {$WebSocket} from 'angular2-websocket/angular2-websocket'
var ws = new $WebSocket("url");
ws.send(event);

also ws.getDataStream() returns Subject to which you can attach an Observer (https://github.com/Reactive-Extensions/RxJS)

Compilation

npm run typings
npm run compile

The default value for binary type is 'arrayBuffer'.

example

import {$WebSocket, WebSocketSendMode} from 'angular2-websocket/angular2-websocket';
  
// connect
var ws = new $WebSocket("ws://127.0.0.1:7000");
// you can send immediately after connect, 
// data will cached until connect open and immediately send or connect fail.
  
// when connect fail, websocket will reconnect or not,
// you can set {WebSocketConfig.reconnectIfNotNormalClose = true} to enable auto reconnect
// all cached data will lost when connect close if not reconnect
  
  
// set received message callback
ws.onMessage(
    (msg: MessageEvent)=> {
        console.log("onMessage ", msg.data);
    },
    {autoApply: false}
);
  
// set received message stream
ws.getDataStream().subscribe(
    (msg)=> {
        console.log("next", msg.data);
        ws.close(false);
    },
    (msg)=> {
        console.log("error", msg);
    },
    ()=> {
        console.log("complete");
    }
);
  
// send with default send mode (now default send mode is Observer)
ws.send("some thing").subscribe(
        (msg)=> {
            console.log("next", msg.data);
        },
        (msg)=> {
            console.log("error", msg);
        },
        ()=> {
            console.log("complete");
        }
    );
  
ws.send("by default, this will never be sent, because Observer is cold.");
ws.send("by default, this will be sent, because Observer is hot.").publish().connect();
  
ws.setSendMode(WebSocketSendMode.Direct);
ws.send("this will be sent Direct, because send mode is set to Direct.");
  
ws.send("this will be sent and return Promise.", WebSocketSendMode.Promise).then(
        (T) => {
            console.log("is send");
        },
        (T) => {
            console.log("not send");
        }
    );
  
ws.send("this will be sent and return Observer.").subscribe(
        (msg)=> {
            console.log("next", msg.data);
        },
        (msg)=> {
            console.log("error", msg);
        },
        ()=> {
            console.log("complete");
        }
    );

ws.close(false);    // close
ws.close(true);    // close immediately


Binary type

To set the binary type for the websocket one can provide it as string in the constructor. Allowed types are:

  • 'blob' (default)
  • 'arraybuffer'
var ws = new $WebSocket("ws://127.0.0.1:7000", null, null, 'arraybuffer');
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].