eventemitter

Emitting event in Node.js

半世苍凉 提交于 2019-12-13 07:36:38
问题 I'm trying to teach myself both javascript and nodejs at the same time here and have not been able to get custom event emitting working. I am not receiving any errors, just not seeing the event being emitted. Is someone able to point out my (likely obvious) logical error? I have a class declared in a separate module: var util = require( 'util' ), events = require( 'events' ); function logger(){ var logpath, initialised, logstream; events.EventEmitter.call(this); } util.inherits(logger, events

Check if object is instance of EventEmitter

♀尐吖头ヾ 提交于 2019-12-13 05:33:26
问题 I am a looking for a way, other than duck typing, to discover if an object inherits from EventEmitter https://nodejs.org/api/events.html I suppose I could just check if the object has a couple of those functions that event emitters have been this is just dirty. Is there a better way to do this with Node.js? Also, if there is a way to determine if something is a stream on top of being an event emitter, that would be useful too. 回答1: To check if an object is an instance of an EventEmmitter you

I want an eventemitter that works across a network

人走茶凉 提交于 2019-12-13 05:19:53
问题 I really like the EventEmitter paradigm, and I'd like to use it to communicate between two programs across a network. I came up with my own SockEmitter , but I want to know: am I "doing it wrong(tm)"? Is there some package that will already do this? Is there a different paradigm that works better for communicating across a network? Here's what I have: var JsonSocket = require('json-socket') // An event emitter that uses a JsonSocket. // emit passes things over the wire, and data received //

RxJS - Create Observable from an EventEmitter's multiple events

余生颓废 提交于 2019-12-13 03:35:46
问题 I have a node.js EventEmitter which raises the following events: error , message . Is there a straight forward way I can create an RxJS Observable from it? i.e next() called on message and error() called on error . 回答1: You can create it like this: const obs$ = Observable.create(observer => { emitter.on('message', val => observer.next(val)); emitter.on('error', err => observer.error(err)); }); As an alternative, you can do this by constructinng and chaining observables like this, but it's

Interaction between expressjs, socket.io and EventEmitter listeners

隐身守侯 提交于 2019-12-12 23:04:11
问题 I have a server setup using expressjs which communicates with the front end clients using socket.io. The server runs on the raspberry pi and provides a backend to control mplayer player for my music library using the mplayer nodejs module. Most of the actions to update the clients on the front end are taken based on events emitted by the mplayer EventEmitter module. For example : When a command to stop the player is issued as player.stop() the EventEmitter instance of the player emits 'stop'

Emit and broadcast events throughout application in Angular

大兔子大兔子 提交于 2019-12-12 09:58:43
问题 Is there a way to emit event in angular2 that can be listened to in entire application? Like we had in AngularJS using $rootScope.broadcast and emit . Can this same thing be achieved in angular2? I read about @Output() and EventEmitter() and implemented it but it restricts only the parent to listen to the event emmitted by child. I read about BehaviorSubject being one of the ways to do this. Is that the right approach? Any other solution for this? 回答1: In Angular2 there is no global scope.

Node ES6 class event emitter function?

微笑、不失礼 提交于 2019-12-12 06:38:05
问题 I'm trying to create a class for which all instances respond to an event: const events = require("events"); const eventEmitter = new events.EventEmitter(); class Camera { constructor(ip) { this.ip = ip; } eventEmitter.on("recordVideo", recordClip); recordClip() { console.log("running record video"); } } // emit event once a minute setInterval(function(){ eventEmitter.emit('recordVideo'); }, 1000*60); The recordClip function never seems to be called. Is this possible? I also tried running this

Angular2 How to pass selected value to other component

拟墨画扇 提交于 2019-12-12 02:26:14
问题 Hi I am tryng to pass value selected from one of the options. I used ngModel to save the value but I can't figure out how to pass it to other component. Since they are connected but not nested, I couldn't use Eventemitter cause I reckon to use Eventemiiter, I should use child component's selector to nest the component in the parent component which I do not want to do. These two components are seperated and I want to pass selected value to the other component? How can I achieve this? Below is

How to create component dynamically with @Output EventEmitter

柔情痞子 提交于 2019-12-11 17:14:26
问题 There are 2 uses for the my-select component: the use-my-select.html template created dynamically. It works in the template but not when created dynamically. How do I create the my-select component dynamically so that mySelected() is called? my-select.ts @Component({ selector: 'my-select', templateUrl: './my-select.html' }) export class MYSelect { @Output() mySelected: EventEmitter<string> = new EventEmitter(); } use-my-select.html <my-select (mySelected)="mySelected($event)" ></my-select>

angular2- how to communicate between two separate components?

混江龙づ霸主 提交于 2019-12-11 05:49:47
问题 I am working on this angular2 project. I have 2 components i.e. WorkspacesComponent & PagesComponent . in database,each workspace contains number of pages. I have written below code to populate list of workspaces in workspacesComponent & list of pages in PagesComponent. getting workspaces from database this.workspaceService.getAllWorkspaces(this.baseUrl) .subscribe((workspaces) => { this.workspaces = workspaces; console.log(this.workspaces); } ); getting pages from databases this.pagesService