2.0.0 • Published 4 years ago
nativescript-signalr-core v2.0.0
Nativescript Signalr Core
Plugin for signalr core in NativeScript All my code is LICENSED under the MIT License
Requirements
This plugin dependent on NativeScript WebSockets plugin thanks for nathan@master-technology.com nativescript-websockets
Installation
tns plugin add nativescript-websockets
npm install nativescript-signalr-core --save
Android
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
<application android:usesCleartextTraffic="true">
How To use nativescript signalr core ?
main.tns.ts
declare var require;
var WebSocket = require('nativescript-websockets');
Home.component.ts
In NativeScript + Angular 7
import {Component, OnInit, NgZone, ChangeDetectorRef} from '@angular/core';
import { SignalrCore } from 'nativescript-signalr-core/angular';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss'],
})
export class HomeComponent implements OnInit {
header: SignalRCoreRHeaders;
constructor(private zone: NgZone, private cd: ChangeDetectorRef) {
this.signalrCore = new SignalrCore();
this.header = new SignalRCoreRHeaders('Authorization', 'myToken'); //(this.header Optional)
this.signalrCore.on('connected', (data) => {
console.log('connected');
});
}
connectToServer() {
this.signalrCore.start('http://server.com/ChatHub', this.header).then((isConnected: boolean) => {
console.log('isConnected? ', isConnected);
});
}
invoke() {
this.signalrCore.invoke('initializeDeviceAsync', '');
}
stop() {
this.signalrCore.close().then((res) => {
console.log('closed...', res);
});
}