Ngxi4SocketClient
This library was generated by Doan Quoc Cuong (cuongdq.payment@gmail.com)
Install:
Run npm to get service for using.
npm install ngxi4-socket-client --save
npm install ngx-device-detector ngx-socket-io --save
npm install ngxi4-dynamic-service --save
npm install croppie crypto-js exif-js simple-crypto-js --save
npm install ngx-barcode@0.2.4 ngx-image-cropper ngx-qrcode2@0.0.9 ngx-webcam@0.2.6 --save
npm install @ionic/angular@4.7.1 ng-multiselect-dropdown@0.2.10
npm install @ionic-native/sqlite --save
npm i ngx-webstorage-service --save
npm install ngx-qrcode2@latest
Download JsEncrypt and copy in assets/js/jsencrypt.js
http://travistidwell.com/jsencrypt/
<!-- Save in src/assets/js/jsencrypt.js -->
Add javascript jsencrypt.js in angular.json
{
"projects": {
"app": {
"architect": {
"build": {
"scripts": [
"src/assets/js/jsencrypt.js"
]
},
}
}
},
}
Use:
1. add in ./app.module.ts
import { Ngxi4SocketClientModule } from 'ngxi4-socket-client'
@NgModule({
imports: [
Ngxi4SocketClientModule.forRoot()
)
]
})
2. add to ./app.component.ts
import { Component } from '@angular/core';
import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { ApiSocketService } from './services/api-socket.service';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss']
})
export class AppComponent {
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private apiSocket: ApiSocketService
) {
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
this.init();
});
}
init() {
this.apiSocket.init()
}
}
3. add to ./my-home.page.ts
import { Component, HostListener } from '@angular/core';
import { CommonsService } from 'ngxi4-dynamic-service';
import { ApiSocketService } from '../services/api-socket.service';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
isMobile: boolean = false;
socketConnection: any;
@HostListener('window:resize', ['$event'])
onResize(event) {
this.isMobile = event.target.innerWidth < 576;
}
constructor(
private apiCommon: CommonsService
, private apiSocket: ApiSocketService
) { this.init() }
init() {
this.isMobile = this.apiCommon.isMobile()
this.socketConnection = this.apiSocket.getConnection();
}
onClickUser() {
if (this.socketConnection.userInfo) {
this.apiSocket.sendSocketIo("client-req-command", { command: "GET-MY-USER" })
} else {
this.apiSocket.sendSocketIo("client-req-command", { command: "LOGIN" })
}
}
onClickDevice() {
if (this.socketConnection.device_online) {
this.apiSocket.sendSocketIo("client-req-command", { command: "GET-MY-DEVICE" })
}
}
}