Skip to content

Commit

Permalink
EventEmitter#off: add deprecation warning
Browse files Browse the repository at this point in the history
(elsewhere): don't call #off except for in its tests
  • Loading branch information
joseph-onsip committed Oct 5, 2014
1 parent b0e3891 commit a160b80
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Dialog/RequestSender.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ RequestSender.prototype = {
this.state === SIP.Transactions.C.STATUS_COMPLETED ||
this.state === SIP.Transactions.C.STATUS_TERMINATED) {

this.off('stateChanged', stateChanged);
this.removeListener('stateChanged', stateChanged);
self.dialog.uac_pending_reply = false;

if (self.dialog.uas_pending_reply === false) {
Expand Down
2 changes: 1 addition & 1 deletion src/Dialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Dialog.prototype = {
this.state === SIP.Transactions.C.STATUS_COMPLETED ||
this.state === SIP.Transactions.C.STATUS_TERMINATED) {

this.off('stateChanged', stateChanged);
this.removeListener('stateChanged', stateChanged);
self.uas_pending_reply = false;

if (self.uac_pending_reply === false) {
Expand Down
8 changes: 8 additions & 0 deletions src/EventEmitter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
var NodeEventEmitter = require('events').EventEmitter;
var console = require('console');

function EventEmitter () {}

EventEmitter.prototype = Object.create(NodeEventEmitter.prototype);

EventEmitter.prototype.off = function off (eventName, listener) {
var warning = '';
warning += 'SIP.EventEmitter#off is deprecated and may be removed in future SIP.js versions.\n';
warning += 'Please use removeListener or removeAllListeners instead.\n';
warning += 'See here for more details:\n';
warning += 'http://nodejs.org/api/events.html#events_emitter_removelistener_event_listener';
console.warn(warning);

if (arguments.length < 2) {
return this.removeAllListeners.apply(this, arguments);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/UA.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ UA.prototype.stop = function() {

function transactionsListener() {
if (ua.nistTransactionsCount === 0 && ua.nictTransactionsCount === 0) {
ua.off('transactionDestroyed', transactionsListener);
ua.removeListener('transactionDestroyed', transactionsListener);
ua.transport.disconnect();
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/spec/SpecEventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ describe('EventEmitter', function () {
describe('.emit', function () {
var foo, bar, that;
function removeSelf () {
EventEmitter.off('aaa', removeSelf);
EventEmitter.removeListener('aaa', removeSelf);
}

beforeEach(function () {
Expand Down Expand Up @@ -292,7 +292,7 @@ describe('EventEmitter', function () {
});

it('ignores off listeners', function () {
EventEmitter.off('aaa', foo);
EventEmitter.removeListener('aaa', foo);
EventEmitter.emit('aaa');
expect(foo).not.toHaveBeenCalled();
expect(bar).toHaveBeenCalled();
Expand Down
4 changes: 2 additions & 2 deletions test/spec/SpecUA.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ describe('UA', function() {
});

it('disconnects from the Web Socket if after transaction destroyed is emitted once there are no non-invite transactions left', function () {
spyOn(UA, 'off');
spyOn(UA, 'removeListener');

//note: you can't explicitly set the *TransactionsCount properties of the UA, they are set by checking the length of the corresponding transactions array

Expand All @@ -250,7 +250,7 @@ describe('UA', function() {
UA.transactions['nict'] = [];
UA.emit('transactionDestroyed');
expect(UA.transport.disconnect).toHaveBeenCalled();
expect(UA.off).toHaveBeenCalled();
expect(UA.removeListener).toHaveBeenCalled();
});
});

Expand Down

0 comments on commit a160b80

Please sign in to comment.