nativescript-nodeify
nativescript-nodeify copied to clipboard
@aspnet/signalr package with nodeify
Hi.
I am trying to connect a nativescript project to a signalr core server. I have already implemented a website made in angular that uses the @aspnet/signalr package. https://www.npmjs.com/package/@aspnet/signalr
Has anyone made that package possible to use in a nativescript project using nodeify?
Thanks for your help and time.
Best regards, Siggi
Did you ever find out how to connect the nativescript project to the signalr core server? I'm having the same issue currently.
Thank you, -Joey
Hello.
I did, I used this package to make it work with Android. https://www.npmjs.com/package/nativescript-signalr-core
It has not been tested yet with IOS
If you are using Azure or Aws servers I needed to setup special settings for it to work. If you are doing similar, I can tell you what I had to do to make it work
Hope this helps
Best regards, Stulli
@stulli103 I'm interested in knowing what you did in Azure and how you configured your client locally. I'm using NS-Vue, but it should hopefully translate.
Hi. In Azure I had to set my App service to set CORS to available, you can then also add your own Available Origins list if you like. It is located under the API branch in the App service list of available functions on the left side,
Then this is a sample code for how the client talks to the signalR server
`
// The signalRCore package uses Websocket´s from another package so this is how the import
// should look like
declare var require;
var WebSocket = require('nativescript-websockets');
import { SignalrCore } from 'nativescript-signalr-core/angular';
// Declare the signalRCore
signalrCore: SignalrCore;
// I initialize it in the constructor and use NgZone and ChangeDetecorRef as well
constructor(
...
private zone: NgZone,
private cd: ChangeDetectorRef
...
) {
...
this.signalrCore = new SignalrCore();
...
}
// Make the connection
ngOnInit(){
this.signalrCore.start('linkToYourServer'+ 'nameOfYourHub').subscribe(() => {
console.log("connected");
setTimeout(() => {
this.joinRoom();
}, 1000);
});
// Add a listener and use ChangeDetectorRef to update the html after receiving the data and
// done some work with it.
this.zone.run(() => {
this.signalrCore.on('functionNameInHere', (data) => {
if (data){
this.sendDataToFunction(data).then(() => {
this.cd.detectChanges();
});
}
})
})
}
// Let user join a group on the SignalR server using the invoke method
joinRoom() {
this.signalrCore.invoke('addtogroup', 'someGroupName');
}
`
Hope this helps