SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. app_module.ts:
  2.  
  3. import { BrowserModule } from '@angular/platform-browser';
  4. import { NgModule } from '@angular/core';
  5. import { SignalRConfiguration, SignalRModule } from 'ng2-signalr'
  6. import { AppComponent } from './app.component';
  7.  
  8. export function createConfig(): SignalRConfiguration {
  9.   const c = new SignalRConfiguration()
  10.   c.url = 'http://localhost:54347/notifications'
  11.   c.hubName = 'TestHub'
  12.   c.qs = { 'access_token': "p6jGmXZajZhRVBmhvmlpSz4mVku7XIvLoEn95vU3FT_sewEzje-4MzwJH38apEZxc6XaXfAKQFZxJADHCwqAPjQ5VPAtcJmf5z3CukoRf6RXJi7zJDmN1s3tfYoc_RYF_CaWMd1AFrfARo2VoHiP6wZIR0E4rFpEbSi3nK2_cD8cKJrdU2HOv_15fMqEldHHOYAi-3AIPDC5jnm3ujtppJlXrrVY69aL50O6QacmtHd5AgShU4qVblmDQvBGycCjB7FCtdpb0xeDsZ1ChBIme3VD6-4GUo8I61ZLuQDwS4K-yw8z7AHQKc3v7j2Nk77QEVeWQsYJA76JoeQms93hRLQpP5Y5zBBLJckyFQfryON582jGUxzC1_sp72z-Ic_3LS_GXrWgOU7gHVuTtXmpY_fAhiLXszG5jTHJaKmn0-f9t5J_Mv2M8o2sUpH2bZ-y" }
  13.   c.logging = true
  14.   return c
  15. }
  16.  
  17. @NgModule({
  18.   declarations: [
  19.     AppComponent
  20.   ],
  21.   imports: [
  22.     BrowserModule, SignalRModule.forRoot(createConfig)
  23.   ],
  24.   providers: [],
  25.   bootstrap: [AppComponent]
  26. })
  27. export class AppModule { }
  28.  
  29.  
  30. app.component.ts:
  31. import { Component } from '@angular/core';
  32. import { BroadcastEventListener, IConnectionOptions, ISignalRConnection, SignalR } from 'ng2-signalr'
  33.  
  34. @Component({
  35.   selector: 'app-root',
  36.   templateUrl: './app.component.html',
  37.   styleUrls: ['./app.component.css']
  38. })
  39. export class AppComponent {
  40.   title = 'this crazy beautiful website';
  41.  
  42.   constructor(private _signalR: SignalR)  {
  43.  }
  44. ngOnInit() {
  45.  }
  46.  
  47.  connect() {
  48.     let o: IConnectionOptions;
  49.     let conx = this._signalR.createConnection();
  50.     conx.status.subscribe((s) => console.warn(s.name));
  51.     conx.start().then((c) => {
  52.       console.log(c.status);
  53.       console.log('Connected?');
  54.       let listener = c.listenForRaw('send');
  55.       listener.subscribe((data: any[]) => {
  56.               console.log(data);
  57.  
  58.       });
  59.       c.invoke('SendToAll', c.id, "test").then((data: string[]) => {
  60.           // var test = data;
  61.           // console.log(c.id);
  62.           // console.log(data);
  63.       });
  64.     });
  65.   }
  66.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top