我的发射事件只是不想触发。我是 nodejs 的新手,很抱歉犯了愚蠢的错误,但我无法解决几个小时。
客户端模块
var Client = require('steam');
var EventEmitter = require('events').EventEmitter;
var newClient = function(user, pass){
EventEmitter.call(this);
this.userName = user;
this.password = pass;
var newClient = new Client();
newClient.on('loggedOn', function() {
console.log('Logged in.'); // this work
this.emit('iConnected'); // this don't work
});
newClient.on('loggedOff', function() {
console.log('Disconnected.'); // this work
this.emit('iDisconnected'); // this don't work
});
newClient.on('error', function(e) {
console.log('Error'); // this work
this.emit('iError'); // this don't work
});
}
require('util').inherits(newClient, EventEmitter);
module.exports = newClient;
应用程序.js
var client = new newClient('login', 'pass');
client.on('iConnected', function(){
console.log('iConnected'); // i can't see this event
});
client.on('iError', function(e){
console.log('iError'); // i can't see this event
});