Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@aspnet/signalr package with nodeify #60

Open
stulli103 opened this issue May 5, 2019 · 4 comments
Open

@aspnet/signalr package with nodeify #60

stulli103 opened this issue May 5, 2019 · 4 comments

Comments

@stulli103
Copy link

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

@joeytitans
Copy link

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

@stulli103
Copy link
Author

stulli103 commented Jun 6, 2019

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

@jawa-the-hutt
Copy link

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

@stulli103
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants