0.2.4 • Published 6 years ago

blast-angular2 v0.2.4

Weekly downloads
2
License
MIT
Repository
-
Last release
6 years ago

Blast-Angular2

Alt text with Alt text

Overview

This is a websocket client for Angular2 projects for connection to a Blast Server. It is a simple wrapper around the default 'WebSocket' implementation, offering additional features like 'reconnect' and the ability to queue messages before connect.

Getting Started

    npm install blast-angular2

Usage

Connect

const blastService: BlastService = new BlastService('ws://127.0.0.1:8081/blast');

Connection Options

 new BlastService(URL,[AutoConnect],[Protocols],[BlastConfig]);
ParameterTypeDescription
URLstringMandatoryURL with sever port and endpoint (default Blast Server is '/blast' - but this is configurable server side
AutoConnectbooleanOptional (default is 'true')- if true, establish a connection immediately, if 'false' then a call to *connect() is required
Protocolsstring[]Optional (default empty)Sebsocket protocols
BlastConfigBlastServiceConfigOptional (default is {initialTimeout: 500, maxTimeout: 300000, reconnectIfNotNormalClose: true})Set following: 'initialTimeout','maxTimeout','reconnectIfNotNormalClose'

Commands

CommandDescription
connectEstablish a connection (Only required if AutoConnect in constructor is manually set to false)
closeManually close the connection

Callbacks

CallBackDescription
OnOpenWhen a connection is established
OnCloseWhen a connection is lost
OnErrorWhen there is an error
OnMessageWhen a message is received

Example

this.blastService.onMessage((msg: any) => {
    // we received a message
    console.log('message',msg.data);
});

Observer

Monitor inbound messages via an 'Observer'

this.blastService.getDataStream().subscribe(
    (msg)=> {
        console.log("next", msg.data);
    },
    (msg)=> {
        console.log("error", msg);
    },
    ()=> {
        console.log("complete");
    }
);

// To send a message
blastService.send("Hello World");

Development

If modifying the core source code then:

   npm run setup

NPM Commands

CommandDescription
npm run lintruns lint
npm run compilecompiles tyepscript
npm run minifyminifies the output javascript
npm run bundleincludes any 3rd party libraries
npm run bundle-minifyminifies the bundle
npm run prepublishruns all above commands
npm run devlint,compile and npm link

Note: Although the main objective for this project is a 'npm module' it also serves as the build for our native javascript library.

to build .. npm run packagr npm publish dist

0.2.4

6 years ago

0.2.3

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.0.4

7 years ago

0.0.2

7 years ago