1

私の発行イベントは発火したくありません。私は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;

app.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
});
4

2 に答える 2