amqplib 0.4.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/Makefile +1 -1
  3. package/README.md +26 -17
  4. package/callback_api.js +1 -0
  5. package/channel_api.js +7 -6
  6. package/examples/headers.js +2 -2
  7. package/examples/receive_generator.js +39 -0
  8. package/examples/send_generators.js +42 -0
  9. package/examples/ssl.js +1 -1
  10. package/examples/tutorials/README.md +1 -1
  11. package/examples/tutorials/callback_api/emit_log.js +1 -1
  12. package/examples/tutorials/callback_api/emit_log_direct.js +1 -1
  13. package/examples/tutorials/callback_api/emit_log_topic.js +1 -1
  14. package/examples/tutorials/callback_api/new_task.js +1 -1
  15. package/examples/tutorials/callback_api/rpc_client.js +1 -1
  16. package/examples/tutorials/callback_api/rpc_server.js +1 -1
  17. package/examples/tutorials/callback_api/send.js +1 -1
  18. package/examples/tutorials/emit_log.js +4 -5
  19. package/examples/tutorials/emit_log_direct.js +4 -5
  20. package/examples/tutorials/emit_log_topic.js +4 -5
  21. package/examples/tutorials/new_task.js +5 -6
  22. package/examples/tutorials/package.json +2 -3
  23. package/examples/tutorials/receive.js +4 -4
  24. package/examples/tutorials/receive_logs.js +1 -1
  25. package/examples/tutorials/receive_logs_direct.js +2 -2
  26. package/examples/tutorials/receive_logs_topic.js +6 -6
  27. package/examples/tutorials/rpc_client.js +25 -26
  28. package/examples/tutorials/rpc_server.js +2 -2
  29. package/examples/tutorials/send.js +10 -6
  30. package/examples/tutorials/worker.js +1 -1
  31. package/examples/waitForConfirms.js +2 -2
  32. package/lib/callback_model.js +13 -12
  33. package/lib/channel.js +2 -2
  34. package/lib/channel_model.js +58 -66
  35. package/lib/codec.js +64 -38
  36. package/lib/connect.js +33 -12
  37. package/lib/connection.js +7 -6
  38. package/lib/credentials.js +6 -3
  39. package/lib/defs.js +75 -75
  40. package/lib/frame.js +2 -1
  41. package/lib/heartbeat.js +1 -1
  42. package/package.json +4 -3
  43. package/test/callback_api.js +6 -5
  44. package/test/channel.js +52 -46
  45. package/test/channel_api.js +125 -136
  46. package/test/codec.js +48 -9
  47. package/test/connect.js +63 -3
  48. package/test/connection.js +10 -9
  49. package/test/data.js +32 -9
  50. package/test/frame.js +4 -4
  51. package/test/util.js +33 -19
  52. package/.npmignore +0 -9
@@ -31,9 +31,9 @@ amqp.connect('amqp://localhost').then(function(conn) {
31
31
  console.log(' [.] fib(%d)', n);
32
32
  var response = fib(n);
33
33
  ch.sendToQueue(msg.properties.replyTo,
34
- new Buffer(response.toString()),
34
+ Buffer.from(response.toString()),
35
35
  {correlationId: msg.properties.correlationId});
36
36
  ch.ack(msg);
37
37
  }
38
38
  });
39
- }).then(null, console.warn);
39
+ }).catch(console.warn);
@@ -1,19 +1,23 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  var amqp = require('amqplib');
4
- var when = require('when');
5
4
 
6
5
  amqp.connect('amqp://localhost').then(function(conn) {
7
- return when(conn.createChannel().then(function(ch) {
6
+ return conn.createChannel().then(function(ch) {
8
7
  var q = 'hello';
9
8
  var msg = 'Hello World!';
10
9
 
11
10
  var ok = ch.assertQueue(q, {durable: false});
12
-
11
+
13
12
  return ok.then(function(_qok) {
14
- ch.sendToQueue(q, new Buffer(msg));
13
+ // NB: `sentToQueue` and `publish` both return a boolean
14
+ // indicating whether it's OK to send again straight away, or
15
+ // (when `false`) that you should wait for the event `'drain'`
16
+ // to fire before writing again. We're just doing the one write,
17
+ // so we'll ignore it.
18
+ ch.sendToQueue(q, Buffer.from(msg));
15
19
  console.log(" [x] Sent '%s'", msg);
16
20
  return ch.close();
17
21
  });
18
- })).ensure(function() { conn.close(); });
19
- }).then(null, console.warn);
22
+ }).finally(function() { conn.close(); });
23
+ }).catch(console.warn);
@@ -25,4 +25,4 @@ amqp.connect('amqp://localhost').then(function(conn) {
25
25
  }, secs * 1000);
26
26
  }
27
27
  });
28
- }).then(null, console.warn);
28
+ }).catch(console.warn);
@@ -12,11 +12,11 @@ function mkCallback(i) {
12
12
  amqp.connect().then(function(c) {
13
13
  c.createConfirmChannel().then(function(ch) {
14
14
  for (var i=0; i < NUM_MSGS; i++) {
15
- ch.publish('amq.topic', 'whatever', new Buffer('blah'), {}, mkCallback(i));
15
+ ch.publish('amq.topic', 'whatever', Buffer.from('blah'), {}, mkCallback(i));
16
16
  }
17
17
  ch.waitForConfirms().then(function() {
18
18
  console.log('All messages done');
19
19
  c.close();
20
- }, console.error);
20
+ }).catch(console.error);
21
21
  });
22
22
  });
@@ -5,7 +5,7 @@
5
5
  'use strict';
6
6
 
7
7
  var defs = require('./defs');
8
- var when = require('when'), defer = when.defer;
8
+ var Promise = require('bluebird');
9
9
  var inherits = require('util').inherits;
10
10
  var EventEmitter = require('events').EventEmitter;
11
11
  var BaseChannel = require('./channel').BaseChannel;
@@ -215,7 +215,7 @@ Channel.prototype.get = function(queue, options, cb0) {
215
215
  if (f.id === defs.BasicGetEmpty) {
216
216
  cb(null, false);
217
217
  }
218
- else if (f.id = defs.BasicGetOk) {
218
+ else if (f.id === defs.BasicGetOk) {
219
219
  self.handleMessage = acceptMessage(function(m) {
220
220
  m.fields = f.fields;
221
221
  cb(null, m);
@@ -308,20 +308,21 @@ ConfirmChannel.prototype.sendToQueue = function(queue, content,
308
308
  };
309
309
 
310
310
  ConfirmChannel.prototype.waitForConfirms = function(k) {
311
- var await = [];
311
+ var awaiting = [];
312
312
  var unconfirmed = this.unconfirmed;
313
313
  unconfirmed.forEach(function(val, index) {
314
314
  if (val === null); // already confirmed
315
315
  else {
316
- var confirmed = defer();
317
- unconfirmed[index] = function(err) {
318
- if (val) val(err);
319
- if (err === null) confirmed.resolve();
320
- else confirmed.reject(err);
321
- };
322
- await.push(confirmed.promise);
316
+ var confirmed = new Promise(function(resolve, reject) {
317
+ unconfirmed[index] = function(err) {
318
+ if (val) val(err);
319
+ if (err === null) resolve();
320
+ else reject(err);
321
+ };
322
+ });
323
+ awaiting.push(confirmed);
323
324
  }
324
325
  });
325
- return when.all(await).then(function() { k(); },
326
- function(err) { k(err); });
326
+ return Promise.all(awaiting).then(function() { k(); },
327
+ function(err) { k(err); });
327
328
  };
package/lib/channel.js CHANGED
@@ -16,7 +16,7 @@ var EventEmitter = require('events').EventEmitter;
16
16
  var fmt = require('util').format;
17
17
  var IllegalOperationError = require('./error').IllegalOperationError;
18
18
  var stackCapture = require('./error').stackCapture;
19
-
19
+ var Buffer = require('safe-buffer').Buffer
20
20
  function Channel(connection) {
21
21
  EventEmitter.call( this );
22
22
  this.connection = connection;
@@ -286,7 +286,7 @@ function acceptMessage(continuation) {
286
286
 
287
287
  // for zero-length messages, content frames aren't required.
288
288
  if (totalSize === 0) {
289
- message.content = new Buffer(0);
289
+ message.content = Buffer.alloc(0);
290
290
  continuation(message);
291
291
  return acceptDeliveryOrReturn;
292
292
  }
@@ -5,7 +5,7 @@
5
5
  'use strict';
6
6
 
7
7
  var defs = require('./defs');
8
- var when = require('when'), defer = when.defer;
8
+ var Promise = require('bluebird');
9
9
  var inherits = require('util').inherits;
10
10
  var EventEmitter = require('events').EventEmitter;
11
11
  var BaseChannel = require('./channel').BaseChannel;
@@ -29,12 +29,7 @@ module.exports.ChannelModel = ChannelModel;
29
29
  var CM = ChannelModel.prototype;
30
30
 
31
31
  CM.close = function() {
32
- var closed = defer();
33
- this.connection.close(function (err) {
34
- if (err === null) closed.resolve();
35
- else closed.reject(err);
36
- });
37
- return closed.promise;
32
+ return Promise.fromCallback(this.connection.close.bind(this.connection));
38
33
  };
39
34
 
40
35
  // Channels
@@ -59,17 +54,18 @@ var C = Channel.prototype;
59
54
  // response's fields; this is intended to be suitable for implementing
60
55
  // API procedures.
61
56
  C.rpc = function(method, fields, expect) {
62
- var reply = defer();
63
- this._rpc(method, fields, expect, function(err, f) {
64
- if (err !== null) reply.reject(err);
65
- else reply.resolve(f.fields);
57
+ var self = this;
58
+ return Promise.fromCallback(function(cb) {
59
+ return self._rpc(method, fields, expect, cb);
60
+ })
61
+ .then(function(f) {
62
+ return f.fields;
66
63
  });
67
- return reply.promise;
68
64
  };
69
65
 
70
66
  // Do the remarkably simple channel open handshake
71
67
  C.open = function() {
72
- return when.try(this.allocate.bind(this)).then(
68
+ return Promise.try(this.allocate.bind(this)).then(
73
69
  function(ch) {
74
70
  return ch.rpc(defs.ChannelOpen, {outOfBand: ""},
75
71
  defs.ChannelOpenOk);
@@ -77,10 +73,11 @@ C.open = function() {
77
73
  };
78
74
 
79
75
  C.close = function() {
80
- var closed = defer();
81
- this.closeBecause("Goodbye", defs.constants.REPLY_SUCCESS,
82
- closed.resolve)
83
- return closed.promise;
76
+ var self = this;
77
+ return Promise.fromCallback(function(cb) {
78
+ return self.closeBecause("Goodbye", defs.constants.REPLY_SUCCESS,
79
+ cb);
80
+ });
84
81
  };
85
82
 
86
83
  // === Public API, declaring queues and stuff ===
@@ -151,7 +148,7 @@ C.bindExchange = function(dest, source, pattern, argt) {
151
148
  C.unbindExchange = function(dest, source, pattern, argt) {
152
149
  return this.rpc(defs.ExchangeUnbind,
153
150
  Args.unbindExchange(dest, source, pattern, argt),
154
- defs.ExchangeUnbindOk);
151
+ defs.ExchangeUnbindOk);
155
152
  };
156
153
 
157
154
  // Working with messages
@@ -170,58 +167,52 @@ C.consume = function(queue, callback, options) {
170
167
  // NB we want the callback to be run synchronously, so that we've
171
168
  // registered the consumerTag before any messages can arrive.
172
169
  var fields = Args.consume(queue, options);
173
- var reply = defer();
174
- this._rpc(defs.BasicConsume, fields, defs.BasicConsumeOk,
175
- function(err, ok) {
176
- if (err === null) {
177
- self.registerConsumer(ok.fields.consumerTag,
178
- callback);
179
- reply.resolve(ok.fields);
180
- }
181
- else reply.reject(err);
182
- });
183
- return reply.promise;
170
+ return Promise.fromCallback(function(cb) {
171
+ self._rpc(defs.BasicConsume, fields, defs.BasicConsumeOk, cb);
172
+ })
173
+ .then(function(ok) {
174
+ self.registerConsumer(ok.fields.consumerTag, callback);
175
+ return ok.fields;
176
+ });
184
177
  };
185
178
 
186
179
  C.cancel = function(consumerTag) {
187
180
  var self = this;
188
- var reply = defer();
189
- this._rpc(defs.BasicCancel, Args.cancel(consumerTag),
190
- defs.BasicCancelOk,
191
- function(err, ok) {
192
- if (err === null) {
193
- self.unregisterConsumer(consumerTag);
194
- reply.resolve(ok.fields);
195
- }
196
- else reply.reject(err);
197
- });
198
- return reply.promise;
181
+ return Promise.fromCallback(function(cb) {
182
+ self._rpc(defs.BasicCancel, Args.cancel(consumerTag),
183
+ defs.BasicCancelOk,
184
+ cb);
185
+ })
186
+ .then(function(ok) {
187
+ self.unregisterConsumer(consumerTag);
188
+ return ok.fields;
189
+ });
199
190
  };
200
191
 
201
192
  C.get = function(queue, options) {
202
- var reply = defer();
203
193
  var self = this;
204
194
  var fields = Args.get(queue, options);
205
- this.sendOrEnqueue(defs.BasicGet, fields, function(err, f) {
206
- if (err === null) {
207
- if (f.id === defs.BasicGetEmpty) {
208
- reply.resolve(false);
209
- }
210
- else if (f.id === defs.BasicGetOk) {
211
- var fields = f.fields;
195
+ return Promise.fromCallback(function(cb) {
196
+ return self.sendOrEnqueue(defs.BasicGet, fields, cb);
197
+ })
198
+ .then(function(f) {
199
+ if (f.id === defs.BasicGetEmpty) {
200
+ return false;
201
+ }
202
+ else if (f.id === defs.BasicGetOk) {
203
+ var fields = f.fields;
204
+ return new Promise(function(resolve) {
212
205
  self.handleMessage = acceptMessage(function(m) {
213
206
  m.fields = fields;
214
- reply.resolve(m);
207
+ resolve(m);
215
208
  });
216
- }
217
- else {
218
- reply.reject(new Error("Unexpected response to BasicGet: " +
219
- inspect(f)));
220
- }
209
+ });
221
210
  }
222
- else reply.reject(err);
223
- });
224
- return reply.promise;
211
+ else {
212
+ throw new Error("Unexpected response to BasicGet: " +
213
+ inspect(f));
214
+ }
215
+ })
225
216
  };
226
217
 
227
218
  C.ack = function(message, allUpTo) {
@@ -308,19 +299,20 @@ CC.sendToQueue = function(queue, content, options, cb) {
308
299
  };
309
300
 
310
301
  CC.waitForConfirms = function() {
311
- var await = [];
302
+ var awaiting = [];
312
303
  var unconfirmed = this.unconfirmed;
313
304
  unconfirmed.forEach(function(val, index) {
314
305
  if (val === null); // already confirmed
315
306
  else {
316
- var confirmed = defer();
317
- unconfirmed[index] = function(err) {
318
- if (val) val(err);
319
- if (err === null) confirmed.resolve();
320
- else confirmed.reject(err);
321
- };
322
- await.push(confirmed.promise);
307
+ var confirmed = new Promise(function(resolve, reject) {
308
+ unconfirmed[index] = function(err) {
309
+ if (val) val(err);
310
+ if (err === null) resolve();
311
+ else reject(err);
312
+ };
313
+ });
314
+ awaiting.push(confirmed);
323
315
  }
324
316
  });
325
- return when.all(await);
317
+ return Promise.all(awaiting);
326
318
  };
package/lib/codec.js CHANGED
@@ -1,4 +1,4 @@
1
- //
1
+ //
2
2
  //
3
3
  //
4
4
 
@@ -110,6 +110,40 @@ function encodeFieldValue(buffer, value, offset) {
110
110
  type = value['!'];
111
111
  }
112
112
 
113
+ // If it's a JS number, we'll have to guess what type to encode it
114
+ // as.
115
+ if (type == 'number') {
116
+ // Making assumptions about the kind of number (floating point
117
+ // v integer, signed, unsigned, size) desired is dangerous in
118
+ // general; however, in practice RabbitMQ uses only
119
+ // longstrings and unsigned integers in its arguments, and
120
+ // other clients generally conflate number types anyway. So
121
+ // the only distinction we care about is floating point vs
122
+ // integers, preferring integers since those can be promoted
123
+ // if necessary. If floating point is required, we may as well
124
+ // use double precision.
125
+ if (isFloatingPoint(val)) {
126
+ type = 'double';
127
+ }
128
+ else { // only signed values are used in tables by
129
+ // RabbitMQ. It *used* to (< v3.3.0) treat the byte 'b'
130
+ // type as unsigned, but most clients (and the spec)
131
+ // think it's signed, and now RabbitMQ does too.
132
+ if (val < 128 && val >= -128) {
133
+ type = 'byte';
134
+ }
135
+ else if (val >= -0x8000 && val < 0x8000) {
136
+ type = 'short'
137
+ }
138
+ else if (val >= -0x80000000 && val < 0x80000000) {
139
+ type = 'int';
140
+ }
141
+ else {
142
+ type = 'long';
143
+ }
144
+ }
145
+ }
146
+
113
147
  function tag(t) { buffer.write(t, offset); offset++; }
114
148
 
115
149
  switch (type) {
@@ -141,44 +175,36 @@ function encodeFieldValue(buffer, value, offset) {
141
175
  tag('t');
142
176
  buffer.writeUInt8((val) ? 1 : 0, offset); offset++;
143
177
  break;
144
- case 'number':
145
- // Making assumptions about the kind of number (floating point
146
- // v integer, signed, unsigned, size) desired is dangerous in
147
- // general; however, in practice RabbitMQ uses only
148
- // longstrings and unsigned integers in its arguments, and
149
- // other clients generally conflate number types anyway. So
150
- // the only distinction we care about is floating point vs
151
- // integers, preferring integers since those can be promoted
152
- // if necessary. If floating point is required, we may as well
153
- // use double precision.
154
- if (isFloatingPoint(val)) {
155
- tag('d');
156
- buffer.writeDoubleBE(val, offset);
157
- offset += 8;
158
- }
159
- else { // only signed values are used in tables by
160
- // RabbitMQ. It *used* to (< v3.3.0) treat the byte 'b'
161
- // type as unsigned, but most clients (and the spec)
162
- // think it's signed, and now RabbitMQ does too.
163
- if (val < 128 && val >= -128) {
164
- tag('b');
165
- buffer.writeInt8(val, offset); offset++;
166
- }
167
- else if (val >= -0x8000 && val < 0x8000) { // short
168
- tag('s');
169
- buffer.writeInt16BE(val, offset); offset += 2;
170
- }
171
- else if (val >= -0x80000000 && val < 0x80000000) { // int
172
- tag('I');
173
- buffer.writeInt32BE(val, offset); offset += 4;
174
- }
175
- else { // long
176
- tag('l');
177
- ints.writeInt64BE(buffer, val, offset); offset += 8;
178
- }
179
- }
178
+ // These are the types that are either guessed above, or
179
+ // explicitly given using the {'!': type} notation.
180
+ case 'double':
181
+ case 'float64':
182
+ tag('d');
183
+ buffer.writeDoubleBE(val, offset);
184
+ offset += 8;
185
+ break;
186
+ case 'byte':
187
+ case 'int8':
188
+ tag('b');
189
+ buffer.writeInt8(val, offset); offset++;
190
+ break;
191
+ case 'short':
192
+ case 'int16':
193
+ tag('s');
194
+ buffer.writeInt16BE(val, offset); offset += 2;
180
195
  break;
181
- // Now for exotic types, those can only be denoted by using
196
+ case 'int':
197
+ case 'int32':
198
+ tag('I');
199
+ buffer.writeInt32BE(val, offset); offset += 4;
200
+ break;
201
+ case 'long':
202
+ case 'int64':
203
+ tag('l');
204
+ ints.writeInt64BE(buffer, val, offset); offset += 8;
205
+ break;
206
+
207
+ // Now for exotic types, those can _only_ be denoted by using
182
208
  // `{'!': type, value: val}
183
209
  case 'timestamp':
184
210
  tag('T');
package/lib/connect.js CHANGED
@@ -76,13 +76,22 @@ function openFrames(vhost, query, credentials, extraClientProperties) {
76
76
  };
77
77
  }
78
78
 
79
- // Decide on credentials based on what we're supplied
79
+ // Decide on credentials based on what we're supplied. Note that in a
80
+ // parsed URL, the auth part is already URL-decoded, so e.g., '%3a' in
81
+ // the URL is already decoded to ':'. This is a bit unhelpful, as it
82
+ // means we can't tell whether a colon is a separator, or part of the
83
+ // username. Assume no colons in usernames.
80
84
  function credentialsFromUrl(parts) {
81
85
  var user = 'guest', passwd = 'guest';
82
86
  if (parts.auth) {
83
- var auth = parts.auth.split(':');
84
- user = auth[0];
85
- passwd = auth[1];
87
+ var colon = parts.auth.indexOf(':')
88
+ if (colon == -1) {
89
+ user = parts.auth;
90
+ passwd = '';
91
+ } else {
92
+ user = parts.auth.substring(0, colon);
93
+ passwd = parts.auth.substring(colon+1);
94
+ }
86
95
  }
87
96
  return credentials.plain(user, passwd);
88
97
  }
@@ -110,15 +119,23 @@ function connect(url, socketOptions, openCallback) {
110
119
  sockopts.port = url.port || ((protocol === 'amqp:') ? 5672 : 5671);
111
120
 
112
121
  var user, pass;
113
- if (!url.username) {
114
- user = 'guest';
115
- pass = url.password || 'guest';
122
+ // Only default if both are missing, to have the same behaviour as
123
+ // the stringly URL.
124
+ if (url.username == undefined && url.password == undefined) {
125
+ user = 'guest'; pass = 'guest';
116
126
  } else {
117
- user = url.username;
118
- pass = url.password;
127
+ user = url.username || '';
128
+ pass = url.password || '';
119
129
  }
120
130
 
121
- fields = openFrames(url.vhost, null, sockopts.credentials || credentials.plain(user, pass), extraClientProperties);
131
+ var config = {
132
+ locale: url.locale,
133
+ channelMax: url.channelMax,
134
+ frameMax: url.frameMax,
135
+ heartbeat: url.heartbeat,
136
+ };
137
+
138
+ fields = openFrames(url.vhost, config, sockopts.credentials || credentials.plain(user, pass), extraClientProperties);
122
139
  } else {
123
140
  var parts = URL.parse(url, true); // yes, parse the query string
124
141
  protocol = parts.protocol;
@@ -159,8 +176,11 @@ function connect(url, socketOptions, openCallback) {
159
176
  }
160
177
 
161
178
  if (timeout) {
162
- sock.setTimeout(
163
- timeout, openCallback.bind(this, new Error('connect ETIMEDOUT')));
179
+ sock.setTimeout(timeout, function() {
180
+ sock.end();
181
+ sock.destroy();
182
+ openCallback(new Error('connect ETIMEDOUT'));
183
+ });
164
184
  }
165
185
 
166
186
  sock.once('error', function(err) {
@@ -170,3 +190,4 @@ function connect(url, socketOptions, openCallback) {
170
190
  }
171
191
 
172
192
  module.exports.connect = connect;
193
+ module.exports.credentialsFromUrl = credentialsFromUrl;
package/lib/connection.js CHANGED
@@ -9,6 +9,7 @@ var constants = defs.constants;
9
9
  var frame = require('./frame');
10
10
  var HEARTBEAT = frame.HEARTBEAT;
11
11
  var Mux = require('./mux').Mux;
12
+ var Buffer = require('safe-buffer').Buffer
12
13
 
13
14
  var Duplex =
14
15
  require('stream').Duplex ||
@@ -43,7 +44,7 @@ function Connection(underlying) {
43
44
  this.muxer = new Mux(stream);
44
45
 
45
46
  // frames
46
- this.rest = new Buffer(0);
47
+ this.rest = Buffer.alloc(0);
47
48
  this.frameMax = constants.FRAME_MIN_SIZE;
48
49
  this.sentSinceLastCheck = false;
49
50
  this.recvSinceLastCheck = false;
@@ -148,7 +149,7 @@ C.open = function(allFields, openCallback0) {
148
149
  // This is where we'll put our negotiated values
149
150
  var tunedOptions = Object.create(allFields);
150
151
 
151
- function await(k) {
152
+ function wait(k) {
152
153
  self.step(function(err, frame) {
153
154
  if (err !== null) bail(err);
154
155
  else if (frame.channel !== 0) {
@@ -161,7 +162,7 @@ C.open = function(allFields, openCallback0) {
161
162
  }
162
163
 
163
164
  function expect(Method, k) {
164
- await(function(frame) {
165
+ wait(function(frame) {
165
166
  if (frame.id === Method) k(frame);
166
167
  else {
167
168
  bail(new Error(
@@ -205,7 +206,7 @@ C.open = function(allFields, openCallback0) {
205
206
  return;
206
207
  }
207
208
  send(defs.ConnectionStartOk);
208
- await(afterStartOk);
209
+ wait(afterStartOk);
209
210
  }
210
211
 
211
212
  function afterStartOk(reply) {
@@ -550,7 +551,7 @@ C.sendMessage = function(channel,
550
551
  var allLen = methodHeaderLen + bodyLen;
551
552
 
552
553
  if (allLen < SINGLE_CHUNK_THRESHOLD) {
553
- var all = new Buffer(allLen);
554
+ var all = Buffer.alloc(allLen);
554
555
  var offset = mframe.copy(all, 0);
555
556
  offset += pframe.copy(all, offset);
556
557
 
@@ -560,7 +561,7 @@ C.sendMessage = function(channel,
560
561
  }
561
562
  else {
562
563
  if (methodHeaderLen < SINGLE_CHUNK_THRESHOLD) {
563
- var both = new Buffer(methodHeaderLen);
564
+ var both = Buffer.alloc(methodHeaderLen);
564
565
  var offset = mframe.copy(both, 0);
565
566
  pframe.copy(both, offset);
566
567
  buffer.write(both);
@@ -8,19 +8,22 @@
8
8
  // * PLAIN (send username and password in the plain)
9
9
  // * EXTERNAL (assume the server will figure out who you are from
10
10
  // context, i.e., your SSL certificate)
11
+ var Buffer = require('safe-buffer').Buffer
11
12
 
12
13
  module.exports.plain = function(user, passwd) {
13
14
  return {
14
15
  mechanism: 'PLAIN',
15
16
  response: function() {
16
- return new Buffer(['', user, passwd].join(String.fromCharCode(0)))
17
- }
17
+ return Buffer.from(['', user, passwd].join(String.fromCharCode(0)))
18
+ },
19
+ username: user,
20
+ password: passwd
18
21
  }
19
22
  }
20
23
 
21
24
  module.exports.external = function() {
22
25
  return {
23
26
  mechanism: 'EXTERNAL',
24
- response: function() { return new Buffer(''); }
27
+ response: function() { return Buffer.from(''); }
25
28
  }
26
29
  }