SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 60 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.  
  31.  
  32.  
  33.  
  34. app.component.ts:
  35. import { Component } from '@angular/core';
  36. import { BroadcastEventListener, IConnectionOptions, ISignalRConnection, SignalR } from 'ng2-signalr'
  37.  
  38. @Component({
  39.   selector: 'app-root',
  40.   templateUrl: './app.component.html',
  41.   styleUrls: ['./app.component.css']
  42. })
  43. export class AppComponent {
  44.   title = 'this crazy beautiful website';
  45.  
  46.   constructor(private _signalR: SignalR)  {
  47.  }
  48. ngOnInit() {
  49.  }
  50.  
  51.  connect() {
  52.     let o: IConnectionOptions;
  53.     let conx = this._signalR.createConnection();
  54.     conx.status.subscribe((s) => console.warn(s.name));
  55.     conx.start().then((c) => {
  56.       console.log(c.status);
  57.       console.log('Connected?');
  58.       let listener = c.listenForRaw('send');
  59.       listener.subscribe((data: any[]) => {
  60.               console.log(data);
  61.  
  62.       });
  63.       c.invoke('SendToAll', c.id, "test").then((data: string[]) => {
  64.           // var test = data;
  65.           // console.log(c.id);
  66.           // console.log(data);
  67.       });
  68.     });
  69.   }
  70.   }
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