Plugin for signalr core in NativeScript All my code is LICENSED under the MIT License
This plugin dependent on NativeScript WebSockets plugin thanks for nathan@master-technology.com nativescript-websockets
tns plugin add nativescript-websockets
npm install nativescript-signalr-core --save
<uses-permission android:name="android.permission.INTERNET"/>
<application android:usesCleartextTraffic="true">
declare var require;
var WebSocket = require('nativescript-websockets');
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);
});
}