question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Primus and angular 2

See original GitHub issue

Version: 4.0.4

Environment:

  • Operating system:All
  • Browser:All
  • Node.js:4

Expected result: Having the possibility to use Primus with typescript for front purpose

Actual result: IDE and compiler keep telling Primus is not defined. If I use the .d.ts it’s not working because the definition is for the server part when I need the client definition.

Steps to reproduce:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app',
  providers: [],
  directives: [],
  styleUrls: [],
  template: ''
})
export class AppComponent implements OnInit {
  ngOnInit() {
    this.initWebsockets();
  }

  private initWebsockets() {
    //
    // Tell primus to create a new connect to the current domain/port/protocol
    //
    const primus = new Primus('http://localhost:3000?token=....');

    //
    // Listen for incoming data and log it in our textarea.
    //
    primus.on('data', function received(data) {
      switch (data.action) {
        case 'create':
          console.log('create');
          break;
        case 'update':
          console.log('update');
          break;
        case 'destroy':
          console.log('destroy');
          break;
        case 'notification':
          console.log('notification');
          break;
      }
      console.log(data);
    });
    //
    // Listen for submits of the form so we can send the message to the server.
    //
    primus.write({action:'join', room:'notification'});
  }
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
stormwincommented, Jul 20, 2016

Get latest version of primus

In config.js where System.config is defined, put this:

meta: {
  "primus": {
    "scriptLoad": true,
    "format": "amd",
    "exports": "primus",
    "build": false
  }
}

and in map object put this:

"primus": "http://localhost:3000/primus/primus.js",

in angular:

import * as Primus from 'primus';
const primus = Primus.connect();
0reactions
stormwincommented, Apr 28, 2019

@justinweathersby 3 years after my last comment and solution… uhhh… lot of things have changed in Angular world since then. Luckily for you, i am still using Angular + Primus and i have new method how to implement and use it in Angular 7. First of all, save client library in some folder of your Angular 7 project. (you can extract it from backend side or start the backend server and get it by url, check the docs) Then you can use it like import * as Primus from ‘place_to_the_file/primus.js’; Somewhere in your code do this for example: this.primusInstance = Primus.connect(url); // Url is url to your site like ‘ws://examplesite.abc’; use primusInstance for data handling, receiving, sending data…

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular-primus - npm
Primus provider for Angular. This plugin works with other Primus plugins like primus-emitter and primus-resource.
Read more >
Ngrx and Angular 2 Tutorial: Building a Reactive Application
In this article, through building a reactive Angular 2 application using Ngrx, you will learn what the pattern is, where the pattern can...
Read more >
Angular 2 · Feathersjs
Using TypeScript. If you're using TypeScript to develop with Angular 2, Feathers and its related modules should be loaded into your app through...
Read more >
Modeling the head of PRIMUS linear accelerator for electron ...
For the beam profiles comparison, the differences ranged from 2% (2 mm) to ... spectra and angular distributions of photons and electrons.
Read more >
PRIMUS Global Services, Inc: Full-Stack .NET Developer – Angular ...
NET Developer – Angular, Azure, Microservices - 100% REMOTE 18237 ... C# and experience with Microsoft Visual Studio, Angular 2, HTML5, JSON and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found