All Projects → sjmf → ng2-mqtt-demo

sjmf / ng2-mqtt-demo

Licence: MIT license
Angular 2 demo using MQTT.js in Typescript

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to ng2-mqtt-demo

cloud-speech-and-vision-demos
A set of demo applications that make use of google speech, nlp and vision apis based in angular2
Stars: ✭ 35 (+9.38%)
Mutual labels:  angular2, angular-cli
Ng Pi Admin
Angular admin http://treesflower.com/ng-pi-admin
Stars: ✭ 131 (+309.38%)
Mutual labels:  angular2, angular-cli
Angular4 Primeng Admin
angular4-primeng-admin @angular/cli开发的后台模板
Stars: ✭ 99 (+209.38%)
Mutual labels:  angular2, angular-cli
Angular Full Stack
Angular Full Stack project built using Angular, Express, Mongoose and Node. Whole stack in TypeScript.
Stars: ✭ 1,261 (+3840.63%)
Mutual labels:  angular2, angular-cli
Angular5 Seed
Angular5 Seed for Application
Stars: ✭ 222 (+593.75%)
Mutual labels:  angular2, angular-cli
Coreui Free Angular Admin Template
CoreUI Angular is free Angular 2+ admin template based on Bootstrap 4
Stars: ✭ 1,279 (+3896.88%)
Mutual labels:  angular2, angular-cli
Ng Packaged
An Angular library packaged by ng-packagr
Stars: ✭ 109 (+240.63%)
Mutual labels:  angular2, angular-cli
Ng Sticky
Angular 4 sticky, have header or any component sticky easy to use.
Stars: ✭ 25 (-21.87%)
Mutual labels:  angular2, angular-cli
Angular4 Docker Example
Efficiently Dockerized Angular CLI example app
Stars: ✭ 212 (+562.5%)
Mutual labels:  angular2, angular-cli
Angular2 Crud Rest
Sample Angular (2.x and 4.x) app: CRUD example + routing
Stars: ✭ 152 (+375%)
Mutual labels:  angular2, angular-cli
Angular2
Angular 2 Seed
Stars: ✭ 75 (+134.38%)
Mutual labels:  angular2, angular-cli
Ng Pokedex
🐵 Pokedex progressive web app built with Angular
Stars: ✭ 245 (+665.63%)
Mutual labels:  angular2, angular-cli
Root Bootstrap 4 Admin Template With Angularjs Angular 2 Support
Root is Boostrap 4 Admin Template with Angular 2 and AngularJS support
Stars: ✭ 54 (+68.75%)
Mutual labels:  angular2, angular-cli
Clever Bootstrap 4 Admin Template With Angularjs Angular 2 Support
Clever is Boostrap 4 Admin Template with Angular 2 and AngularJS support
Stars: ✭ 98 (+206.25%)
Mutual labels:  angular2, angular-cli
Nebular
💥 Customizable Angular UI Library based on Eva Design System 🌚✨Dark Mode
Stars: ✭ 7,368 (+22925%)
Mutual labels:  angular2, angular-cli
Anvel
Angular 2 Laravel Starter Kit
Stars: ✭ 102 (+218.75%)
Mutual labels:  angular2, angular-cli
Cc
一个基于angular5.0.0+ng-bootstrap1.0.0-beta.8+bootstrap4.0.0-beta.2+scss的后台管理系统界面(没基础的同学请先自学基础,谢谢!)
Stars: ✭ 416 (+1200%)
Mutual labels:  angular2, angular-cli
Angular2 Express Starter
Angular 8 and Express 👪 ( Heroku ready )
Stars: ✭ 565 (+1665.63%)
Mutual labels:  angular2, angular-cli
Paper Kit 2 Angular
Free Bootstrap 4 UI Kit for Angular 2+
Stars: ✭ 133 (+315.63%)
Mutual labels:  angular2, angular-cli
Blog Angular
Angular 笔记
Stars: ✭ 238 (+643.75%)
Mutual labels:  angular2, angular-cli

MQTT Angular 2 Demo App

A demo application using Angular 2, Typescript, and mqtt.js. This project uses angular-cli and is a re-write of my earlier example using stomp.js (where I really should have foreseen that the transport doesn't need to be tied to one library. Well, you live and learn.)

This app demonstrates a more ng2-faithful way of connecting to a message queue and subscribing to messages via MQTT. It includes an MQService which subscribes to messages, and an example 'raw data' component which uses the Observable type to data-bind messages to the DOM.

Quick Start

As well as the following, you will also need the appropriate toolchain for Typescript, and a message queue supporting MQTT, such as ActiveMQ.

To get started running this app locally, install angular-cli and the necessary dependencies:

# Clone the repo and cd into it
git clone https://github.com/sjmf/ng2-mqtt-demo
# cd into it
cd ng2-mqtt-demo
# Install the packages from package.json
npm install

You will also need to edit the src/api/config.json configuration file to set the correct connection parameters for your message broker. This file is included with the idea that in a production app, you might want to get credentials for a connection from an API. See the angular-cli instructions for proxying to a backend for more information.

When you've done this, you can run the application locally: run ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

Layout

The source is located under the app folder. Partial tree is below:

├── src                                          * Source folder
│   ├── api                                      * Example API folder (static for demo)
│   │   └── config.json                          * Configuration file for STOMP
│   │
│   ├── app                                      * Application folder
│   │   ├── components                           * Components folder
│   │   │   ├── rawdata                          * Example data streaming component folder
│   │   │   └── status                           * STOMP Status component folder
│   │   │
│   │   ├── pipes                                * Pipes folder
│   │   │
│   │   ├── services                             * Services folder
│   │   │   ├── config                           * Config service folder (retrieves the configuration)
│   │   │   └── mqtt                             * MQTT service folder (ng2 definition for an MQTT configuration)
│   │   │
│   │   ├── app.component.css                    * Component css file
│   │   ├── app.component.html                   * Component html file
│   │   ├── app.component.spec.ts                * Component testings
│   │   ├── app.component.ts                     * Top-level app-root component
│   │   ├── app.module.ts                        * App module definition
│   │   └── index.ts                             * Indexing file
│   │
│   ├── assets                                   * Assets folder
│   │   └── .gitkeep                             * Placeholder to include the folder to source control
│   │
│   ├── environments                             * Environment settings folder
│   │   ├── environment.prod.ts                  * Production environment settings
│   │   └── environment.ts                       * Development environment settings
│   │
│   ├── index.html                               * The root page served to browser
│   ├── main.ts                                  * App bootstrap
│   ├── polyfills.ts                             * Polyfills file
│   ├── styles.css                               * Main css file
│   ├── tsconfig.app.json                        * App Typescript transpiler options
│   └── typings.d.ts                             * Typescript typings definition file
│
├── .angular-cli.json                            * Angular CLI configuration file
├── package.json                                 * Package info and list of dependencies to install
├── tsconfig.json                                * Main Typescript transpiler options
└── tslint.json                                  * Typescript Linter configuration file

Excluded from this partial tree for brevity: sub-component .ts .html etc files under folders, testing framework files, and the e2e End to End testing folder containing app behaviour testings and definitions. The node_modules directory will also be generated for the installed node packages.)

Extending

The example data streaming component provides a demonstration of how to use the MQService to subscribe to a data stream. At its' core, the MQService makes available an Observable which the RawDataComponent uses in its own template, and additionally subscribes its' own on_next method to.

A barebones set-up of the service could run from a component's ngOnInit method, and might look something like this:

this._mqService.configure( config, () => console.log("connected") );
this._mqService.try_connect();

Our RawDataComponent then copies a reference to the public member messages, which can be used with a template variable and the |async pipe to update the template in real time.

The instantiating component must provide an instance of MQService. This implementation also uses a ConfigService to retrieve the MQTT connection variables from a json file, with the intention that other clients might like to route this request to an API along with some form of user token.

The MQTT connection status is also fed-back to the application user via a BehaviorSubject observable, implemented following the model used in this Angular2 stocks app. If the connection fails, the application will retry every 5 seconds until it reopens.

Contributing

Very happy to accept suggestions for improvement (or even pull requests!). Just raise an issue and let me know :) - I'll try and work on it when I get time.

Licence

MIT Licence.

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].