twilio_ip_messaging_rails 0.1.1 → 0.1.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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/twilio_ip_messaging_rails.js +1344 -1369
- data/lib/twilio_ip_messaging_rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 35d4c4898437cdda74651d3e1ccf2c6ff9e46850
|
|
4
|
+
data.tar.gz: af170c85fa081d0f797b8ff360c613952c6421d9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 54914261f8be78c8218556b5b54d36556357c6b63a59e2763a769ed94cfd63ece587674fd9e32b10c70a62c2d76137ffb281f538db90ba496ea23bb8228e287e
|
|
7
|
+
data.tar.gz: 9a9187d530bd3391b4d5a9cf8bd72eb1bc53efdab74c90870ff9022fbd545871fe19c4933bcc8bd83ee37a4f0739e5862083ea9ebb5b48ff5fac9b215a74a1c0
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* twilio-ip-messaging.js 0.
|
|
1
|
+
/* twilio-ip-messaging.js 0.10.0
|
|
2
2
|
The following license applies to all parts of this software except as
|
|
3
3
|
documented below.
|
|
4
4
|
|
|
@@ -145,21 +145,23 @@ This software includes platform.js under the following license.
|
|
|
145
145
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
146
146
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
147
147
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
148
|
-
*/
|
|
148
|
+
*/
|
|
149
149
|
|
|
150
150
|
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
|
151
|
+
(function (global){
|
|
152
|
+
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.Twilio || (g.Twilio = {})).IPMessaging = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
|
|
151
153
|
'use strict';
|
|
152
154
|
|
|
153
|
-
var log =
|
|
155
|
+
var log = _dereq_('loglevel');
|
|
154
156
|
|
|
155
|
-
var DataSyncConfig =
|
|
156
|
-
var Subscriptions =
|
|
157
|
-
var Router =
|
|
158
|
-
var Network =
|
|
157
|
+
var DataSyncConfig = _dereq_('./configuration.js');
|
|
158
|
+
var Subscriptions = _dereq_('./subscriptions.js');
|
|
159
|
+
var Router = _dereq_('./router.js');
|
|
160
|
+
var Network = _dereq_('./network.js');
|
|
159
161
|
|
|
160
|
-
var DataEntity =
|
|
161
|
-
var DataStream =
|
|
162
|
-
var DataMap =
|
|
162
|
+
var DataEntity = _dereq_('./dataentity.js');
|
|
163
|
+
var DataStream = _dereq_('./datastream.js');
|
|
164
|
+
var DataMap = _dereq_('./datamap.js');
|
|
163
165
|
|
|
164
166
|
var COREDATA_ENTITY_NOTIFICATION_TYPE = 'com.twilio.rtd.cds.entity';
|
|
165
167
|
var COREDATA_STREAM_NOTIFICATION_TYPE = 'com.twilio.rtd.cds.stream';
|
|
@@ -334,7 +336,7 @@ Object.freeze(DataSyncClient);
|
|
|
334
336
|
|
|
335
337
|
module.exports = DataSyncClient;
|
|
336
338
|
|
|
337
|
-
},{"./configuration.js":3,"./dataentity.js":4,"./datamap.js":5,"./datastream.js":6,"./network.js":7,"./router.js":8,"./subscriptions.js":9,"loglevel":
|
|
339
|
+
},{"./configuration.js":3,"./dataentity.js":4,"./datamap.js":5,"./datastream.js":6,"./network.js":7,"./router.js":8,"./subscriptions.js":9,"loglevel":60}],2:[function(_dereq_,module,exports){
|
|
338
340
|
'use strict';
|
|
339
341
|
|
|
340
342
|
/**
|
|
@@ -373,7 +375,7 @@ Object.freeze(CollectionEntity);
|
|
|
373
375
|
|
|
374
376
|
module.exports = CollectionEntity;
|
|
375
377
|
|
|
376
|
-
},{}],3:[function(
|
|
378
|
+
},{}],3:[function(_dereq_,module,exports){
|
|
377
379
|
'use strict';
|
|
378
380
|
|
|
379
381
|
var CDS_URI = 'https://cds.twilio.com';
|
|
@@ -428,15 +430,15 @@ DataSyncConfig.prototype.updateToken = function (token) {
|
|
|
428
430
|
|
|
429
431
|
module.exports = DataSyncConfig;
|
|
430
432
|
|
|
431
|
-
},{}],4:[function(
|
|
433
|
+
},{}],4:[function(_dereq_,module,exports){
|
|
432
434
|
'use strict';
|
|
433
435
|
|
|
434
436
|
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
|
|
435
437
|
|
|
436
|
-
var EventEmitter =
|
|
437
|
-
var inherits =
|
|
438
|
-
var JsonDiff =
|
|
439
|
-
var log =
|
|
438
|
+
var EventEmitter = _dereq_('events').EventEmitter;
|
|
439
|
+
var inherits = _dereq_('util').inherits;
|
|
440
|
+
var JsonDiff = _dereq_('../../util/jsondiff');
|
|
441
|
+
var log = _dereq_('loglevel');
|
|
440
442
|
|
|
441
443
|
/**
|
|
442
444
|
* @class DataEntity
|
|
@@ -680,7 +682,7 @@ DataEntity.prototype.addEventHandler = function (eventName, path, handler) {
|
|
|
680
682
|
* @param {string} path JSON path
|
|
681
683
|
*/
|
|
682
684
|
DataEntity.prototype.value = function (path) {
|
|
683
|
-
var result =
|
|
685
|
+
var result = void 0;
|
|
684
686
|
try {
|
|
685
687
|
var pathArr = path.replace(/^\/|\/$/gm, '').split('/');
|
|
686
688
|
var obj = this.getData();
|
|
@@ -746,16 +748,16 @@ Object.freeze(DataEntity);
|
|
|
746
748
|
|
|
747
749
|
module.exports = DataEntity;
|
|
748
750
|
|
|
749
|
-
},{"../../util/jsondiff":
|
|
751
|
+
},{"../../util/jsondiff":37,"events":54,"loglevel":60,"util":94}],5:[function(_dereq_,module,exports){
|
|
750
752
|
'use strict';
|
|
751
753
|
|
|
752
754
|
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
|
|
753
755
|
|
|
754
|
-
var EventEmitter =
|
|
755
|
-
var inherits =
|
|
756
|
-
var util =
|
|
756
|
+
var EventEmitter = _dereq_('events').EventEmitter;
|
|
757
|
+
var inherits = _dereq_('util').inherits;
|
|
758
|
+
var util = _dereq_('../../util');
|
|
757
759
|
|
|
758
|
-
var Entity =
|
|
760
|
+
var Entity = _dereq_('./collectionentity');
|
|
759
761
|
|
|
760
762
|
/**
|
|
761
763
|
* @class DataMap
|
|
@@ -811,7 +813,7 @@ DataMap.prototype._tryPostOrUpdate = function (uri, data) {
|
|
|
811
813
|
}).catch(function (err) {
|
|
812
814
|
if (err.status === 409) {
|
|
813
815
|
var _ret = function () {
|
|
814
|
-
var location =
|
|
816
|
+
var location = void 0;
|
|
815
817
|
try {
|
|
816
818
|
var body = JSON.parse(err.body);
|
|
817
819
|
location = body.links.entity;
|
|
@@ -1029,7 +1031,7 @@ DataMap.prototype.forEach = function (handler) {
|
|
|
1029
1031
|
}).catch(reject);
|
|
1030
1032
|
};
|
|
1031
1033
|
|
|
1032
|
-
var _undefined =
|
|
1034
|
+
var _undefined = void 0;
|
|
1033
1035
|
processChunk(_undefined, handler, function () {
|
|
1034
1036
|
_this10._cacheState.ensured = true;resolve();
|
|
1035
1037
|
});
|
|
@@ -1122,15 +1124,15 @@ Object.freeze(DataMap);
|
|
|
1122
1124
|
|
|
1123
1125
|
module.exports = DataMap;
|
|
1124
1126
|
|
|
1125
|
-
},{"../../util":
|
|
1127
|
+
},{"../../util":36,"./collectionentity":2,"events":54,"util":94}],6:[function(_dereq_,module,exports){
|
|
1126
1128
|
'use strict';
|
|
1127
1129
|
|
|
1128
|
-
var EventEmitter =
|
|
1129
|
-
var inherits =
|
|
1130
|
-
var util =
|
|
1131
|
-
var log =
|
|
1130
|
+
var EventEmitter = _dereq_('events').EventEmitter;
|
|
1131
|
+
var inherits = _dereq_('util').inherits;
|
|
1132
|
+
var util = _dereq_('../../util');
|
|
1133
|
+
var log = _dereq_('loglevel');
|
|
1132
1134
|
|
|
1133
|
-
var Entity =
|
|
1135
|
+
var Entity = _dereq_('./collectionentity');
|
|
1134
1136
|
|
|
1135
1137
|
/**
|
|
1136
1138
|
* @class EventStream
|
|
@@ -1431,7 +1433,7 @@ Object.freeze(EventStream);
|
|
|
1431
1433
|
|
|
1432
1434
|
module.exports = EventStream;
|
|
1433
1435
|
|
|
1434
|
-
},{"../../util":
|
|
1436
|
+
},{"../../util":36,"./collectionentity":2,"events":54,"loglevel":60,"util":94}],7:[function(_dereq_,module,exports){
|
|
1435
1437
|
'use strict';
|
|
1436
1438
|
|
|
1437
1439
|
/**
|
|
@@ -1499,11 +1501,11 @@ Object.freeze(Network);
|
|
|
1499
1501
|
|
|
1500
1502
|
module.exports = Network;
|
|
1501
1503
|
|
|
1502
|
-
},{}],8:[function(
|
|
1504
|
+
},{}],8:[function(_dereq_,module,exports){
|
|
1503
1505
|
'use strict';
|
|
1504
1506
|
|
|
1505
|
-
var util =
|
|
1506
|
-
var log =
|
|
1507
|
+
var util = _dereq_('../../util');
|
|
1508
|
+
var log = _dereq_('loglevel');
|
|
1507
1509
|
|
|
1508
1510
|
var COREDATA_ENTITY_NOTIFICATION_TYPE = 'com.twilio.rtd.cds.entity';
|
|
1509
1511
|
var COREDATA_STREAM_NOTIFICATION_TYPE = 'com.twilio.rtd.cds.stream';
|
|
@@ -1534,8 +1536,8 @@ Router.prototype.onMessage = function (type, message) {
|
|
|
1534
1536
|
entity._update(copiedMessage.event);
|
|
1535
1537
|
});
|
|
1536
1538
|
} else if (type === COREDATA_STREAM_NOTIFICATION_TYPE || type === COREDATA_MAP_NOTIFICATION_TYPE) {
|
|
1537
|
-
var
|
|
1538
|
-
this._subscriptions.getSubscribers(
|
|
1539
|
+
var _uri = message.collection.links.collection;
|
|
1540
|
+
this._subscriptions.getSubscribers(_uri).forEach(function (eventStream) {
|
|
1539
1541
|
var copiedMessage = util.deepClone(message);
|
|
1540
1542
|
eventStream._update(copiedMessage.event);
|
|
1541
1543
|
});
|
|
@@ -1588,10 +1590,10 @@ Object.freeze(Router);
|
|
|
1588
1590
|
|
|
1589
1591
|
module.exports = Router;
|
|
1590
1592
|
|
|
1591
|
-
},{"../../util":
|
|
1593
|
+
},{"../../util":36,"loglevel":60}],9:[function(_dereq_,module,exports){
|
|
1592
1594
|
'use strict';
|
|
1593
1595
|
|
|
1594
|
-
var log =
|
|
1596
|
+
var log = _dereq_('loglevel');
|
|
1595
1597
|
|
|
1596
1598
|
/**
|
|
1597
1599
|
* @class Subscriptions
|
|
@@ -1737,17 +1739,17 @@ Object.freeze(Subscriptions);
|
|
|
1737
1739
|
|
|
1738
1740
|
module.exports = Subscriptions;
|
|
1739
1741
|
|
|
1740
|
-
},{"loglevel":
|
|
1742
|
+
},{"loglevel":60}],10:[function(_dereq_,module,exports){
|
|
1741
1743
|
'use strict';
|
|
1742
1744
|
|
|
1743
|
-
var EventEmitter =
|
|
1744
|
-
var inherits =
|
|
1745
|
+
var EventEmitter = _dereq_('events').EventEmitter;
|
|
1746
|
+
var inherits = _dereq_('util').inherits;
|
|
1745
1747
|
|
|
1746
|
-
var MembersEntity =
|
|
1747
|
-
var Member =
|
|
1748
|
-
var MessagesEntity =
|
|
1749
|
-
var JsonDiff =
|
|
1750
|
-
var log =
|
|
1748
|
+
var MembersEntity = _dereq_('./data/members');
|
|
1749
|
+
var Member = _dereq_('./member');
|
|
1750
|
+
var MessagesEntity = _dereq_('./data/messages');
|
|
1751
|
+
var JsonDiff = _dereq_('../../util/jsondiff');
|
|
1752
|
+
var log = _dereq_('loglevel');
|
|
1751
1753
|
|
|
1752
1754
|
var fieldMappings = {
|
|
1753
1755
|
attributes: 'attributes',
|
|
@@ -1763,6 +1765,14 @@ var fieldMappings = {
|
|
|
1763
1765
|
uniqueName: 'uniqueName'
|
|
1764
1766
|
};
|
|
1765
1767
|
|
|
1768
|
+
function parseTime(timeString) {
|
|
1769
|
+
try {
|
|
1770
|
+
return new Date(timeString);
|
|
1771
|
+
} catch (e) {
|
|
1772
|
+
return null;
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1766
1776
|
/**
|
|
1767
1777
|
* @class
|
|
1768
1778
|
* @classdesc A Channel represents a remote channel of communication between
|
|
@@ -1784,6 +1794,7 @@ var fieldMappings = {
|
|
|
1784
1794
|
* @fires Channel#memberJoined
|
|
1785
1795
|
* @fires Channel#memberLeft
|
|
1786
1796
|
* @fires Channel#memberUpdated
|
|
1797
|
+
* @fires Channel#memberInfoUpdated
|
|
1787
1798
|
* @fires Channel#messageAdded
|
|
1788
1799
|
* @fires Channel#messageRemoved
|
|
1789
1800
|
* @fires Channel#messageUpdated
|
|
@@ -1792,18 +1803,18 @@ var fieldMappings = {
|
|
|
1792
1803
|
* @fires Channel#updated
|
|
1793
1804
|
*/
|
|
1794
1805
|
|
|
1795
|
-
function Channel(
|
|
1806
|
+
function Channel(services, data, sid) {
|
|
1796
1807
|
var _this = this;
|
|
1797
1808
|
|
|
1798
1809
|
if (!(this instanceof Channel)) {
|
|
1799
|
-
return new Channel(
|
|
1810
|
+
return new Channel(services, data, sid);
|
|
1800
1811
|
}
|
|
1801
1812
|
|
|
1802
1813
|
var attributes = data.attributes || {};
|
|
1803
1814
|
var createdBy = data.createdBy;
|
|
1804
|
-
var dateCreated = data.dateCreated;
|
|
1805
|
-
var dateUpdated = data.dateUpdated;
|
|
1806
|
-
var friendlyName = data.name || data.friendlyName;
|
|
1815
|
+
var dateCreated = parseTime(data.dateCreated);
|
|
1816
|
+
var dateUpdated = parseTime(data.dateUpdated);
|
|
1817
|
+
var friendlyName = data.name || data.friendlyName || null;
|
|
1807
1818
|
var lastConsumedMessageIndex = data.lastConsumedMessageIndex || null;
|
|
1808
1819
|
var status = 'known';
|
|
1809
1820
|
var type = data.type || Channel.type.PUBLIC;
|
|
@@ -1821,13 +1832,14 @@ function Channel(session, data, sid) {
|
|
|
1821
1832
|
}
|
|
1822
1833
|
|
|
1823
1834
|
var members = new Map();
|
|
1824
|
-
var membersEntity = new MembersEntity(this, session, members);
|
|
1835
|
+
var membersEntity = new MembersEntity(this, services.session, services.userInfos, members);
|
|
1825
1836
|
membersEntity.on('memberJoined', this.emit.bind(this, 'memberJoined'));
|
|
1826
1837
|
membersEntity.on('memberLeft', this.emit.bind(this, 'memberLeft'));
|
|
1827
1838
|
membersEntity.on('memberUpdated', this.emit.bind(this, 'memberUpdated'));
|
|
1839
|
+
membersEntity.on('memberInfoUpdated', this.emit.bind(this, 'memberInfoUpdated'));
|
|
1828
1840
|
|
|
1829
1841
|
var messages = [];
|
|
1830
|
-
var messagesEntity = new MessagesEntity(this, session, messages);
|
|
1842
|
+
var messagesEntity = new MessagesEntity(this, services.session, messages);
|
|
1831
1843
|
messagesEntity.on('messageAdded', this.emit.bind(this, 'messageAdded'));
|
|
1832
1844
|
messagesEntity.on('messageUpdated', this.emit.bind(this, 'messageUpdated'));
|
|
1833
1845
|
messagesEntity.on('messageRemoved', this.emit.bind(this, 'messageRemoved'));
|
|
@@ -1915,10 +1927,11 @@ function Channel(session, data, sid) {
|
|
|
1915
1927
|
},
|
|
1916
1928
|
_entityPromise: { value: null, writable: true },
|
|
1917
1929
|
_subscribePromise: { value: null, writable: true },
|
|
1918
|
-
_lastTypingUpdate: { value: 0, writable: true },
|
|
1919
1930
|
_membersEntity: { value: membersEntity },
|
|
1920
1931
|
_messagesEntity: { value: messagesEntity },
|
|
1921
|
-
_session: { value: session },
|
|
1932
|
+
_session: { value: services.session },
|
|
1933
|
+
_typingIndicator: { value: services.typingIndicator },
|
|
1934
|
+
_consumptionHorizon: { value: services.consumptionHorizon },
|
|
1922
1935
|
_uri: { value: uri, writable: true },
|
|
1923
1936
|
attributes: {
|
|
1924
1937
|
enumerable: true,
|
|
@@ -2119,20 +2132,16 @@ Channel.prototype._setStatus = function (status) {
|
|
|
2119
2132
|
|
|
2120
2133
|
this._status = status;
|
|
2121
2134
|
|
|
2122
|
-
if (status ===
|
|
2135
|
+
if (status === Channel.status.JOINED) {
|
|
2123
2136
|
this._subscribeStreams();
|
|
2124
|
-
} else if (status ===
|
|
2137
|
+
} else if (status === Channel.status.INVITED) {
|
|
2125
2138
|
this._subscribe();
|
|
2126
2139
|
} else if (this._entityPromise) {
|
|
2127
2140
|
this._unsubscribe();
|
|
2128
2141
|
}
|
|
2129
2142
|
};
|
|
2130
2143
|
|
|
2131
|
-
|
|
2132
|
-
* Updates local channel object with new values
|
|
2133
|
-
* @private
|
|
2134
|
-
*/
|
|
2135
|
-
Channel.prototype._update = function (update) {
|
|
2144
|
+
function preprocessUpdate(update, channelSid) {
|
|
2136
2145
|
try {
|
|
2137
2146
|
if (typeof update.attributes === 'string') {
|
|
2138
2147
|
update.attributes = JSON.parse(update.attributes);
|
|
@@ -2140,24 +2149,60 @@ Channel.prototype._update = function (update) {
|
|
|
2140
2149
|
JSON.stringify(update.attributes);
|
|
2141
2150
|
}
|
|
2142
2151
|
} catch (e) {
|
|
2143
|
-
log.warn('Retrieved malformed attributes from the server for channel: ' +
|
|
2152
|
+
log.warn('Retrieved malformed attributes from the server for channel: ' + channelSid);
|
|
2144
2153
|
update.attributes = {};
|
|
2145
2154
|
}
|
|
2146
2155
|
|
|
2156
|
+
try {
|
|
2157
|
+
if (update.dateCreated) {
|
|
2158
|
+
update.dateCreated = new Date(update.dateCreated);
|
|
2159
|
+
}
|
|
2160
|
+
} catch (e) {
|
|
2161
|
+
log.warn('Retrieved malformed attributes from the server for channel: ' + channelSid);
|
|
2162
|
+
delete update.dateCreated;
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
try {
|
|
2166
|
+
if (update.dateUpdated) {
|
|
2167
|
+
update.dateUpdated = new Date(update.dateUpdated);
|
|
2168
|
+
}
|
|
2169
|
+
} catch (e) {
|
|
2170
|
+
log.warn('Retrieved malformed attributes from the server for channel: ' + channelSid);
|
|
2171
|
+
delete update.dateUpdated;
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
|
|
2175
|
+
/**
|
|
2176
|
+
* Updates local channel object with new values
|
|
2177
|
+
* @private
|
|
2178
|
+
*/
|
|
2179
|
+
Channel.prototype._update = function (update) {
|
|
2180
|
+
preprocessUpdate(update, this._sid);
|
|
2181
|
+
|
|
2147
2182
|
var updated = false;
|
|
2148
2183
|
for (var key in update) {
|
|
2149
2184
|
var localKey = fieldMappings[key];
|
|
2150
|
-
if (localKey
|
|
2185
|
+
if (!localKey) {
|
|
2186
|
+
continue;
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
if (localKey === fieldMappings.attributes) {
|
|
2151
2190
|
if (!JsonDiff.isDeepEqual(this._attributes, update.attributes)) {
|
|
2152
2191
|
this._attributes = update.attributes;
|
|
2153
2192
|
updated = true;
|
|
2154
2193
|
}
|
|
2155
|
-
} else if (
|
|
2194
|
+
} else if (update[key] instanceof Date) {
|
|
2195
|
+
if (!this[localKey] || this[localKey].getTime() !== update[key].getTime()) {
|
|
2196
|
+
this['_' + localKey] = update[key];
|
|
2197
|
+
updated = true;
|
|
2198
|
+
}
|
|
2199
|
+
} else if (this[localKey] !== update[key]) {
|
|
2156
2200
|
this['_' + localKey] = update[key];
|
|
2157
2201
|
updated = true;
|
|
2158
2202
|
}
|
|
2159
2203
|
}
|
|
2160
|
-
|
|
2204
|
+
|
|
2205
|
+
// if uniqueName is not present in the update - then we should set it to null on the client object
|
|
2161
2206
|
if (!update.status && !update.uniqueName) {
|
|
2162
2207
|
if (this._uniqueName) {
|
|
2163
2208
|
this._uniqueName = null;
|
|
@@ -2165,14 +2210,6 @@ Channel.prototype._update = function (update) {
|
|
|
2165
2210
|
}
|
|
2166
2211
|
}
|
|
2167
2212
|
|
|
2168
|
-
if (this._dateCreated && !(this._dateCreated instanceof Date)) {
|
|
2169
|
-
this._dateCreated = new Date(this._dateCreated);
|
|
2170
|
-
}
|
|
2171
|
-
|
|
2172
|
-
if (this._dateUpdated && !(this._dateUpdated instanceof Date)) {
|
|
2173
|
-
this._dateUpdated = new Date(this._dateUpdated);
|
|
2174
|
-
}
|
|
2175
|
-
|
|
2176
2213
|
if (updated) {
|
|
2177
2214
|
this.emit('updated', this);
|
|
2178
2215
|
}
|
|
@@ -2201,14 +2238,15 @@ Channel.prototype.advanceLastConsumedMessageIndex = function advanceLastConsumed
|
|
|
2201
2238
|
var _this4 = this;
|
|
2202
2239
|
|
|
2203
2240
|
if (parseInt(index) !== index) {
|
|
2204
|
-
|
|
2205
|
-
|
|
2241
|
+
throw new Error('Channel.advanceLastConsumedMessageIndex requires an integral <Number>index parameter');
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2244
|
+
if (this.lastConsumedMessageIndex !== null && index <= this.lastConsumedMessageIndex || 0) {
|
|
2245
|
+
return Promise.resolve();
|
|
2206
2246
|
}
|
|
2207
2247
|
|
|
2208
2248
|
return this._subscribeStreams().then(function () {
|
|
2209
|
-
|
|
2210
|
-
_this4._session.advanceLastConsumedMessageIndexForChannel(_this4, index);
|
|
2211
|
-
}
|
|
2249
|
+
_this4._consumptionHorizon.advanceLastConsumedMessageIndexForChannel(_this4.sid, index);
|
|
2212
2250
|
}).then(function () {
|
|
2213
2251
|
return _this4;
|
|
2214
2252
|
});
|
|
@@ -2216,7 +2254,7 @@ Channel.prototype.advanceLastConsumedMessageIndex = function advanceLastConsumed
|
|
|
2216
2254
|
|
|
2217
2255
|
/**
|
|
2218
2256
|
* Decline an invitation to the Channel.
|
|
2219
|
-
* @returns {Promise<Channel>}
|
|
2257
|
+
* @returns {Promise<Channel|SessionError>}
|
|
2220
2258
|
*/
|
|
2221
2259
|
Channel.prototype.decline = function declineChannel() {
|
|
2222
2260
|
var _this5 = this;
|
|
@@ -2230,7 +2268,7 @@ Channel.prototype.decline = function declineChannel() {
|
|
|
2230
2268
|
|
|
2231
2269
|
/**
|
|
2232
2270
|
* Delete the Channel.
|
|
2233
|
-
* @returns {Promise<Channel>}
|
|
2271
|
+
* @returns {Promise<Channel|SessionError>}
|
|
2234
2272
|
*/
|
|
2235
2273
|
Channel.prototype.delete = function deleteChannel() {
|
|
2236
2274
|
var _this6 = this;
|
|
@@ -2304,7 +2342,7 @@ Channel.prototype.invite = function inviteByIdentity(identity) {
|
|
|
2304
2342
|
|
|
2305
2343
|
/**
|
|
2306
2344
|
* Join the Channel.
|
|
2307
|
-
* @returns {Promise<Channel>}
|
|
2345
|
+
* @returns {Promise<Channel|SessionError>}
|
|
2308
2346
|
*/
|
|
2309
2347
|
Channel.prototype.join = function joinChannel() {
|
|
2310
2348
|
var _this10 = this;
|
|
@@ -2318,7 +2356,7 @@ Channel.prototype.join = function joinChannel() {
|
|
|
2318
2356
|
|
|
2319
2357
|
/**
|
|
2320
2358
|
* Leave the Channel.
|
|
2321
|
-
* @returns {Promise<Channel>}
|
|
2359
|
+
* @returns {Promise<Channel|SessionError>}
|
|
2322
2360
|
*/
|
|
2323
2361
|
Channel.prototype.leave = function leaveChannel() {
|
|
2324
2362
|
var _this11 = this;
|
|
@@ -2364,7 +2402,7 @@ Channel.prototype.setAllMessagesConsumed = function setAllChannelMessagesConsume
|
|
|
2364
2402
|
var _this12 = this;
|
|
2365
2403
|
|
|
2366
2404
|
return this._subscribeStreams().then(function () {
|
|
2367
|
-
if (_this12.messages
|
|
2405
|
+
if (_this12.messages && _this12.messages.length > 0) {
|
|
2368
2406
|
return _this12.advanceLastConsumedMessageIndex(_this12.messages[_this12.messages.length - 1].index);
|
|
2369
2407
|
}
|
|
2370
2408
|
}).then(function () {
|
|
@@ -2377,18 +2415,13 @@ Channel.prototype.setAllMessagesConsumed = function setAllChannelMessagesConsume
|
|
|
2377
2415
|
* @returns {Promise}
|
|
2378
2416
|
*/
|
|
2379
2417
|
Channel.prototype.typing = function typing() {
|
|
2380
|
-
|
|
2381
|
-
return Promise.resolve();
|
|
2382
|
-
}
|
|
2383
|
-
|
|
2384
|
-
this._lastTypingUpdate = Date.now();
|
|
2385
|
-
return this._session.sendTypingIndicator(this._sid);
|
|
2418
|
+
return this._typingIndicator.send(this._sid);
|
|
2386
2419
|
};
|
|
2387
2420
|
|
|
2388
2421
|
/**
|
|
2389
2422
|
* Update the Channel's attributes.
|
|
2390
2423
|
* @param {Object} attributes - The new attributes object.
|
|
2391
|
-
* @returns {Promise<Channel>} A Promise for the Channel
|
|
2424
|
+
* @returns {Promise<Channel|SessionError>} A Promise for the Channel
|
|
2392
2425
|
*/
|
|
2393
2426
|
Channel.prototype.updateAttributes = function updateAttributes(attributes) {
|
|
2394
2427
|
var _this13 = this;
|
|
@@ -2410,7 +2443,7 @@ Channel.prototype.updateAttributes = function updateAttributes(attributes) {
|
|
|
2410
2443
|
/**
|
|
2411
2444
|
* Update the Channel's friendlyName.
|
|
2412
2445
|
* @param {String} name - The new Channel friendlyName.
|
|
2413
|
-
* @returns {Promise<Channel>} A Promise for the Channel
|
|
2446
|
+
* @returns {Promise<Channel|SessionError>} A Promise for the Channel
|
|
2414
2447
|
*/
|
|
2415
2448
|
Channel.prototype.updateFriendlyName = function updateFriendlyName(name) {
|
|
2416
2449
|
var _this14 = this;
|
|
@@ -2441,7 +2474,7 @@ Channel.prototype.updateLastConsumedMessageIndex = function updateLastConsumedMe
|
|
|
2441
2474
|
}
|
|
2442
2475
|
|
|
2443
2476
|
return this._subscribeStreams().then(function () {
|
|
2444
|
-
_this15.
|
|
2477
|
+
_this15._consumptionHorizon.updateLastConsumedMessageIndexForChannel(_this15.sid, index);
|
|
2445
2478
|
}).then(function () {
|
|
2446
2479
|
return _this15;
|
|
2447
2480
|
});
|
|
@@ -2468,7 +2501,7 @@ Channel.prototype.updateType = function (type) {
|
|
|
2468
2501
|
/**
|
|
2469
2502
|
* Update the Channel's unique name (tag).
|
|
2470
2503
|
* @param {String} uniqueName - The new Channel uniqueName.
|
|
2471
|
-
* @returns {Promise<Channel>} A Promise for the Channel
|
|
2504
|
+
* @returns {Promise<Channel|SessionError>} A Promise for the Channel
|
|
2472
2505
|
*/
|
|
2473
2506
|
Channel.prototype.updateUniqueName = function updateUniqueName(uniqueName) {
|
|
2474
2507
|
var _this16 = this;
|
|
@@ -2502,6 +2535,11 @@ Object.freeze(Channel);
|
|
|
2502
2535
|
* @param {Member} member
|
|
2503
2536
|
* @event Channel#memberUpdated
|
|
2504
2537
|
*/
|
|
2538
|
+
/**
|
|
2539
|
+
* Fired when a Member's UserInfo fields has been updated.
|
|
2540
|
+
* @param {Member} member
|
|
2541
|
+
* @event Channel#memberInfoUpdated
|
|
2542
|
+
*/
|
|
2505
2543
|
/**
|
|
2506
2544
|
* Fired when a new Message has been added to the Channel on the server.
|
|
2507
2545
|
* @param {Message} message
|
|
@@ -2535,26 +2573,27 @@ Object.freeze(Channel);
|
|
|
2535
2573
|
|
|
2536
2574
|
module.exports = Channel;
|
|
2537
2575
|
|
|
2538
|
-
},{"../../util/jsondiff":
|
|
2576
|
+
},{"../../util/jsondiff":37,"./data/members":14,"./data/messages":15,"./member":17,"events":54,"loglevel":60,"util":94}],11:[function(_dereq_,module,exports){
|
|
2539
2577
|
'use strict';
|
|
2540
2578
|
|
|
2541
|
-
var EventEmitter =
|
|
2542
|
-
var inherits =
|
|
2543
|
-
var log =
|
|
2579
|
+
var EventEmitter = _dereq_('events').EventEmitter;
|
|
2580
|
+
var inherits = _dereq_('util').inherits;
|
|
2581
|
+
var log = _dereq_('loglevel');
|
|
2544
2582
|
|
|
2545
|
-
var Configuration =
|
|
2546
|
-
var Session =
|
|
2547
|
-
var
|
|
2548
|
-
var ChannelsEntity = require('./data/channels.js');
|
|
2583
|
+
var Configuration = _dereq_('./configuration');
|
|
2584
|
+
var Session = _dereq_('./session.js');
|
|
2585
|
+
var ChannelsEntity = _dereq_('./data/channels.js');
|
|
2549
2586
|
|
|
2550
|
-
var
|
|
2551
|
-
var
|
|
2552
|
-
var
|
|
2553
|
-
var Transport = require('../transport');
|
|
2587
|
+
var UserInfos = _dereq_('./data/userinfos.js');
|
|
2588
|
+
var TypingIndicator = _dereq_('./services/typingindicator');
|
|
2589
|
+
var ConsumptionHorizon = _dereq_('./services/consumptionhorizon');
|
|
2554
2590
|
|
|
2555
|
-
var
|
|
2591
|
+
var DataSyncClient = _dereq_('../datasync/client');
|
|
2592
|
+
var NotificationClient = _dereq_('../notification/client');
|
|
2593
|
+
var TwilsockClient = _dereq_('../twilsock/client');
|
|
2594
|
+
var Transport = _dereq_('../transport');
|
|
2556
2595
|
|
|
2557
|
-
var SDK_VERSION =
|
|
2596
|
+
var SDK_VERSION = _dereq_('../../../package.json').version;
|
|
2558
2597
|
|
|
2559
2598
|
/**
|
|
2560
2599
|
* @class
|
|
@@ -2563,14 +2602,14 @@ var SDK_VERSION = require('../../../package.json').version;
|
|
|
2563
2602
|
* synchronously return an instance of Client, and will hold
|
|
2564
2603
|
* any outgoing methods until it has asynchronously finished
|
|
2565
2604
|
* syncing with the server.
|
|
2566
|
-
* @param {AccessManager
|
|
2567
|
-
* token JWT string.
|
|
2605
|
+
* @param {AccessManager} accessManager - The Client's AccessManager
|
|
2568
2606
|
* @param {Client#ClientOptions} options - Options to customize the Client
|
|
2569
2607
|
* @property {AccessManager} accessManager - The Client's AccessManager
|
|
2570
2608
|
* @property {Map<sid, Channel>} channels - A Map containing all Channels known locally on
|
|
2571
2609
|
* the Client. To ensure the Channels have loaded before getting a response, use
|
|
2572
2610
|
* {@link Client#getChannels}.
|
|
2573
|
-
* @property {
|
|
2611
|
+
* @property {UserInfo} userInfo - User information for logged in user
|
|
2612
|
+
* @property {String} identity - Deprecated: User identity for logged in user
|
|
2574
2613
|
* @fires Client#channelAdded
|
|
2575
2614
|
* @fires Client#channelInvited
|
|
2576
2615
|
* @fires Client#channelJoined
|
|
@@ -2586,6 +2625,7 @@ var SDK_VERSION = require('../../../package.json').version;
|
|
|
2586
2625
|
* @fires Client#tokenExpired
|
|
2587
2626
|
* @fires Client#typingEnded
|
|
2588
2627
|
* @fires Client#typingStarted
|
|
2628
|
+
* @fires Client#userInfoUpdated
|
|
2589
2629
|
*/
|
|
2590
2630
|
function Client(accessManager, options) {
|
|
2591
2631
|
var _this = this;
|
|
@@ -2597,12 +2637,8 @@ function Client(accessManager, options) {
|
|
|
2597
2637
|
log.setLevel(options.logLevel);
|
|
2598
2638
|
var config = new Configuration(options);
|
|
2599
2639
|
|
|
2600
|
-
if (typeof accessManager === 'string') {
|
|
2601
|
-
accessManager = new AccessManager(accessManager);
|
|
2602
|
-
}
|
|
2603
|
-
|
|
2604
2640
|
if (!accessManager || !accessManager.token) {
|
|
2605
|
-
throw new Error('A valid Twilio AccessManager
|
|
2641
|
+
throw new Error('A valid Twilio AccessManager must be passed to IPMessaging Client');
|
|
2606
2642
|
}
|
|
2607
2643
|
|
|
2608
2644
|
var token = accessManager.token;
|
|
@@ -2611,11 +2647,17 @@ function Client(accessManager, options) {
|
|
|
2611
2647
|
var transport = options.transportClient || new Transport(twilsock, options);
|
|
2612
2648
|
var notification = options.notificationClient || new NotificationClient('ip_messaging', token, transport, twilsock, options);
|
|
2613
2649
|
var datasync = options.dataSyncClient || new DataSyncClient(token, notification, transport, options);
|
|
2614
|
-
var session = new Session(datasync, transport,
|
|
2615
|
-
var sessionPromise = session.initialize();
|
|
2650
|
+
var session = new Session(datasync, transport, config);
|
|
2651
|
+
var sessionPromise = session.initialize(token);
|
|
2652
|
+
|
|
2653
|
+
var userInfos = new UserInfos(session, datasync, accessManager.identity);
|
|
2654
|
+
userInfos.on('userInfoUpdated', this.emit.bind(this, 'userInfoUpdated'));
|
|
2655
|
+
|
|
2656
|
+
var consumptionHorizon = new ConsumptionHorizon(config, session);
|
|
2657
|
+
var typingIndicator = new TypingIndicator(config, accessManager, transport, notification, this.getChannelBySid.bind(this));
|
|
2616
2658
|
|
|
2617
2659
|
var channels = new Map();
|
|
2618
|
-
var channelsEntity = new ChannelsEntity(session, channels);
|
|
2660
|
+
var channelsEntity = new ChannelsEntity({ session: session, userInfos: userInfos, typingIndicator: typingIndicator, consumptionHorizon: consumptionHorizon }, channels);
|
|
2619
2661
|
var channelsPromise = sessionPromise.then(function () {
|
|
2620
2662
|
channelsEntity.on('channelAdded', _this.emit.bind(_this, 'channelAdded'));
|
|
2621
2663
|
channelsEntity.on('channelRemoved', _this.emit.bind(_this, 'channelRemoved'));
|
|
@@ -2651,8 +2693,12 @@ function Client(accessManager, options) {
|
|
|
2651
2693
|
_notification: { value: notification },
|
|
2652
2694
|
_session: { value: session },
|
|
2653
2695
|
_sessionPromise: { value: sessionPromise },
|
|
2696
|
+
_initializePromise: { value: null, writable: true },
|
|
2654
2697
|
_token: { value: token, writable: true },
|
|
2655
2698
|
_twilsock: { value: twilsock },
|
|
2699
|
+
_typingIndicator: { value: typingIndicator },
|
|
2700
|
+
_userInfos: { value: userInfos },
|
|
2701
|
+
_userInfo: { writable: true },
|
|
2656
2702
|
accessManager: {
|
|
2657
2703
|
enumerable: true,
|
|
2658
2704
|
value: accessManager
|
|
@@ -2666,10 +2712,16 @@ function Client(accessManager, options) {
|
|
|
2666
2712
|
get: function get() {
|
|
2667
2713
|
return accessManager.identity;
|
|
2668
2714
|
}
|
|
2715
|
+
},
|
|
2716
|
+
userInfo: {
|
|
2717
|
+
enumerable: true,
|
|
2718
|
+
get: function get() {
|
|
2719
|
+
return _this._userInfos.myUserInfo;
|
|
2720
|
+
}
|
|
2669
2721
|
}
|
|
2670
2722
|
});
|
|
2671
2723
|
|
|
2672
|
-
this._initialize(
|
|
2724
|
+
this._initializePromise = this._initialize();
|
|
2673
2725
|
EventEmitter.call(this);
|
|
2674
2726
|
}
|
|
2675
2727
|
|
|
@@ -2687,60 +2739,34 @@ Object.defineProperties(Client, {
|
|
|
2687
2739
|
});
|
|
2688
2740
|
|
|
2689
2741
|
inherits(Client, EventEmitter);
|
|
2742
|
+
|
|
2690
2743
|
/**
|
|
2691
|
-
* @
|
|
2692
|
-
* @returns {*|Promise.<T>|Request}
|
|
2744
|
+
* @returns {Promise.<T>|Request}
|
|
2693
2745
|
* @private
|
|
2694
2746
|
*/
|
|
2695
|
-
Client.prototype._initialize = function _initialize(
|
|
2747
|
+
Client.prototype._initialize = function _initialize() {
|
|
2696
2748
|
var _this2 = this;
|
|
2697
2749
|
|
|
2698
2750
|
return this._sessionPromise.then(function () {
|
|
2699
|
-
_this2._notification.subscribe('twilio.ipmsg.typing_indicator', 'twilsock');
|
|
2700
2751
|
_this2._notification.subscribe('twilio.channel.new_message', 'gcm');
|
|
2701
2752
|
_this2._notification.subscribe('twilio.channel.added_to_channel', 'gcm');
|
|
2753
|
+
}).then(this._typingIndicator.initialize());
|
|
2754
|
+
};
|
|
2702
2755
|
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
try {
|
|
2716
|
-
for (var _iterator = channel.members.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
2717
|
-
var member = _step.value;
|
|
2756
|
+
/**
|
|
2757
|
+
* Initializes library
|
|
2758
|
+
* Library will be eventually initialized even without this method called,
|
|
2759
|
+
* but client can use returned promise to track library initialization state.
|
|
2760
|
+
* It's safe to call this method multiple times. It won't reinitialize library in ready state.
|
|
2761
|
+
*
|
|
2762
|
+
* @public
|
|
2763
|
+
* @returns {Promise<Client>}
|
|
2764
|
+
*/
|
|
2765
|
+
Client.prototype.initialize = function initialize() {
|
|
2766
|
+
var _this3 = this;
|
|
2718
2767
|
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
break;
|
|
2722
|
-
}
|
|
2723
|
-
}
|
|
2724
|
-
} catch (err) {
|
|
2725
|
-
_didIteratorError = true;
|
|
2726
|
-
_iteratorError = err;
|
|
2727
|
-
} finally {
|
|
2728
|
-
try {
|
|
2729
|
-
if (!_iteratorNormalCompletion && _iterator.return) {
|
|
2730
|
-
_iterator.return();
|
|
2731
|
-
}
|
|
2732
|
-
} finally {
|
|
2733
|
-
if (_didIteratorError) {
|
|
2734
|
-
throw _iteratorError;
|
|
2735
|
-
}
|
|
2736
|
-
}
|
|
2737
|
-
}
|
|
2738
|
-
}).catch(function (err) {
|
|
2739
|
-
log.error('IMPSG E: ', err);
|
|
2740
|
-
throw err;
|
|
2741
|
-
});
|
|
2742
|
-
}
|
|
2743
|
-
});
|
|
2768
|
+
return this._initializePromise.then(function () {
|
|
2769
|
+
return _this3;
|
|
2744
2770
|
});
|
|
2745
2771
|
};
|
|
2746
2772
|
|
|
@@ -2751,7 +2777,7 @@ Client.prototype._initialize = function _initialize(typingTimeout) {
|
|
|
2751
2777
|
* @returns {Promise<Client>}
|
|
2752
2778
|
*/
|
|
2753
2779
|
Client.prototype._updateToken = function _updateToken(token) {
|
|
2754
|
-
var
|
|
2780
|
+
var _this4 = this;
|
|
2755
2781
|
|
|
2756
2782
|
if (!token || token.split('.').length !== 3) {
|
|
2757
2783
|
return log.error('Received a malformed token from AccessManager. \
|
|
@@ -2766,9 +2792,9 @@ Client.prototype._updateToken = function _updateToken(token) {
|
|
|
2766
2792
|
log.info('IPMSG I: authTokenUpdated');
|
|
2767
2793
|
|
|
2768
2794
|
return Promise.all([this._twilsock.setAuthToken(token), this._notification.setAuthToken(token), this._datasync.setAuthToken(token), this._sessionPromise.then(function () {
|
|
2769
|
-
return
|
|
2795
|
+
return _this4._session.updateToken(token);
|
|
2770
2796
|
})]).then(function () {
|
|
2771
|
-
return
|
|
2797
|
+
return _this4;
|
|
2772
2798
|
});
|
|
2773
2799
|
};
|
|
2774
2800
|
|
|
@@ -2778,14 +2804,14 @@ Client.prototype._updateToken = function _updateToken(token) {
|
|
|
2778
2804
|
* @returns {Promise<Channel>}
|
|
2779
2805
|
*/
|
|
2780
2806
|
Client.prototype.getChannelBySid = function getChannelBySid(channelSid) {
|
|
2781
|
-
var
|
|
2807
|
+
var _this5 = this;
|
|
2782
2808
|
|
|
2783
2809
|
if (!channelSid || typeof channelSid !== 'string') {
|
|
2784
2810
|
throw new Error('Client.getChannelBySid requires a <String>channelSid parameter');
|
|
2785
2811
|
}
|
|
2786
2812
|
|
|
2787
2813
|
return this._channelsPromise.then(function () {
|
|
2788
|
-
return
|
|
2814
|
+
return _this5.channels.get(channelSid) || null;
|
|
2789
2815
|
});
|
|
2790
2816
|
};
|
|
2791
2817
|
|
|
@@ -2795,39 +2821,21 @@ Client.prototype.getChannelBySid = function getChannelBySid(channelSid) {
|
|
|
2795
2821
|
* @returns {Promise<Channel>}
|
|
2796
2822
|
*/
|
|
2797
2823
|
Client.prototype.getChannelByUniqueName = function getChannelByUniqueName(uniqueName) {
|
|
2798
|
-
var
|
|
2824
|
+
var _this6 = this;
|
|
2799
2825
|
|
|
2800
2826
|
if (!uniqueName || typeof uniqueName !== 'string') {
|
|
2801
2827
|
throw new Error('Client.getChannelByUniqueName requires a <String>uniqueName parameter');
|
|
2802
2828
|
}
|
|
2803
2829
|
|
|
2804
2830
|
return this._channelsPromise.then(function () {
|
|
2805
|
-
var
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
try {
|
|
2810
|
-
for (var _iterator2 = _this5.channels.values()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
2811
|
-
var channel = _step2.value;
|
|
2812
|
-
|
|
2813
|
-
if (channel.uniqueName === uniqueName) {
|
|
2814
|
-
return channel;
|
|
2815
|
-
}
|
|
2816
|
-
}
|
|
2817
|
-
} catch (err) {
|
|
2818
|
-
_didIteratorError2 = true;
|
|
2819
|
-
_iteratorError2 = err;
|
|
2820
|
-
} finally {
|
|
2821
|
-
try {
|
|
2822
|
-
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
|
2823
|
-
_iterator2.return();
|
|
2824
|
-
}
|
|
2825
|
-
} finally {
|
|
2826
|
-
if (_didIteratorError2) {
|
|
2827
|
-
throw _iteratorError2;
|
|
2828
|
-
}
|
|
2831
|
+
var foundChannel = null;
|
|
2832
|
+
_this6.channels.forEach(function (channel) {
|
|
2833
|
+
if (!foundChannel && channel.uniqueName === uniqueName) {
|
|
2834
|
+
foundChannel = channel;
|
|
2829
2835
|
}
|
|
2830
|
-
}
|
|
2836
|
+
});
|
|
2837
|
+
|
|
2838
|
+
return foundChannel;
|
|
2831
2839
|
});
|
|
2832
2840
|
};
|
|
2833
2841
|
|
|
@@ -2836,11 +2844,11 @@ Client.prototype.getChannelByUniqueName = function getChannelByUniqueName(unique
|
|
|
2836
2844
|
* @returns {Promise<Array<Channel>>}
|
|
2837
2845
|
*/
|
|
2838
2846
|
Client.prototype.getChannels = function getChannels() {
|
|
2839
|
-
var
|
|
2847
|
+
var _this7 = this;
|
|
2840
2848
|
|
|
2841
2849
|
return this._channelsPromise.then(function () {
|
|
2842
2850
|
var channels = [];
|
|
2843
|
-
|
|
2851
|
+
_this7.channels.forEach(function (channel) {
|
|
2844
2852
|
return channels.push(channel);
|
|
2845
2853
|
});
|
|
2846
2854
|
return channels;
|
|
@@ -2854,10 +2862,8 @@ Client.prototype.getChannels = function getChannels() {
|
|
|
2854
2862
|
*/
|
|
2855
2863
|
Client.prototype.createChannel = function createChannel(options) {
|
|
2856
2864
|
options = options || {};
|
|
2857
|
-
|
|
2858
|
-
var channel = new Channel(this._session, options, null);
|
|
2859
2865
|
return this._channelsPromise.then(function (channelsEntity) {
|
|
2860
|
-
return channelsEntity.addChannel(
|
|
2866
|
+
return channelsEntity.addChannel(options);
|
|
2861
2867
|
});
|
|
2862
2868
|
};
|
|
2863
2869
|
|
|
@@ -2955,10 +2961,15 @@ Object.freeze(Client);
|
|
|
2955
2961
|
* @param {Member} member
|
|
2956
2962
|
* @event Client#typingStarted
|
|
2957
2963
|
*/
|
|
2964
|
+
/**
|
|
2965
|
+
* Fired when a userInfo has been updated.
|
|
2966
|
+
* @param {UserInfo} UserInfo
|
|
2967
|
+
* @event Client#userInfoUpdated
|
|
2968
|
+
*/
|
|
2958
2969
|
|
|
2959
2970
|
module.exports = Client;
|
|
2960
2971
|
|
|
2961
|
-
},{"../../../package.json":
|
|
2972
|
+
},{"../../../package.json":98,"../datasync/client":1,"../notification/client":24,"../transport":28,"../twilsock/client":30,"./configuration":12,"./data/channels.js":13,"./data/userinfos.js":16,"./services/consumptionhorizon":19,"./services/typingindicator":20,"./session.js":21,"events":54,"loglevel":60,"util":94}],12:[function(_dereq_,module,exports){
|
|
2962
2973
|
'use strict';
|
|
2963
2974
|
|
|
2964
2975
|
var TYPING_URI = 'https://aim.twilio.com';
|
|
@@ -2983,13 +2994,13 @@ function IPMessagingConfig(options) {
|
|
|
2983
2994
|
|
|
2984
2995
|
module.exports = IPMessagingConfig;
|
|
2985
2996
|
|
|
2986
|
-
},{}],13:[function(
|
|
2997
|
+
},{}],13:[function(_dereq_,module,exports){
|
|
2987
2998
|
'use strict';
|
|
2988
2999
|
|
|
2989
|
-
var EventEmitter =
|
|
2990
|
-
var inherits =
|
|
3000
|
+
var EventEmitter = _dereq_('events').EventEmitter;
|
|
3001
|
+
var inherits = _dereq_('util').inherits;
|
|
2991
3002
|
|
|
2992
|
-
var Channel =
|
|
3003
|
+
var Channel = _dereq_('../channel');
|
|
2993
3004
|
|
|
2994
3005
|
/**
|
|
2995
3006
|
* Creates an instance of channels collection {@see Channel}
|
|
@@ -2997,9 +3008,12 @@ var Channel = require('../channel');
|
|
|
2997
3008
|
* @class ChannelsEntity
|
|
2998
3009
|
* @classdesc Provides an access to the channels collection
|
|
2999
3010
|
*/
|
|
3000
|
-
function ChannelsEntity(
|
|
3011
|
+
function ChannelsEntity(services, channels) {
|
|
3001
3012
|
Object.defineProperties(this, {
|
|
3002
|
-
|
|
3013
|
+
_services: { value: services },
|
|
3014
|
+
_userInfos: { value: services.userInfos },
|
|
3015
|
+
_typingIndicator: { value: services.typingIndicator },
|
|
3016
|
+
_session: { value: services.session },
|
|
3003
3017
|
channels: {
|
|
3004
3018
|
enumerable: true,
|
|
3005
3019
|
value: channels
|
|
@@ -3014,27 +3028,24 @@ inherits(ChannelsEntity, EventEmitter);
|
|
|
3014
3028
|
/**
|
|
3015
3029
|
* Add channel to server
|
|
3016
3030
|
* @private
|
|
3017
|
-
* @returns {Promise} Channel
|
|
3031
|
+
* @returns {Promise<Channel|SessionError>} Channel
|
|
3018
3032
|
*/
|
|
3019
|
-
ChannelsEntity.prototype.addChannel = function addChannel(
|
|
3033
|
+
ChannelsEntity.prototype.addChannel = function addChannel(options) {
|
|
3020
3034
|
var _this = this;
|
|
3021
3035
|
|
|
3022
3036
|
return this._session.addCommand('createChannel', {
|
|
3023
|
-
friendlyName:
|
|
3024
|
-
uniqueName:
|
|
3025
|
-
type:
|
|
3026
|
-
attributes: JSON.stringify(
|
|
3037
|
+
friendlyName: options.friendlyName,
|
|
3038
|
+
uniqueName: options.uniqueName,
|
|
3039
|
+
type: options.isPrivate ? 'private' : 'public',
|
|
3040
|
+
attributes: JSON.stringify(options.attributes)
|
|
3027
3041
|
}).then(function (response) {
|
|
3028
3042
|
var existingChannel = _this.channels.get(response.channelSid);
|
|
3029
|
-
|
|
3030
|
-
channel._sid = response.channelSid;
|
|
3031
|
-
channel._uri = response.channelUrl;
|
|
3032
|
-
|
|
3033
3043
|
if (existingChannel) {
|
|
3034
|
-
existingChannel._update(
|
|
3044
|
+
existingChannel._update(response);
|
|
3035
3045
|
return existingChannel;
|
|
3036
3046
|
}
|
|
3037
3047
|
|
|
3048
|
+
var channel = new Channel(_this._services, response, response.channelSid);
|
|
3038
3049
|
_this.channels.set(channel.sid, channel);
|
|
3039
3050
|
_this._registerForEvents(channel);
|
|
3040
3051
|
|
|
@@ -3143,7 +3154,7 @@ ChannelsEntity.prototype._fetchPublicChannels = function (url) {
|
|
|
3143
3154
|
var channel = _this3.channels.get(sid);
|
|
3144
3155
|
|
|
3145
3156
|
if (!channel) {
|
|
3146
|
-
channel = new Channel(_this3.
|
|
3157
|
+
channel = new Channel(_this3._services, entity.value, sid);
|
|
3147
3158
|
_this3._registerForEvents(channel);
|
|
3148
3159
|
_this3.channels.set(sid, channel);
|
|
3149
3160
|
_this3.emit('channelAdded', channel);
|
|
@@ -3173,7 +3184,7 @@ ChannelsEntity.prototype._fetchPublicChannels = function (url) {
|
|
|
3173
3184
|
var channelData = entity.value;
|
|
3174
3185
|
var sid = entity.id;
|
|
3175
3186
|
|
|
3176
|
-
var channel = new Channel(_this3.
|
|
3187
|
+
var channel = new Channel(_this3._services, channelData, sid);
|
|
3177
3188
|
_this3._registerForEvents(channel);
|
|
3178
3189
|
_this3.channels.set(sid, channel);
|
|
3179
3190
|
}).then(function () {
|
|
@@ -3215,7 +3226,7 @@ ChannelsEntity.prototype._upsertChannel = function (sid, data) {
|
|
|
3215
3226
|
}
|
|
3216
3227
|
|
|
3217
3228
|
// Fetch the Channel if we don't know about it
|
|
3218
|
-
channel = new Channel(this.
|
|
3229
|
+
channel = new Channel(this._services, data, sid);
|
|
3219
3230
|
this._registerForEvents(channel);
|
|
3220
3231
|
|
|
3221
3232
|
this.channels.set(sid, channel);
|
|
@@ -3250,24 +3261,29 @@ ChannelsEntity.prototype._registerForEvents = function (channel) {
|
|
|
3250
3261
|
|
|
3251
3262
|
module.exports = ChannelsEntity;
|
|
3252
3263
|
|
|
3253
|
-
},{"../channel":10,"events":
|
|
3264
|
+
},{"../channel":10,"events":54,"util":94}],14:[function(_dereq_,module,exports){
|
|
3254
3265
|
'use strict';
|
|
3255
3266
|
|
|
3256
|
-
var EventEmitter =
|
|
3257
|
-
var inherits =
|
|
3267
|
+
var EventEmitter = _dereq_('events').EventEmitter;
|
|
3268
|
+
var inherits = _dereq_('util').inherits;
|
|
3258
3269
|
|
|
3259
|
-
var Member =
|
|
3270
|
+
var Member = _dereq_('../member');
|
|
3260
3271
|
|
|
3261
3272
|
/**
|
|
3262
3273
|
* Creates members collection
|
|
3263
3274
|
*
|
|
3264
3275
|
* @class Members
|
|
3265
3276
|
* @classdesc Represents the collection of members for the channel
|
|
3277
|
+
* @fires Members#memberJoined
|
|
3278
|
+
* @fires Members#memberLeft
|
|
3279
|
+
* @fires Members#memberUpdated
|
|
3280
|
+
* @fires Members#memberInfoUpdated
|
|
3266
3281
|
*/
|
|
3267
|
-
function Members(channel, session, members) {
|
|
3282
|
+
function Members(channel, session, userInfos, members) {
|
|
3268
3283
|
|
|
3269
3284
|
Object.defineProperties(this, {
|
|
3270
3285
|
_datasync: { value: session.datasync },
|
|
3286
|
+
_userInfos: { value: userInfos },
|
|
3271
3287
|
_session: { value: session },
|
|
3272
3288
|
_rosterStreamPromise: {
|
|
3273
3289
|
writable: true,
|
|
@@ -3301,12 +3317,9 @@ Members.prototype.subscribe = function (rosterUri) {
|
|
|
3301
3317
|
rosterMap.subscribe();
|
|
3302
3318
|
|
|
3303
3319
|
rosterMap.on('entityAdded', function (entity) {
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
}
|
|
3308
|
-
var member = _this.upsertMember(memberSid, entity.value);
|
|
3309
|
-
_this.emit('memberJoined', member);
|
|
3320
|
+
_this.upsertMember(entity.id, entity.value).then(function (member) {
|
|
3321
|
+
_this.emit('memberJoined', member);
|
|
3322
|
+
});
|
|
3310
3323
|
});
|
|
3311
3324
|
|
|
3312
3325
|
rosterMap.on('entityRemoved', function (memberSid) {
|
|
@@ -3319,18 +3332,14 @@ Members.prototype.subscribe = function (rosterUri) {
|
|
|
3319
3332
|
});
|
|
3320
3333
|
|
|
3321
3334
|
rosterMap.on('entityUpdated', function (entity) {
|
|
3322
|
-
|
|
3323
|
-
if (!_this.members.has(memberSid)) {
|
|
3324
|
-
return;
|
|
3325
|
-
}
|
|
3326
|
-
_this.upsertMember(memberSid, entity.value);
|
|
3335
|
+
_this.upsertMember(entity.id, entity.value);
|
|
3327
3336
|
});
|
|
3328
3337
|
|
|
3338
|
+
var membersPromises = [];
|
|
3329
3339
|
return rosterMap.forEach(function (entity) {
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
}
|
|
3340
|
+
membersPromises.push(_this.upsertMember(entity.id, entity.value));
|
|
3341
|
+
}).then(function () {
|
|
3342
|
+
return Promise.all(membersPromises);
|
|
3334
3343
|
}).then(function () {
|
|
3335
3344
|
return rosterMap;
|
|
3336
3345
|
});
|
|
@@ -3342,17 +3351,22 @@ Members.prototype.upsertMember = function upsertMember(memberSid, data) {
|
|
|
3342
3351
|
var _this2 = this;
|
|
3343
3352
|
|
|
3344
3353
|
var member = this.members.get(memberSid);
|
|
3354
|
+
if (member) {
|
|
3355
|
+
member._update(data);
|
|
3356
|
+
return Promise.resolve(member);
|
|
3357
|
+
}
|
|
3345
3358
|
|
|
3346
|
-
|
|
3347
|
-
member = new Member(
|
|
3348
|
-
|
|
3359
|
+
return this._userInfos.getUserInfo(data.identity, data.userInfo).then(function (userInfo) {
|
|
3360
|
+
member = new Member(_this2.channel, data, memberSid, userInfo);
|
|
3361
|
+
_this2.members.set(memberSid, member);
|
|
3349
3362
|
member.on('updated', function () {
|
|
3350
3363
|
return _this2.emit('memberUpdated', member);
|
|
3351
3364
|
});
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3365
|
+
member.on('userInfoUpdated', function () {
|
|
3366
|
+
return _this2.emit('memberInfoUpdated', member);
|
|
3367
|
+
});
|
|
3368
|
+
return member;
|
|
3369
|
+
});
|
|
3356
3370
|
};
|
|
3357
3371
|
|
|
3358
3372
|
/**
|
|
@@ -3383,6 +3397,7 @@ Members.prototype.getMembers = function () {
|
|
|
3383
3397
|
|
|
3384
3398
|
/**
|
|
3385
3399
|
* Add user to the channel
|
|
3400
|
+
* @returns {Promise<|SessionError>}
|
|
3386
3401
|
*/
|
|
3387
3402
|
Members.prototype.add = function (username) {
|
|
3388
3403
|
return this._session.addCommand('addMember', {
|
|
@@ -3394,6 +3409,7 @@ Members.prototype.add = function (username) {
|
|
|
3394
3409
|
/**
|
|
3395
3410
|
* Invites user to the channel
|
|
3396
3411
|
* User can choose either to join or not
|
|
3412
|
+
* @returns {Promise<|SessionError>}
|
|
3397
3413
|
*/
|
|
3398
3414
|
Members.prototype.invite = function (username) {
|
|
3399
3415
|
return this._session.addCommand('inviteMember', {
|
|
@@ -3404,6 +3420,7 @@ Members.prototype.invite = function (username) {
|
|
|
3404
3420
|
|
|
3405
3421
|
/**
|
|
3406
3422
|
* Remove user from channel
|
|
3423
|
+
* @returns {Promise<|SessionError>}
|
|
3407
3424
|
*/
|
|
3408
3425
|
Members.prototype.remove = function (username) {
|
|
3409
3426
|
return this._session.addCommand('removeMember', {
|
|
@@ -3434,14 +3451,20 @@ module.exports = Members;
|
|
|
3434
3451
|
* @type {Member}
|
|
3435
3452
|
*/
|
|
3436
3453
|
|
|
3437
|
-
|
|
3454
|
+
/**
|
|
3455
|
+
* Fired when userInfo for member is updated
|
|
3456
|
+
* @event Members#memberInfoUpdated
|
|
3457
|
+
* @type {Member}
|
|
3458
|
+
*/
|
|
3459
|
+
|
|
3460
|
+
},{"../member":17,"events":54,"util":94}],15:[function(_dereq_,module,exports){
|
|
3438
3461
|
'use strict';
|
|
3439
3462
|
|
|
3440
|
-
var EventEmitter =
|
|
3441
|
-
var inherits =
|
|
3463
|
+
var EventEmitter = _dereq_('events').EventEmitter;
|
|
3464
|
+
var inherits = _dereq_('util').inherits;
|
|
3442
3465
|
|
|
3443
|
-
var Message =
|
|
3444
|
-
var Q =
|
|
3466
|
+
var Message = _dereq_('../message');
|
|
3467
|
+
var Q = _dereq_('q');
|
|
3445
3468
|
|
|
3446
3469
|
/*
|
|
3447
3470
|
* Creates an instance of messages collection
|
|
@@ -3488,33 +3511,13 @@ Messages.prototype.subscribe = function subscribe(uri) {
|
|
|
3488
3511
|
return _this.emit('messageUpdated', message);
|
|
3489
3512
|
});
|
|
3490
3513
|
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
for (var _iterator = _this.channel.members.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
3497
|
-
var member = _step.value;
|
|
3498
|
-
|
|
3499
|
-
if (member.identity === message.author) {
|
|
3500
|
-
member._endTyping();
|
|
3501
|
-
break;
|
|
3502
|
-
}
|
|
3514
|
+
// This place should be rewritten on iterators, etc.
|
|
3515
|
+
// But currently IE11 support blocks that
|
|
3516
|
+
_this.channel.members.forEach(function (member) {
|
|
3517
|
+
if (member.identity === message.author) {
|
|
3518
|
+
member._endTyping();
|
|
3503
3519
|
}
|
|
3504
|
-
}
|
|
3505
|
-
_didIteratorError = true;
|
|
3506
|
-
_iteratorError = err;
|
|
3507
|
-
} finally {
|
|
3508
|
-
try {
|
|
3509
|
-
if (!_iteratorNormalCompletion && _iterator.return) {
|
|
3510
|
-
_iterator.return();
|
|
3511
|
-
}
|
|
3512
|
-
} finally {
|
|
3513
|
-
if (_didIteratorError) {
|
|
3514
|
-
throw _iteratorError;
|
|
3515
|
-
}
|
|
3516
|
-
}
|
|
3517
|
-
}
|
|
3520
|
+
});
|
|
3518
3521
|
|
|
3519
3522
|
_this.emit('messageAdded', message);
|
|
3520
3523
|
});
|
|
@@ -3558,7 +3561,7 @@ Messages.prototype.unsubscribe = function unsubscribe() {
|
|
|
3558
3561
|
* @private
|
|
3559
3562
|
*/
|
|
3560
3563
|
Messages.prototype._removeMessageById = function (entityId) {
|
|
3561
|
-
var removedMessage =
|
|
3564
|
+
var removedMessage = void 0;
|
|
3562
3565
|
|
|
3563
3566
|
for (var i = 0; i < this._sortedMessages.length; i++) {
|
|
3564
3567
|
var message = this._sortedMessages[i];
|
|
@@ -3644,50 +3647,118 @@ Messages.prototype.getMessages = function getMessages(count, anchor) {
|
|
|
3644
3647
|
|
|
3645
3648
|
Messages.prototype._updateSortedMessages = function _updateSortedMessages() {
|
|
3646
3649
|
var uniqueValues = [];
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
try {
|
|
3652
|
-
for (var _iterator2 = this._messagesByIndex.values()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
3653
|
-
var message = _step2.value;
|
|
3654
|
-
|
|
3655
|
-
uniqueValues.push(message);
|
|
3656
|
-
}
|
|
3657
|
-
} catch (err) {
|
|
3658
|
-
_didIteratorError2 = true;
|
|
3659
|
-
_iteratorError2 = err;
|
|
3660
|
-
} finally {
|
|
3661
|
-
try {
|
|
3662
|
-
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
|
3663
|
-
_iterator2.return();
|
|
3664
|
-
}
|
|
3665
|
-
} finally {
|
|
3666
|
-
if (_didIteratorError2) {
|
|
3667
|
-
throw _iteratorError2;
|
|
3668
|
-
}
|
|
3669
|
-
}
|
|
3670
|
-
}
|
|
3671
|
-
|
|
3650
|
+
this._messagesByIndex.forEach(function (message) {
|
|
3651
|
+
uniqueValues.push(message);
|
|
3652
|
+
});
|
|
3672
3653
|
uniqueValues.sort(function (message1, message2) {
|
|
3673
3654
|
return message1.index - message2.index;
|
|
3674
3655
|
});
|
|
3656
|
+
|
|
3675
3657
|
Array.prototype.splice.apply(this._sortedMessages, [0, this._sortedMessages.length].concat(uniqueValues));
|
|
3676
3658
|
};
|
|
3677
3659
|
|
|
3678
3660
|
module.exports = Messages;
|
|
3679
3661
|
|
|
3680
|
-
},{"../message":
|
|
3662
|
+
},{"../message":18,"events":54,"q":68,"util":94}],16:[function(_dereq_,module,exports){
|
|
3663
|
+
'use strict';
|
|
3664
|
+
|
|
3665
|
+
var EventEmitter = _dereq_('events').EventEmitter;
|
|
3666
|
+
var inherits = _dereq_('util').inherits;
|
|
3667
|
+
|
|
3668
|
+
var UserInfo = _dereq_('../userinfo');
|
|
3669
|
+
|
|
3670
|
+
/**
|
|
3671
|
+
* @class
|
|
3672
|
+
* @classdesc Container for known user infos
|
|
3673
|
+
* @fires UserInfos#userInfoUpdated
|
|
3674
|
+
*
|
|
3675
|
+
* @constructor
|
|
3676
|
+
* @private
|
|
3677
|
+
*/
|
|
3678
|
+
function UserInfos(session, datasync, myIdentity) {
|
|
3679
|
+
var _this = this;
|
|
3680
|
+
|
|
3681
|
+
Object.defineProperties(this, {
|
|
3682
|
+
_session: { value: session },
|
|
3683
|
+
_datasync: { value: datasync },
|
|
3684
|
+
_mapsUrl: { value: '', writable: true },
|
|
3685
|
+
_infos: { value: new Map() },
|
|
3686
|
+
|
|
3687
|
+
myUserInfo: { enumerable: true, get: function get() {
|
|
3688
|
+
return _this._infos.get(myIdentity);
|
|
3689
|
+
} }
|
|
3690
|
+
});
|
|
3691
|
+
|
|
3692
|
+
var myUserInfo = new UserInfo(myIdentity, null, datasync, session);
|
|
3693
|
+
this._infos.set(myIdentity, myUserInfo);
|
|
3694
|
+
myUserInfo.on('updated', function () {
|
|
3695
|
+
return _this.emit('userInfoUpdated', myUserInfo);
|
|
3696
|
+
});
|
|
3697
|
+
|
|
3698
|
+
session.onKeyUpdated('/mapsUrl', function (url) {
|
|
3699
|
+
_this._mapsUrl = url;
|
|
3700
|
+
});
|
|
3701
|
+
|
|
3702
|
+
this._session.getUserInfosData().then(function (data) {
|
|
3703
|
+
_this._mapsUrl = data.mapsUrl;
|
|
3704
|
+
_this.myUserInfo._uri = data.mapsUrl + '/' + data.userInfo;
|
|
3705
|
+
return data;
|
|
3706
|
+
}).then(function () {
|
|
3707
|
+
return myUserInfo._ensureFetched();
|
|
3708
|
+
});
|
|
3709
|
+
|
|
3710
|
+
EventEmitter.call(this);
|
|
3711
|
+
}
|
|
3712
|
+
inherits(UserInfos, EventEmitter);
|
|
3713
|
+
|
|
3714
|
+
/**
|
|
3715
|
+
* @returns {Promise<UserInfo>} Fully initialized user info for logged in user
|
|
3716
|
+
*/
|
|
3717
|
+
UserInfos.prototype.getMyUserInfo = function () {
|
|
3718
|
+
var _this2 = this;
|
|
3719
|
+
|
|
3720
|
+
return this._session.getUserInfosData().then(function (data) {
|
|
3721
|
+
_this2._mapsUrl = data.mapsUrl;
|
|
3722
|
+
return data;
|
|
3723
|
+
}).then(function (data) {
|
|
3724
|
+
return _this2.getUserInfo(data.identity, data.userInfo);
|
|
3725
|
+
});
|
|
3726
|
+
};
|
|
3727
|
+
|
|
3728
|
+
/**
|
|
3729
|
+
* @returns {Promise<UserInfo>} Fully initialized user info
|
|
3730
|
+
*/
|
|
3731
|
+
UserInfos.prototype.getUserInfo = function (identity, id) {
|
|
3732
|
+
var _this3 = this;
|
|
3733
|
+
|
|
3734
|
+
var userInfo = this._infos.get(identity);
|
|
3735
|
+
if (!userInfo) {
|
|
3736
|
+
var url = id ? this._mapsUrl + '/' + id : null;
|
|
3737
|
+
userInfo = new UserInfo(identity, url, this._datasync, this._session);
|
|
3738
|
+
this._infos.set(identity, userInfo);
|
|
3739
|
+
userInfo.on('updated', function () {
|
|
3740
|
+
return _this3.emit('userInfoUpdated', userInfo);
|
|
3741
|
+
});
|
|
3742
|
+
}
|
|
3743
|
+
return userInfo._ensureFetched();
|
|
3744
|
+
};
|
|
3745
|
+
|
|
3746
|
+
Object.freeze(UserInfos);
|
|
3747
|
+
|
|
3748
|
+
module.exports = UserInfos;
|
|
3749
|
+
|
|
3750
|
+
},{"../userinfo":23,"events":54,"util":94}],17:[function(_dereq_,module,exports){
|
|
3681
3751
|
'use strict';
|
|
3682
3752
|
|
|
3683
|
-
var EventEmitter =
|
|
3684
|
-
var inherits =
|
|
3753
|
+
var EventEmitter = _dereq_('events').EventEmitter;
|
|
3754
|
+
var inherits = _dereq_('util').inherits;
|
|
3685
3755
|
|
|
3686
3756
|
/**
|
|
3687
3757
|
* @class
|
|
3688
3758
|
* @classdesc A Member represents a remote Client in a Channel.
|
|
3689
3759
|
* @property {Channel} channel - The Channel the remote Client is a Member of.
|
|
3690
|
-
* @property {String} identity - The identity of the remote Client.
|
|
3760
|
+
* @property {String} identity - Deprecated: The identity of the remote Client.
|
|
3761
|
+
* @property {UserInfo} userInfo - UserInfo structure for member.
|
|
3691
3762
|
* @property {Boolean} isTyping - Whether or not this Member is currently typing.
|
|
3692
3763
|
* @property {Number} lastConsumedMessageIndex - Latest consumed Message index by this Member.
|
|
3693
3764
|
* @property {Date} lastConsumptionTimestamp - Date when Member has updated his consumption horizon.
|
|
@@ -3695,10 +3766,13 @@ var inherits = require('util').inherits;
|
|
|
3695
3766
|
* @fires Member#typingEnded
|
|
3696
3767
|
* @fires Member#typingStarted
|
|
3697
3768
|
* @fires Member#updated
|
|
3769
|
+
* @fires Member#userInfoUpdated
|
|
3698
3770
|
*/
|
|
3699
|
-
function Member(channel, data, sid) {
|
|
3771
|
+
function Member(channel, data, sid, userInfo) {
|
|
3772
|
+
var _this = this;
|
|
3773
|
+
|
|
3700
3774
|
if (!(this instanceof Member)) {
|
|
3701
|
-
return new Member(channel, data, sid);
|
|
3775
|
+
return new Member(channel, data, sid, userInfo);
|
|
3702
3776
|
}
|
|
3703
3777
|
|
|
3704
3778
|
var isTyping = false;
|
|
@@ -3795,10 +3869,20 @@ function Member(channel, data, sid) {
|
|
|
3795
3869
|
sid: {
|
|
3796
3870
|
enumerable: true,
|
|
3797
3871
|
value: sid
|
|
3872
|
+
},
|
|
3873
|
+
userInfo: {
|
|
3874
|
+
enumerable: true,
|
|
3875
|
+
get: function get() {
|
|
3876
|
+
return userInfo;
|
|
3877
|
+
}
|
|
3798
3878
|
}
|
|
3799
3879
|
});
|
|
3800
3880
|
|
|
3801
3881
|
EventEmitter.call(this);
|
|
3882
|
+
|
|
3883
|
+
userInfo.on('updated', function () {
|
|
3884
|
+
return _this.emit('userInfoUpdated', _this);
|
|
3885
|
+
});
|
|
3802
3886
|
}
|
|
3803
3887
|
|
|
3804
3888
|
inherits(Member, EventEmitter);
|
|
@@ -3810,7 +3894,7 @@ Object.freeze(Member);
|
|
|
3810
3894
|
* @private
|
|
3811
3895
|
*/
|
|
3812
3896
|
Member.prototype._startTyping = function (timeout) {
|
|
3813
|
-
var
|
|
3897
|
+
var _this2 = this;
|
|
3814
3898
|
|
|
3815
3899
|
clearTimeout(this._typingTimeout);
|
|
3816
3900
|
|
|
@@ -3819,7 +3903,7 @@ Member.prototype._startTyping = function (timeout) {
|
|
|
3819
3903
|
this.channel.emit('typingStarted', this);
|
|
3820
3904
|
|
|
3821
3905
|
this._typingTimeout = setTimeout(function () {
|
|
3822
|
-
return
|
|
3906
|
+
return _this2._endTyping();
|
|
3823
3907
|
}, timeout);
|
|
3824
3908
|
return this;
|
|
3825
3909
|
};
|
|
@@ -3899,11 +3983,17 @@ module.exports = Member;
|
|
|
3899
3983
|
* @type {Member}
|
|
3900
3984
|
*/
|
|
3901
3985
|
|
|
3902
|
-
|
|
3986
|
+
/**
|
|
3987
|
+
* Fired when member's user info is updated
|
|
3988
|
+
* @event Member#userInfoUpdated
|
|
3989
|
+
* @type {Member}
|
|
3990
|
+
*/
|
|
3991
|
+
|
|
3992
|
+
},{"events":54,"util":94}],18:[function(_dereq_,module,exports){
|
|
3903
3993
|
'use strict';
|
|
3904
3994
|
|
|
3905
|
-
var EventEmitter =
|
|
3906
|
-
var inherits =
|
|
3995
|
+
var EventEmitter = _dereq_('events').EventEmitter;
|
|
3996
|
+
var inherits = _dereq_('util').inherits;
|
|
3907
3997
|
|
|
3908
3998
|
/**
|
|
3909
3999
|
* @class
|
|
@@ -4022,7 +4112,7 @@ Message.prototype._update = function (data) {
|
|
|
4022
4112
|
|
|
4023
4113
|
/**
|
|
4024
4114
|
* Remove the Message.
|
|
4025
|
-
* @returns {Promise<Message>}
|
|
4115
|
+
* @returns {Promise<Message|SessionError>}
|
|
4026
4116
|
*/
|
|
4027
4117
|
Message.prototype.remove = function removeMessage() {
|
|
4028
4118
|
var _this = this;
|
|
@@ -4038,7 +4128,7 @@ Message.prototype.remove = function removeMessage() {
|
|
|
4038
4128
|
/**
|
|
4039
4129
|
* Edit message body.
|
|
4040
4130
|
* @param {String} body - new body of Message.
|
|
4041
|
-
* @returns {Promise<Message>}
|
|
4131
|
+
* @returns {Promise<Message|SessionError>}
|
|
4042
4132
|
*/
|
|
4043
4133
|
Message.prototype.updateBody = function updateMessageBody(body) {
|
|
4044
4134
|
var _this2 = this;
|
|
@@ -4064,18 +4154,208 @@ Message.prototype.updateBody = function updateMessageBody(body) {
|
|
|
4064
4154
|
|
|
4065
4155
|
module.exports = Message;
|
|
4066
4156
|
|
|
4067
|
-
},{"events":
|
|
4157
|
+
},{"events":54,"util":94}],19:[function(_dereq_,module,exports){
|
|
4158
|
+
'use strict';
|
|
4159
|
+
|
|
4160
|
+
/**
|
|
4161
|
+
* @classdesc Provides consumption horizon management functionality
|
|
4162
|
+
*
|
|
4163
|
+
* @constructor
|
|
4164
|
+
* @private
|
|
4165
|
+
*/
|
|
4166
|
+
|
|
4167
|
+
function ConsumptionHorizon(config, session) {
|
|
4168
|
+
Object.defineProperties(this, {
|
|
4169
|
+
_session: { value: session },
|
|
4170
|
+
_consumptionHorizonReports: { value: new Map() },
|
|
4171
|
+
_consumptionHorizonUpdateTimer: { value: null, writable: true }
|
|
4172
|
+
});
|
|
4173
|
+
}
|
|
4174
|
+
|
|
4175
|
+
ConsumptionHorizon.prototype._getReportInterval = function () {
|
|
4176
|
+
return this._session.getConsumptionReportInterval().then(function (duration) {
|
|
4177
|
+
return duration.seconds * 1000;
|
|
4178
|
+
});
|
|
4179
|
+
};
|
|
4180
|
+
|
|
4181
|
+
/**
|
|
4182
|
+
* Updates consumption horizon value without any checks
|
|
4183
|
+
*/
|
|
4184
|
+
ConsumptionHorizon.prototype.updateLastConsumedMessageIndexForChannel = function (channelSid, index) {
|
|
4185
|
+
var _this = this;
|
|
4186
|
+
|
|
4187
|
+
this._consumptionHorizonReports.set(channelSid, {
|
|
4188
|
+
channelSid: channelSid,
|
|
4189
|
+
messageIdx: index
|
|
4190
|
+
});
|
|
4191
|
+
|
|
4192
|
+
this._getReportInterval().then(function (delay) {
|
|
4193
|
+
return _this._delayedSendConsumptionHorizon(delay);
|
|
4194
|
+
});
|
|
4195
|
+
};
|
|
4196
|
+
|
|
4197
|
+
/**
|
|
4198
|
+
* Move consumption horizon forward
|
|
4199
|
+
*/
|
|
4200
|
+
ConsumptionHorizon.prototype.advanceLastConsumedMessageIndexForChannel = function (channelSid, index) {
|
|
4201
|
+
var _this2 = this;
|
|
4202
|
+
|
|
4203
|
+
var currentHorizon = this._consumptionHorizonReports.get(channelSid);
|
|
4204
|
+
if (currentHorizon && currentHorizon.messageIdx >= index) {
|
|
4205
|
+
return;
|
|
4206
|
+
}
|
|
4207
|
+
|
|
4208
|
+
this._consumptionHorizonReports.set(channelSid, {
|
|
4209
|
+
channelSid: channelSid,
|
|
4210
|
+
messageIdx: index
|
|
4211
|
+
});
|
|
4212
|
+
|
|
4213
|
+
this._getReportInterval().then(function (delay) {
|
|
4214
|
+
return _this2._delayedSendConsumptionHorizon(delay);
|
|
4215
|
+
});
|
|
4216
|
+
};
|
|
4217
|
+
|
|
4218
|
+
ConsumptionHorizon.prototype._delayedSendConsumptionHorizon = function (delay) {
|
|
4219
|
+
var _this3 = this;
|
|
4220
|
+
|
|
4221
|
+
if (this._consumptionHorizonUpdateTimer !== null) {
|
|
4222
|
+
return;
|
|
4223
|
+
}
|
|
4224
|
+
|
|
4225
|
+
this._consumptionHorizonUpdateTimer = setTimeout(function () {
|
|
4226
|
+
var reports = [];
|
|
4227
|
+
_this3._consumptionHorizonReports.forEach(function (entry) {
|
|
4228
|
+
return reports.push(entry);
|
|
4229
|
+
});
|
|
4230
|
+
if (reports.length > 0) {
|
|
4231
|
+
_this3._session.addCommand('consumptionReport', { report: reports });
|
|
4232
|
+
}
|
|
4233
|
+
_this3._consumptionHorizonUpdateTimer = null;
|
|
4234
|
+
_this3._consumptionHorizonReports.clear();
|
|
4235
|
+
}, delay);
|
|
4236
|
+
};
|
|
4237
|
+
|
|
4238
|
+
Object.freeze(ConsumptionHorizon);
|
|
4239
|
+
|
|
4240
|
+
module.exports = ConsumptionHorizon;
|
|
4241
|
+
|
|
4242
|
+
},{}],20:[function(_dereq_,module,exports){
|
|
4243
|
+
'use strict';
|
|
4244
|
+
|
|
4245
|
+
var log = _dereq_('loglevel');
|
|
4246
|
+
|
|
4247
|
+
var TYPING_INDICATOR_MESSAGE_TYPE = 'twilio.ipmsg.typing_indicator';
|
|
4248
|
+
|
|
4249
|
+
/**
|
|
4250
|
+
* @class TypingIndicator
|
|
4251
|
+
*
|
|
4252
|
+
* @constructor
|
|
4253
|
+
* @private
|
|
4254
|
+
*/
|
|
4255
|
+
function TypingIndicator(config, accessManager, transport, notifications, getChannel) {
|
|
4256
|
+
var _this = this;
|
|
4257
|
+
|
|
4258
|
+
Object.defineProperties(this, {
|
|
4259
|
+
_transport: { value: transport },
|
|
4260
|
+
_notifications: { value: notifications },
|
|
4261
|
+
_config: { value: config },
|
|
4262
|
+
_typingTimeout: { value: null, writable: true },
|
|
4263
|
+
_sentUpdates: { value: new Map() },
|
|
4264
|
+
_getChannel: { value: getChannel },
|
|
4265
|
+
token: { get: function get() {
|
|
4266
|
+
return accessManager.token;
|
|
4267
|
+
} },
|
|
4268
|
+
typingTimeout: { get: function get() {
|
|
4269
|
+
return _this._typingTimeout || config.typingIndicatorTimeout;
|
|
4270
|
+
} }
|
|
4271
|
+
});
|
|
4272
|
+
}
|
|
4273
|
+
|
|
4274
|
+
/**
|
|
4275
|
+
* Initialize TypingIndicator controller
|
|
4276
|
+
* Registers for needed message types and sets listeners
|
|
4277
|
+
* @private
|
|
4278
|
+
*/
|
|
4279
|
+
TypingIndicator.prototype.initialize = function () {
|
|
4280
|
+
var _this2 = this;
|
|
4281
|
+
|
|
4282
|
+
this._notifications.subscribe(TYPING_INDICATOR_MESSAGE_TYPE, 'twilsock');
|
|
4283
|
+
this._notifications.on('message', function (type, message) {
|
|
4284
|
+
if (type === TYPING_INDICATOR_MESSAGE_TYPE) {
|
|
4285
|
+
_this2._handleRemoteTyping(message);
|
|
4286
|
+
}
|
|
4287
|
+
});
|
|
4288
|
+
};
|
|
4289
|
+
|
|
4290
|
+
/**
|
|
4291
|
+
* Remote members typing events handler
|
|
4292
|
+
* @private
|
|
4293
|
+
*/
|
|
4294
|
+
TypingIndicator.prototype._handleRemoteTyping = function (message) {
|
|
4295
|
+
var _this3 = this;
|
|
4296
|
+
|
|
4297
|
+
log.trace('Got new typing indicator ', message);
|
|
4298
|
+
this._getChannel(message.channel_sid).then(function (channel) {
|
|
4299
|
+
channel.members.forEach(function (member) {
|
|
4300
|
+
if (member.identity === message.identity) {
|
|
4301
|
+
member._startTyping(_this3.typingTimeout);
|
|
4302
|
+
}
|
|
4303
|
+
});
|
|
4304
|
+
}).catch(function (err) {
|
|
4305
|
+
log.error('IMPSG E: ', err);
|
|
4306
|
+
throw err;
|
|
4307
|
+
});
|
|
4308
|
+
};
|
|
4309
|
+
|
|
4310
|
+
TypingIndicator.prototype.send = function (channelSid) {
|
|
4311
|
+
var lastUpdate = this._sentUpdates.get(channelSid);
|
|
4312
|
+
if (lastUpdate && lastUpdate > Date.now() - this.typingTimeout) {
|
|
4313
|
+
return Promise.resolve();
|
|
4314
|
+
}
|
|
4315
|
+
|
|
4316
|
+
this._sentUpdates.set(channelSid, Date.now());
|
|
4317
|
+
return this._send(channelSid);
|
|
4318
|
+
};
|
|
4319
|
+
|
|
4320
|
+
TypingIndicator.prototype._send = function (channelSid) {
|
|
4321
|
+
var _this4 = this;
|
|
4322
|
+
|
|
4323
|
+
log.trace('IPMSG I: sending typing indicator');
|
|
4324
|
+
|
|
4325
|
+
var url = this._config.typingIndicatorUri;
|
|
4326
|
+
var headers = {
|
|
4327
|
+
'X-Twilio-Token': this.token,
|
|
4328
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
4329
|
+
};
|
|
4330
|
+
var body = 'ChannelSid=' + channelSid;
|
|
4331
|
+
|
|
4332
|
+
this._transport.post(url, headers, body).then(function (response) {
|
|
4333
|
+
if (response.body.hasOwnProperty('typing_timeout')) {
|
|
4334
|
+
_this4._typingTimeout = response.body.typing_timeout * 1000;
|
|
4335
|
+
}
|
|
4336
|
+
}).catch(function (err) {
|
|
4337
|
+
log.error('IPMSG E: failed to send typing indicator: ', err);
|
|
4338
|
+
throw err;
|
|
4339
|
+
});
|
|
4340
|
+
};
|
|
4341
|
+
|
|
4342
|
+
Object.freeze(TypingIndicator);
|
|
4343
|
+
|
|
4344
|
+
module.exports = TypingIndicator;
|
|
4345
|
+
|
|
4346
|
+
},{"loglevel":60}],21:[function(_dereq_,module,exports){
|
|
4068
4347
|
'use strict';
|
|
4069
4348
|
|
|
4070
|
-
var guid =
|
|
4071
|
-
var platform =
|
|
4072
|
-
var log =
|
|
4349
|
+
var guid = _dereq_('../../util/guid');
|
|
4350
|
+
var platform = _dereq_('platform');
|
|
4351
|
+
var log = _dereq_('loglevel');
|
|
4073
4352
|
|
|
4074
|
-
var ChangeTracker =
|
|
4353
|
+
var ChangeTracker = _dereq_('../../util/changetracker');
|
|
4354
|
+
var SessionError = _dereq_('./sessionerror');
|
|
4075
4355
|
|
|
4076
|
-
var Durational =
|
|
4356
|
+
var Durational = _dereq_('durational');
|
|
4077
4357
|
|
|
4078
|
-
var SDK_VERSION =
|
|
4358
|
+
var SDK_VERSION = _dereq_('../../../package.json').version;
|
|
4079
4359
|
|
|
4080
4360
|
/**
|
|
4081
4361
|
* Constructs the instance of Session
|
|
@@ -4087,12 +4367,11 @@ var SDK_VERSION = require('../../../package.json').version;
|
|
|
4087
4367
|
* and waits the answer from the server.
|
|
4088
4368
|
*/
|
|
4089
4369
|
function Session(datasync, transport, token, config) {
|
|
4370
|
+
var _this = this;
|
|
4090
4371
|
|
|
4091
4372
|
var platformInfo = typeof navigator !== 'undefined' ? platform.parse(navigator.userAgent) : platform;
|
|
4092
4373
|
|
|
4093
4374
|
Object.defineProperties(this, {
|
|
4094
|
-
_consumptionHorizonUpdateTimer: { value: null, writable: true },
|
|
4095
|
-
_consumptionHorizonReports: { value: new Map() },
|
|
4096
4375
|
_purpose: { value: 'com.twilio.rtd.ipmsg' },
|
|
4097
4376
|
_endpointPlatform: {
|
|
4098
4377
|
value: ['js', SDK_VERSION, platformInfo.os, platformInfo.name, platformInfo.version].join('|')
|
|
@@ -4101,34 +4380,38 @@ function Session(datasync, transport, token, config) {
|
|
|
4101
4380
|
_sessionContextChangeTracker: { value: new ChangeTracker() },
|
|
4102
4381
|
_sessionStreamPromise: { value: null, writable: true },
|
|
4103
4382
|
_config: { value: config },
|
|
4383
|
+
identity: { enumerable: true, get: function get() {
|
|
4384
|
+
return _this._sessionContextChangeTracker._data.identity;
|
|
4385
|
+
} },
|
|
4386
|
+
userInfo: { enumerable: true, get: function get() {
|
|
4387
|
+
return _this._sessionContextChangeTracker._data.userInfo;
|
|
4388
|
+
} },
|
|
4104
4389
|
datasync: { enumerable: true, value: datasync },
|
|
4105
|
-
transport: { value: transport }
|
|
4106
|
-
token: { enumerable: true, value: token, writable: true },
|
|
4107
|
-
typingTimeout: { value: config.typingIndicatorTimeout, writable: true }
|
|
4390
|
+
transport: { value: transport }
|
|
4108
4391
|
});
|
|
4109
4392
|
}
|
|
4110
4393
|
|
|
4111
|
-
Session.prototype.initialize = function () {
|
|
4112
|
-
var
|
|
4394
|
+
Session.prototype.initialize = function (token) {
|
|
4395
|
+
var _this2 = this;
|
|
4113
4396
|
|
|
4114
4397
|
var context = {
|
|
4115
4398
|
type: 'IpMsgSession',
|
|
4116
4399
|
version: 'v2',
|
|
4117
4400
|
endpointPlatform: this._endpointPlatform,
|
|
4118
|
-
token:
|
|
4401
|
+
token: token
|
|
4119
4402
|
};
|
|
4120
4403
|
|
|
4121
4404
|
this._sessionStreamPromise = this.datasync.createStream(this._purpose, context).then(function (stream) {
|
|
4122
4405
|
log.trace('IPMSG: session created');
|
|
4123
4406
|
|
|
4124
4407
|
stream.on('entityAdded', function (entity) {
|
|
4125
|
-
return
|
|
4408
|
+
return _this2._processCommandResponse(entity);
|
|
4126
4409
|
});
|
|
4127
4410
|
stream.on('entityUpdated', function (entity) {
|
|
4128
|
-
return
|
|
4411
|
+
return _this2._processCommandResponse(entity);
|
|
4129
4412
|
});
|
|
4130
4413
|
stream.on('contextUpdated', function (updatedContext) {
|
|
4131
|
-
return
|
|
4414
|
+
return _this2._sessionContextChangeTracker.update(updatedContext);
|
|
4132
4415
|
});
|
|
4133
4416
|
|
|
4134
4417
|
stream.subscribe();
|
|
@@ -4153,15 +4436,15 @@ Session.prototype.addCommand = function (action, params) {
|
|
|
4153
4436
|
* @private
|
|
4154
4437
|
*/
|
|
4155
4438
|
Session.prototype._processCommand = function (action, params) {
|
|
4156
|
-
var
|
|
4439
|
+
var _this3 = this;
|
|
4157
4440
|
|
|
4158
4441
|
var command = { request: params };
|
|
4159
4442
|
command.request.action = action;
|
|
4160
4443
|
command.commandId = guid();
|
|
4161
4444
|
|
|
4162
4445
|
return new Promise(function (resolve, reject) {
|
|
4163
|
-
|
|
4164
|
-
|
|
4446
|
+
_this3._sessionStreamPromise.then(function (stream) {
|
|
4447
|
+
_this3._pendingCommands.set(command.commandId, {
|
|
4165
4448
|
resolve: resolve,
|
|
4166
4449
|
reject: reject
|
|
4167
4450
|
});
|
|
@@ -4189,7 +4472,7 @@ Session.prototype._processCommandResponse = function (entity) {
|
|
|
4189
4472
|
log.error('Command failed: ', value);
|
|
4190
4473
|
var reject = this._pendingCommands.get(commandId).reject;
|
|
4191
4474
|
this._pendingCommands.delete(commandId);
|
|
4192
|
-
reject(new
|
|
4475
|
+
reject(new SessionError(value.response.statusText, value.response.status));
|
|
4193
4476
|
}
|
|
4194
4477
|
}
|
|
4195
4478
|
};
|
|
@@ -4212,129 +4495,247 @@ Session.prototype.onKeyUpdated = function (path, handler) {
|
|
|
4212
4495
|
};
|
|
4213
4496
|
|
|
4214
4497
|
Session.prototype.getChannelsUrl = function () {
|
|
4215
|
-
var
|
|
4498
|
+
var _this4 = this;
|
|
4216
4499
|
|
|
4217
4500
|
return new Promise(function (resolve) {
|
|
4218
|
-
|
|
4501
|
+
_this4._sessionStreamPromise.then(function (stream) {
|
|
4219
4502
|
return stream.getContext();
|
|
4220
4503
|
}).then(function (context) {
|
|
4221
4504
|
if (context.hasOwnProperty('channelsUrl')) {
|
|
4222
4505
|
resolve(context.channelsUrl);
|
|
4223
4506
|
} else {
|
|
4224
|
-
|
|
4507
|
+
_this4.onKeyUpdated('/channelsUrl', resolve);
|
|
4225
4508
|
}
|
|
4226
4509
|
});
|
|
4227
4510
|
});
|
|
4228
4511
|
};
|
|
4229
4512
|
|
|
4230
4513
|
Session.prototype.getMyChannelsUrl = function () {
|
|
4231
|
-
var
|
|
4514
|
+
var _this5 = this;
|
|
4232
4515
|
|
|
4233
4516
|
return new Promise(function (resolve) {
|
|
4234
|
-
|
|
4517
|
+
_this5._sessionStreamPromise.then(function (stream) {
|
|
4235
4518
|
return stream.getContext();
|
|
4236
4519
|
}).then(function (context) {
|
|
4237
4520
|
if (context.hasOwnProperty('myChannelsUrl')) {
|
|
4238
4521
|
resolve(context.myChannelsUrl);
|
|
4239
4522
|
} else {
|
|
4240
|
-
|
|
4523
|
+
_this5.onKeyUpdated('/myChannelsUrl', resolve);
|
|
4241
4524
|
}
|
|
4242
4525
|
});
|
|
4243
4526
|
});
|
|
4244
4527
|
};
|
|
4245
4528
|
|
|
4246
|
-
Session.prototype.
|
|
4247
|
-
var
|
|
4529
|
+
Session.prototype.getUserInfosData = function () {
|
|
4530
|
+
var _this6 = this;
|
|
4531
|
+
|
|
4532
|
+
return new Promise(function (resolve) {
|
|
4533
|
+
function resolveWithData(context) {
|
|
4534
|
+
resolve({
|
|
4535
|
+
mapsUrl: context.mapsUrl,
|
|
4536
|
+
userInfo: context.userInfo,
|
|
4537
|
+
identity: context.identity
|
|
4538
|
+
});
|
|
4539
|
+
}
|
|
4540
|
+
|
|
4541
|
+
_this6._sessionStreamPromise.then(function (stream) {
|
|
4542
|
+
return stream.getContext();
|
|
4543
|
+
}).then(function (context) {
|
|
4544
|
+
if (context.hasOwnProperty('mapsUrl')) {
|
|
4545
|
+
resolveWithData(context);
|
|
4546
|
+
} else {
|
|
4547
|
+
_this6.onKeyUpdated('/mapsUrl', function () {
|
|
4548
|
+
_this6._sessionStreamPromise.then(function (stream) {
|
|
4549
|
+
return stream.getContext();
|
|
4550
|
+
}).then(function (updatedContext) {
|
|
4551
|
+
return resolveWithData(updatedContext);
|
|
4552
|
+
});
|
|
4553
|
+
});
|
|
4554
|
+
}
|
|
4555
|
+
});
|
|
4556
|
+
});
|
|
4557
|
+
};
|
|
4558
|
+
|
|
4559
|
+
Session.prototype.getConsumptionReportInterval = function () {
|
|
4560
|
+
var _this7 = this;
|
|
4248
4561
|
|
|
4249
4562
|
return this._sessionStreamPromise.then(function (stream) {
|
|
4250
4563
|
return stream.getContext();
|
|
4251
4564
|
}).then(function (context) {
|
|
4252
|
-
return Durational.fromString(context.consumptionReportInterval ||
|
|
4565
|
+
return Durational.fromString(context.consumptionReportInterval || _this7._config.consumptionReportInterval);
|
|
4253
4566
|
});
|
|
4254
4567
|
};
|
|
4255
4568
|
|
|
4256
|
-
|
|
4257
|
-
var _this6 = this;
|
|
4569
|
+
module.exports = Session;
|
|
4258
4570
|
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
channelSid: channel.sid,
|
|
4262
|
-
messageIdx: index
|
|
4263
|
-
});
|
|
4264
|
-
_this6._delayedSendConsumptionHorizon(duration);
|
|
4265
|
-
});
|
|
4266
|
-
};
|
|
4571
|
+
},{"../../../package.json":98,"../../util/changetracker":34,"../../util/guid":35,"./sessionerror":22,"durational":52,"loglevel":60,"platform":61}],22:[function(_dereq_,module,exports){
|
|
4572
|
+
'use strict';
|
|
4267
4573
|
|
|
4268
|
-
|
|
4269
|
-
var _this7 = this;
|
|
4574
|
+
var inherits = _dereq_('util').inherits;
|
|
4270
4575
|
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4576
|
+
/**
|
|
4577
|
+
* @class
|
|
4578
|
+
* @classdesc Exception type for service-side issues
|
|
4579
|
+
*
|
|
4580
|
+
* @property {Number} code - Error code
|
|
4581
|
+
* @property {String} message - Error description
|
|
4582
|
+
*/
|
|
4583
|
+
function SessionError(message, code) {
|
|
4584
|
+
Error.captureStackTrace(this, this.constructor);
|
|
4585
|
+
this.name = this.constructor.name;
|
|
4586
|
+
this.message = message;
|
|
4587
|
+
this.code = code;
|
|
4588
|
+
}
|
|
4589
|
+
|
|
4590
|
+
inherits(SessionError, Error);
|
|
4591
|
+
|
|
4592
|
+
module.exports = SessionError;
|
|
4593
|
+
|
|
4594
|
+
},{"util":94}],23:[function(_dereq_,module,exports){
|
|
4595
|
+
'use strict';
|
|
4596
|
+
|
|
4597
|
+
var EventEmitter = _dereq_('events').EventEmitter;
|
|
4598
|
+
var inherits = _dereq_('util').inherits;
|
|
4599
|
+
|
|
4600
|
+
/**
|
|
4601
|
+
* @class
|
|
4602
|
+
* @classdesc Extended user information
|
|
4603
|
+
* @param {String} identity - Identity of user
|
|
4604
|
+
* @param {String} uri - uri to user's info object
|
|
4605
|
+
* @param {Object} datasync - datasync service
|
|
4606
|
+
* @param {Object} session - session service
|
|
4607
|
+
*
|
|
4608
|
+
* @property {String} identity - User identity
|
|
4609
|
+
* @property {String} friendlyName - User friendly name. Null if not set
|
|
4610
|
+
* @property {Object} attributes - Object with custom attributes for user
|
|
4611
|
+
* @fires UserInfo#updated
|
|
4612
|
+
*/
|
|
4613
|
+
function UserInfo(identity, uri, datasync, session) {
|
|
4614
|
+
var _this = this;
|
|
4615
|
+
|
|
4616
|
+
Object.defineProperties(this, {
|
|
4617
|
+
_datasync: { value: datasync },
|
|
4618
|
+
_session: { value: session },
|
|
4619
|
+
_identity: { value: identity },
|
|
4620
|
+
_uri: { value: uri, writable: true }, // writable only because of lazy loading of myUserInfo
|
|
4621
|
+
_attributes: { value: {}, writable: true },
|
|
4622
|
+
_friendlyName: { value: null, writable: true },
|
|
4623
|
+
_promiseToFetch: { writable: true },
|
|
4624
|
+
identity: { enumerable: true, get: function get() {
|
|
4625
|
+
return _this._identity;
|
|
4626
|
+
} },
|
|
4627
|
+
attributes: { enumerable: true, get: function get() {
|
|
4628
|
+
return _this._attributes;
|
|
4629
|
+
} },
|
|
4630
|
+
friendlyName: { enumerable: true, get: function get() {
|
|
4631
|
+
return _this._friendlyName;
|
|
4632
|
+
} }
|
|
4280
4633
|
});
|
|
4281
|
-
};
|
|
4282
4634
|
|
|
4283
|
-
|
|
4284
|
-
|
|
4635
|
+
EventEmitter.call(this);
|
|
4636
|
+
}
|
|
4285
4637
|
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
}
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4638
|
+
inherits(UserInfo, EventEmitter);
|
|
4639
|
+
|
|
4640
|
+
UserInfo.prototype._update = function (key, value) {
|
|
4641
|
+
switch (key) {
|
|
4642
|
+
case 'friendlyName':
|
|
4643
|
+
this._friendlyName = value;
|
|
4644
|
+
break;
|
|
4645
|
+
case 'attributes':
|
|
4646
|
+
try {
|
|
4647
|
+
this._attributes = JSON.parse(value);
|
|
4648
|
+
} catch (e) {
|
|
4649
|
+
this._attributes = {};
|
|
4650
|
+
}
|
|
4651
|
+
break;
|
|
4652
|
+
default:
|
|
4653
|
+
return;
|
|
4301
4654
|
}
|
|
4655
|
+
this.emit('updated');
|
|
4302
4656
|
};
|
|
4303
4657
|
|
|
4304
|
-
|
|
4305
|
-
var
|
|
4658
|
+
UserInfo.prototype._fetch = function () {
|
|
4659
|
+
var _this2 = this;
|
|
4306
4660
|
|
|
4307
|
-
|
|
4661
|
+
if (!this._uri) {
|
|
4662
|
+
return Promise.resolve(this);
|
|
4663
|
+
}
|
|
4308
4664
|
|
|
4309
|
-
var
|
|
4310
|
-
|
|
4311
|
-
'X-Twilio-Token': this.token,
|
|
4312
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
|
4665
|
+
var update = function update(item) {
|
|
4666
|
+
return _this2._update(item.id, item.value.value);
|
|
4313
4667
|
};
|
|
4314
|
-
|
|
4668
|
+
this._promiseToFetch = this._datasync.openMap(this._uri).then(function (map) {
|
|
4669
|
+
map.subscribe();
|
|
4670
|
+
map.on('entityUpdated', update);
|
|
4671
|
+
return Promise.all([map.get('friendlyName').then(update), map.get('attributes').then(update)]);
|
|
4672
|
+
}).then(function () {
|
|
4673
|
+
return _this2;
|
|
4674
|
+
}).catch(function (err) {
|
|
4675
|
+
_this2._promiseToFetch = null;
|
|
4676
|
+
throw err;
|
|
4677
|
+
});
|
|
4678
|
+
return this._promiseToFetch;
|
|
4679
|
+
};
|
|
4315
4680
|
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4681
|
+
UserInfo.prototype._ensureFetched = function () {
|
|
4682
|
+
return this._promiseToFetch || this._fetch();
|
|
4683
|
+
};
|
|
4684
|
+
|
|
4685
|
+
/**
|
|
4686
|
+
* Update the UserInfo's attributes.
|
|
4687
|
+
* @param {Object} attributes - The new attributes object.
|
|
4688
|
+
* @returns {Promise<UserInfo|SessionError>} A Promise for the UserInfo
|
|
4689
|
+
*/
|
|
4690
|
+
UserInfo.prototype.updateAttributes = function (attributes) {
|
|
4691
|
+
var _this3 = this;
|
|
4692
|
+
|
|
4693
|
+
if (attributes.constructor !== Object) {
|
|
4694
|
+
throw new Error('Attributes must be an object.');
|
|
4695
|
+
}
|
|
4696
|
+
|
|
4697
|
+
return this._session.addCommand('editUserAttributes', {
|
|
4698
|
+
username: this._identity,
|
|
4699
|
+
attributes: JSON.stringify(attributes)
|
|
4700
|
+
}).then(function () {
|
|
4701
|
+
return _this3;
|
|
4324
4702
|
});
|
|
4325
4703
|
};
|
|
4326
4704
|
|
|
4327
|
-
|
|
4705
|
+
/**
|
|
4706
|
+
* Update the Users's friendlyName.
|
|
4707
|
+
* @param {String} name - The new friendlyName.
|
|
4708
|
+
* @returns {Promise<UserInfo|SessionError>} A Promise for the UserInfo
|
|
4709
|
+
*/
|
|
4710
|
+
UserInfo.prototype.updateFriendlyName = function (friendlyName) {
|
|
4711
|
+
var _this4 = this;
|
|
4712
|
+
|
|
4713
|
+
return this._session.addCommand('editUserFriendlyName', {
|
|
4714
|
+
username: this._identity,
|
|
4715
|
+
friendlyName: friendlyName
|
|
4716
|
+
}).then(function () {
|
|
4717
|
+
return _this4;
|
|
4718
|
+
});
|
|
4719
|
+
};
|
|
4720
|
+
|
|
4721
|
+
Object.freeze(UserInfo);
|
|
4328
4722
|
|
|
4329
|
-
|
|
4723
|
+
/**
|
|
4724
|
+
* Fired when the UserInfo's fields have been updated.
|
|
4725
|
+
* @event UserInfo#updated
|
|
4726
|
+
*/
|
|
4727
|
+
|
|
4728
|
+
module.exports = UserInfo;
|
|
4729
|
+
|
|
4730
|
+
},{"events":54,"util":94}],24:[function(_dereq_,module,exports){
|
|
4330
4731
|
'use strict';
|
|
4331
4732
|
|
|
4332
|
-
var EventEmitter =
|
|
4333
|
-
var inherits =
|
|
4334
|
-
var log =
|
|
4733
|
+
var EventEmitter = _dereq_('events').EventEmitter;
|
|
4734
|
+
var inherits = _dereq_('util').inherits;
|
|
4735
|
+
var log = _dereq_('loglevel');
|
|
4335
4736
|
|
|
4336
|
-
var NotificationConfig =
|
|
4337
|
-
var Registrar =
|
|
4737
|
+
var NotificationConfig = _dereq_('./configuration');
|
|
4738
|
+
var Registrar = _dereq_('./registrar');
|
|
4338
4739
|
|
|
4339
4740
|
/**
|
|
4340
4741
|
* Creates the instance of Notification helper library
|
|
@@ -4492,7 +4893,7 @@ Object.freeze(NotificationClient);
|
|
|
4492
4893
|
|
|
4493
4894
|
module.exports = NotificationClient;
|
|
4494
4895
|
|
|
4495
|
-
},{"./configuration":
|
|
4896
|
+
},{"./configuration":25,"./registrar":27,"events":54,"loglevel":60,"util":94}],25:[function(_dereq_,module,exports){
|
|
4496
4897
|
'use strict';
|
|
4497
4898
|
|
|
4498
4899
|
var ERS_URI = 'https://ers.twilio.com';
|
|
@@ -4526,14 +4927,14 @@ NotificationConfig.prototype.updateToken = function (token) {
|
|
|
4526
4927
|
|
|
4527
4928
|
module.exports = NotificationConfig;
|
|
4528
4929
|
|
|
4529
|
-
},{}],
|
|
4930
|
+
},{}],26:[function(_dereq_,module,exports){
|
|
4530
4931
|
'use strict';
|
|
4531
4932
|
|
|
4532
|
-
var EventEmitter =
|
|
4533
|
-
var inherits =
|
|
4534
|
-
var StateMachine =
|
|
4535
|
-
var Backoff =
|
|
4536
|
-
var log =
|
|
4933
|
+
var EventEmitter = _dereq_('events').EventEmitter;
|
|
4934
|
+
var inherits = _dereq_('util').inherits;
|
|
4935
|
+
var StateMachine = _dereq_('javascript-state-machine');
|
|
4936
|
+
var Backoff = _dereq_('backoff');
|
|
4937
|
+
var log = _dereq_('loglevel');
|
|
4537
4938
|
|
|
4538
4939
|
/**
|
|
4539
4940
|
* Creates new instance of the ERS registrar
|
|
@@ -4723,7 +5124,7 @@ RegistrarClient.prototype._unregister = function () {
|
|
|
4723
5124
|
return Promise.resolve();
|
|
4724
5125
|
}
|
|
4725
5126
|
|
|
4726
|
-
var uri = this._url + '/' + this._registrationId;
|
|
5127
|
+
var uri = this._url + '/' + this._registrationId + '?productId=' + this._productId;
|
|
4727
5128
|
var headers = {
|
|
4728
5129
|
'Content-Type': 'application/json',
|
|
4729
5130
|
'X-Twilio-Token': this._config.token
|
|
@@ -4747,14 +5148,14 @@ Object.freeze(RegistrarClient);
|
|
|
4747
5148
|
|
|
4748
5149
|
module.exports = RegistrarClient;
|
|
4749
5150
|
|
|
4750
|
-
},{"backoff":
|
|
5151
|
+
},{"backoff":39,"events":54,"javascript-state-machine":59,"loglevel":60,"util":94}],27:[function(_dereq_,module,exports){
|
|
4751
5152
|
'use strict';
|
|
4752
5153
|
|
|
4753
|
-
var EventEmitter =
|
|
4754
|
-
var inherits =
|
|
4755
|
-
var log =
|
|
5154
|
+
var EventEmitter = _dereq_('events').EventEmitter;
|
|
5155
|
+
var inherits = _dereq_('util').inherits;
|
|
5156
|
+
var log = _dereq_('loglevel');
|
|
4756
5157
|
|
|
4757
|
-
var RegistrarClient =
|
|
5158
|
+
var RegistrarClient = _dereq_('./registrar.connector');
|
|
4758
5159
|
|
|
4759
5160
|
/**
|
|
4760
5161
|
* Creates the new instance of ERS registrar client
|
|
@@ -4934,10 +5335,10 @@ Object.freeze(Registrar);
|
|
|
4934
5335
|
|
|
4935
5336
|
module.exports = Registrar;
|
|
4936
5337
|
|
|
4937
|
-
},{"./registrar.connector":
|
|
5338
|
+
},{"./registrar.connector":26,"events":54,"loglevel":60,"util":94}],28:[function(_dereq_,module,exports){
|
|
4938
5339
|
'use strict';
|
|
4939
5340
|
|
|
4940
|
-
var request =
|
|
5341
|
+
var request = _dereq_('./request');
|
|
4941
5342
|
|
|
4942
5343
|
function parseUri(uri) {
|
|
4943
5344
|
var match = uri.match(/^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)(\/[^?#]*)(\?[^#]*|)(#.*|)$/);
|
|
@@ -5107,10 +5508,10 @@ Object.freeze(Transport);
|
|
|
5107
5508
|
|
|
5108
5509
|
module.exports = Transport;
|
|
5109
5510
|
|
|
5110
|
-
},{"./request":
|
|
5511
|
+
},{"./request":29}],29:[function(_dereq_,module,exports){
|
|
5111
5512
|
'use strict';
|
|
5112
5513
|
|
|
5113
|
-
var XHR = typeof XMLHttpRequest === 'undefined' ?
|
|
5514
|
+
var XHR = typeof XMLHttpRequest === 'undefined' ? _dereq_('xmlhttprequest').XMLHttpRequest : XMLHttpRequest;
|
|
5114
5515
|
|
|
5115
5516
|
function parseResponseHeaders(headerString) {
|
|
5116
5517
|
return headerString.split('\r\n').map(function (el) {
|
|
@@ -5203,16 +5604,16 @@ Request.delete = function (params) {
|
|
|
5203
5604
|
|
|
5204
5605
|
module.exports = Request;
|
|
5205
5606
|
|
|
5206
|
-
},{"xmlhttprequest":
|
|
5607
|
+
},{"xmlhttprequest":96}],30:[function(_dereq_,module,exports){
|
|
5207
5608
|
'use strict';
|
|
5208
5609
|
|
|
5209
|
-
var EventEmitter =
|
|
5210
|
-
var inherits =
|
|
5211
|
-
var log =
|
|
5610
|
+
var EventEmitter = _dereq_('events').EventEmitter;
|
|
5611
|
+
var inherits = _dereq_('util').inherits;
|
|
5612
|
+
var log = _dereq_('loglevel');
|
|
5212
5613
|
|
|
5213
|
-
var Configuration =
|
|
5214
|
-
var TwilsockChannel =
|
|
5215
|
-
var PacketInterface =
|
|
5614
|
+
var Configuration = _dereq_('./configuration.js');
|
|
5615
|
+
var TwilsockChannel = _dereq_('./twilsock.js');
|
|
5616
|
+
var PacketInterface = _dereq_('./packetinterface.js');
|
|
5216
5617
|
|
|
5217
5618
|
/**
|
|
5218
5619
|
* Client library for the Twilsock protocol
|
|
@@ -5313,7 +5714,7 @@ Object.freeze(TwilsockClient);
|
|
|
5313
5714
|
|
|
5314
5715
|
module.exports = TwilsockClient;
|
|
5315
5716
|
|
|
5316
|
-
},{"./configuration.js":
|
|
5717
|
+
},{"./configuration.js":31,"./packetinterface.js":32,"./twilsock.js":33,"events":54,"loglevel":60,"util":94}],31:[function(_dereq_,module,exports){
|
|
5317
5718
|
'use strict';
|
|
5318
5719
|
|
|
5319
5720
|
var TWILSOCK_URI = 'wss://tsock.twilio.com';
|
|
@@ -5352,10 +5753,10 @@ TwilsockConfig.prototype.updateToken = function (token) {
|
|
|
5352
5753
|
|
|
5353
5754
|
module.exports = TwilsockConfig;
|
|
5354
5755
|
|
|
5355
|
-
},{}],
|
|
5756
|
+
},{}],32:[function(_dereq_,module,exports){
|
|
5356
5757
|
'use strict';
|
|
5357
5758
|
|
|
5358
|
-
var log =
|
|
5759
|
+
var log = _dereq_('loglevel');
|
|
5359
5760
|
|
|
5360
5761
|
var TIMEOUT = 30000;
|
|
5361
5762
|
|
|
@@ -5416,21 +5817,21 @@ PacketInterface.prototype.shutdown = function () {
|
|
|
5416
5817
|
|
|
5417
5818
|
module.exports = PacketInterface;
|
|
5418
5819
|
|
|
5419
|
-
},{"loglevel":
|
|
5820
|
+
},{"loglevel":60}],33:[function(_dereq_,module,exports){
|
|
5420
5821
|
(function (Buffer){
|
|
5421
5822
|
'use strict';
|
|
5422
5823
|
|
|
5423
5824
|
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
|
|
5424
5825
|
|
|
5425
|
-
var EventEmitter =
|
|
5426
|
-
var util =
|
|
5427
|
-
var inherits =
|
|
5428
|
-
var log =
|
|
5826
|
+
var EventEmitter = _dereq_('events').EventEmitter;
|
|
5827
|
+
var util = _dereq_('../../util');
|
|
5828
|
+
var inherits = _dereq_('util').inherits;
|
|
5829
|
+
var log = _dereq_('loglevel');
|
|
5429
5830
|
|
|
5430
|
-
var Backoff =
|
|
5431
|
-
var WebSocket =
|
|
5831
|
+
var Backoff = _dereq_('backoff');
|
|
5832
|
+
var WebSocket = _dereq_('ws');
|
|
5432
5833
|
|
|
5433
|
-
var StateMachine =
|
|
5834
|
+
var StateMachine = _dereq_('javascript-state-machine');
|
|
5434
5835
|
|
|
5435
5836
|
var ACTIVITY_CHECK_INTERVAL = 5000;
|
|
5436
5837
|
var ACTIVITY_TIMEOUT = 43000;
|
|
@@ -5806,28 +6207,13 @@ Object.freeze(TwilsockChannel);
|
|
|
5806
6207
|
|
|
5807
6208
|
module.exports = TwilsockChannel;
|
|
5808
6209
|
|
|
5809
|
-
}).call(this,
|
|
5810
|
-
},{"../../util":
|
|
6210
|
+
}).call(this,_dereq_("buffer").Buffer)
|
|
6211
|
+
},{"../../util":36,"backoff":39,"buffer":48,"events":54,"javascript-state-machine":59,"loglevel":60,"util":94,"ws":95}],34:[function(_dereq_,module,exports){
|
|
5811
6212
|
'use strict';
|
|
5812
6213
|
|
|
5813
|
-
|
|
5814
|
-
|
|
5815
|
-
|
|
5816
|
-
|
|
5817
|
-
IPMessaging.Client = require('./clients/ipmessaging/client');
|
|
5818
|
-
IPMessaging.DataSyncClient = require('./clients/datasync/client');
|
|
5819
|
-
IPMessaging.NotificationClient = require('./clients/notification/client');
|
|
5820
|
-
IPMessaging.Transport = require('./clients/transport');
|
|
5821
|
-
IPMessaging.TwilsockClient = require('./clients/twilsock/client');
|
|
5822
|
-
|
|
5823
|
-
module.exports = IPMessaging;
|
|
5824
|
-
|
|
5825
|
-
},{"./clients/datasync/client":1,"./clients/ipmessaging/client":11,"./clients/notification/client":19,"./clients/transport":23,"./clients/twilsock/client":25}],30:[function(require,module,exports){
|
|
5826
|
-
'use strict';
|
|
5827
|
-
|
|
5828
|
-
var EventEmitter = require('events').EventEmitter;
|
|
5829
|
-
var inherits = require('util').inherits;
|
|
5830
|
-
var JsonDiff = require('./jsondiff');
|
|
6214
|
+
var EventEmitter = _dereq_('events').EventEmitter;
|
|
6215
|
+
var inherits = _dereq_('util').inherits;
|
|
6216
|
+
var JsonDiff = _dereq_('./jsondiff');
|
|
5831
6217
|
|
|
5832
6218
|
/**
|
|
5833
6219
|
* Tracks changes for JS objects and emits appropriate callbacks
|
|
@@ -5892,7 +6278,7 @@ ChangeTracker.prototype.addEventHandler = function (eventName, path, handler) {
|
|
|
5892
6278
|
|
|
5893
6279
|
module.exports = ChangeTracker;
|
|
5894
6280
|
|
|
5895
|
-
},{"./jsondiff":
|
|
6281
|
+
},{"./jsondiff":37,"events":54,"util":94}],35:[function(_dereq_,module,exports){
|
|
5896
6282
|
'use strict';
|
|
5897
6283
|
|
|
5898
6284
|
function guid() {
|
|
@@ -5904,7 +6290,7 @@ function guid() {
|
|
|
5904
6290
|
|
|
5905
6291
|
module.exports = guid;
|
|
5906
6292
|
|
|
5907
|
-
},{}],
|
|
6293
|
+
},{}],36:[function(_dereq_,module,exports){
|
|
5908
6294
|
(function (Buffer){
|
|
5909
6295
|
'use strict';
|
|
5910
6296
|
|
|
@@ -6238,8 +6624,8 @@ module.exports.overwriteArray = overwriteArray;
|
|
|
6238
6624
|
module.exports.faultTolerantWait = faultTolerantWait;
|
|
6239
6625
|
module.exports.UriBuilder = UriBuilder;
|
|
6240
6626
|
|
|
6241
|
-
}).call(this,
|
|
6242
|
-
},{"buffer":
|
|
6627
|
+
}).call(this,_dereq_("buffer").Buffer)
|
|
6628
|
+
},{"buffer":48}],37:[function(_dereq_,module,exports){
|
|
6243
6629
|
'use strict';
|
|
6244
6630
|
|
|
6245
6631
|
/**
|
|
@@ -6493,14 +6879,29 @@ JsonDiff.isDeepEqual = function (o1, o2) {
|
|
|
6493
6879
|
|
|
6494
6880
|
module.exports = JsonDiff;
|
|
6495
6881
|
|
|
6496
|
-
},{}],
|
|
6882
|
+
},{}],38:[function(_dereq_,module,exports){
|
|
6883
|
+
'use strict';
|
|
6884
|
+
|
|
6885
|
+
function IPMessaging(token, options) {
|
|
6886
|
+
return new IPMessaging.Client(token, options);
|
|
6887
|
+
}
|
|
6888
|
+
|
|
6889
|
+
IPMessaging.Client = _dereq_('./clients/ipmessaging/client');
|
|
6890
|
+
IPMessaging.DataSyncClient = _dereq_('./clients/datasync/client');
|
|
6891
|
+
IPMessaging.NotificationClient = _dereq_('./clients/notification/client');
|
|
6892
|
+
IPMessaging.Transport = _dereq_('./clients/transport');
|
|
6893
|
+
IPMessaging.TwilsockClient = _dereq_('./clients/twilsock/client');
|
|
6894
|
+
|
|
6895
|
+
module.exports = IPMessaging;
|
|
6896
|
+
|
|
6897
|
+
},{"./clients/datasync/client":1,"./clients/ipmessaging/client":11,"./clients/notification/client":24,"./clients/transport":28,"./clients/twilsock/client":30}],39:[function(_dereq_,module,exports){
|
|
6497
6898
|
// Copyright (c) 2012 Mathieu Turcotte
|
|
6498
6899
|
// Licensed under the MIT license.
|
|
6499
6900
|
|
|
6500
|
-
var Backoff =
|
|
6501
|
-
var ExponentialBackoffStrategy =
|
|
6502
|
-
var FibonacciBackoffStrategy =
|
|
6503
|
-
var FunctionCall =
|
|
6901
|
+
var Backoff = _dereq_('./lib/backoff');
|
|
6902
|
+
var ExponentialBackoffStrategy = _dereq_('./lib/strategy/exponential');
|
|
6903
|
+
var FibonacciBackoffStrategy = _dereq_('./lib/strategy/fibonacci');
|
|
6904
|
+
var FunctionCall = _dereq_('./lib/function_call.js');
|
|
6504
6905
|
|
|
6505
6906
|
module.exports.Backoff = Backoff;
|
|
6506
6907
|
module.exports.FunctionCall = FunctionCall;
|
|
@@ -6526,13 +6927,13 @@ module.exports.call = function(fn, vargs, callback) {
|
|
|
6526
6927
|
return new FunctionCall(fn, vargs, callback);
|
|
6527
6928
|
};
|
|
6528
6929
|
|
|
6529
|
-
},{"./lib/backoff":
|
|
6930
|
+
},{"./lib/backoff":40,"./lib/function_call.js":41,"./lib/strategy/exponential":42,"./lib/strategy/fibonacci":43}],40:[function(_dereq_,module,exports){
|
|
6530
6931
|
// Copyright (c) 2012 Mathieu Turcotte
|
|
6531
6932
|
// Licensed under the MIT license.
|
|
6532
6933
|
|
|
6533
|
-
var events =
|
|
6534
|
-
var precond =
|
|
6535
|
-
var util =
|
|
6934
|
+
var events = _dereq_('events');
|
|
6935
|
+
var precond = _dereq_('precond');
|
|
6936
|
+
var util = _dereq_('util');
|
|
6536
6937
|
|
|
6537
6938
|
// A class to hold the state of a backoff operation. Accepts a backoff strategy
|
|
6538
6939
|
// to generate the backoff delays.
|
|
@@ -6593,16 +6994,16 @@ Backoff.prototype.reset = function() {
|
|
|
6593
6994
|
|
|
6594
6995
|
module.exports = Backoff;
|
|
6595
6996
|
|
|
6596
|
-
},{"events":
|
|
6997
|
+
},{"events":54,"precond":62,"util":94}],41:[function(_dereq_,module,exports){
|
|
6597
6998
|
// Copyright (c) 2012 Mathieu Turcotte
|
|
6598
6999
|
// Licensed under the MIT license.
|
|
6599
7000
|
|
|
6600
|
-
var events =
|
|
6601
|
-
var precond =
|
|
6602
|
-
var util =
|
|
7001
|
+
var events = _dereq_('events');
|
|
7002
|
+
var precond = _dereq_('precond');
|
|
7003
|
+
var util = _dereq_('util');
|
|
6603
7004
|
|
|
6604
|
-
var Backoff =
|
|
6605
|
-
var FibonacciBackoffStrategy =
|
|
7005
|
+
var Backoff = _dereq_('./backoff');
|
|
7006
|
+
var FibonacciBackoffStrategy = _dereq_('./strategy/fibonacci');
|
|
6606
7007
|
|
|
6607
7008
|
// Wraps a function to be called in a backoff loop.
|
|
6608
7009
|
function FunctionCall(fn, args, callback) {
|
|
@@ -6621,6 +7022,7 @@ function FunctionCall(fn, args, callback) {
|
|
|
6621
7022
|
this.backoff_ = null;
|
|
6622
7023
|
this.strategy_ = null;
|
|
6623
7024
|
this.failAfter_ = -1;
|
|
7025
|
+
this.retryPredicate_ = FunctionCall.DEFAULT_RETRY_PREDICATE_;
|
|
6624
7026
|
|
|
6625
7027
|
this.state_ = FunctionCall.State_.PENDING;
|
|
6626
7028
|
}
|
|
@@ -6639,6 +7041,11 @@ FunctionCall.State_ = {
|
|
|
6639
7041
|
ABORTED: 3
|
|
6640
7042
|
};
|
|
6641
7043
|
|
|
7044
|
+
// The default retry predicate which considers any error as retriable.
|
|
7045
|
+
FunctionCall.DEFAULT_RETRY_PREDICATE_ = function(err) {
|
|
7046
|
+
return true;
|
|
7047
|
+
};
|
|
7048
|
+
|
|
6642
7049
|
// Checks whether the call is pending.
|
|
6643
7050
|
FunctionCall.prototype.isPending = function() {
|
|
6644
7051
|
return this.state_ == FunctionCall.State_.PENDING;
|
|
@@ -6667,6 +7074,16 @@ FunctionCall.prototype.setStrategy = function(strategy) {
|
|
|
6667
7074
|
return this; // Return this for chaining.
|
|
6668
7075
|
};
|
|
6669
7076
|
|
|
7077
|
+
// Sets the predicate which will be used to determine whether the errors
|
|
7078
|
+
// returned from the wrapped function should be retried or not, e.g. a
|
|
7079
|
+
// network error would be retriable while a type error would stop the
|
|
7080
|
+
// function call.
|
|
7081
|
+
FunctionCall.prototype.retryIf = function(retryPredicate) {
|
|
7082
|
+
precond.checkState(this.isPending(), 'FunctionCall in progress.');
|
|
7083
|
+
this.retryPredicate_ = retryPredicate;
|
|
7084
|
+
return this;
|
|
7085
|
+
};
|
|
7086
|
+
|
|
6670
7087
|
// Returns all intermediary results returned by the wrapped function since
|
|
6671
7088
|
// the initial call.
|
|
6672
7089
|
FunctionCall.prototype.getLastResult = function() {
|
|
@@ -6687,19 +7104,24 @@ FunctionCall.prototype.failAfter = function(maxNumberOfRetry) {
|
|
|
6687
7104
|
|
|
6688
7105
|
// Aborts the call.
|
|
6689
7106
|
FunctionCall.prototype.abort = function() {
|
|
6690
|
-
|
|
7107
|
+
if (this.isCompleted() || this.isAborted()) {
|
|
7108
|
+
return;
|
|
7109
|
+
}
|
|
6691
7110
|
|
|
6692
7111
|
if (this.isRunning()) {
|
|
6693
7112
|
this.backoff_.reset();
|
|
6694
7113
|
}
|
|
6695
7114
|
|
|
6696
7115
|
this.state_ = FunctionCall.State_.ABORTED;
|
|
7116
|
+
this.lastResult_ = [new Error('Backoff aborted.')];
|
|
7117
|
+
this.emit('abort');
|
|
7118
|
+
this.doCallback_();
|
|
6697
7119
|
};
|
|
6698
7120
|
|
|
6699
7121
|
// Initiates the call to the wrapped function. Accepts an optional factory
|
|
6700
7122
|
// function used to create the backoff instance; used when testing.
|
|
6701
7123
|
FunctionCall.prototype.start = function(backoffFactory) {
|
|
6702
|
-
precond.checkState(!this.isAborted(), 'FunctionCall aborted.');
|
|
7124
|
+
precond.checkState(!this.isAborted(), 'FunctionCall is aborted.');
|
|
6703
7125
|
precond.checkState(this.isPending(), 'FunctionCall already started.');
|
|
6704
7126
|
|
|
6705
7127
|
var strategy = this.strategy_ || new FibonacciBackoffStrategy();
|
|
@@ -6748,8 +7170,9 @@ FunctionCall.prototype.handleFunctionCallback_ = function() {
|
|
|
6748
7170
|
this.lastResult_ = args; // Save last callback arguments.
|
|
6749
7171
|
events.EventEmitter.prototype.emit.apply(this, ['callback'].concat(args));
|
|
6750
7172
|
|
|
6751
|
-
|
|
6752
|
-
|
|
7173
|
+
var err = args[0];
|
|
7174
|
+
if (err && this.retryPredicate_(err)) {
|
|
7175
|
+
this.backoff_.backoff(err);
|
|
6753
7176
|
} else {
|
|
6754
7177
|
this.state_ = FunctionCall.State_.COMPLETED;
|
|
6755
7178
|
this.doCallback_();
|
|
@@ -6763,14 +7186,14 @@ FunctionCall.prototype.handleBackoff_ = function(number, delay, err) {
|
|
|
6763
7186
|
|
|
6764
7187
|
module.exports = FunctionCall;
|
|
6765
7188
|
|
|
6766
|
-
},{"./backoff":
|
|
7189
|
+
},{"./backoff":40,"./strategy/fibonacci":43,"events":54,"precond":62,"util":94}],42:[function(_dereq_,module,exports){
|
|
6767
7190
|
// Copyright (c) 2012 Mathieu Turcotte
|
|
6768
7191
|
// Licensed under the MIT license.
|
|
6769
7192
|
|
|
6770
|
-
var util =
|
|
6771
|
-
var precond =
|
|
7193
|
+
var util = _dereq_('util');
|
|
7194
|
+
var precond = _dereq_('precond');
|
|
6772
7195
|
|
|
6773
|
-
var BackoffStrategy =
|
|
7196
|
+
var BackoffStrategy = _dereq_('./strategy');
|
|
6774
7197
|
|
|
6775
7198
|
// Exponential backoff strategy.
|
|
6776
7199
|
function ExponentialBackoffStrategy(options) {
|
|
@@ -6806,13 +7229,13 @@ ExponentialBackoffStrategy.prototype.reset_ = function() {
|
|
|
6806
7229
|
|
|
6807
7230
|
module.exports = ExponentialBackoffStrategy;
|
|
6808
7231
|
|
|
6809
|
-
},{"./strategy":
|
|
7232
|
+
},{"./strategy":44,"precond":62,"util":94}],43:[function(_dereq_,module,exports){
|
|
6810
7233
|
// Copyright (c) 2012 Mathieu Turcotte
|
|
6811
7234
|
// Licensed under the MIT license.
|
|
6812
7235
|
|
|
6813
|
-
var util =
|
|
7236
|
+
var util = _dereq_('util');
|
|
6814
7237
|
|
|
6815
|
-
var BackoffStrategy =
|
|
7238
|
+
var BackoffStrategy = _dereq_('./strategy');
|
|
6816
7239
|
|
|
6817
7240
|
// Fibonacci backoff strategy.
|
|
6818
7241
|
function FibonacciBackoffStrategy(options) {
|
|
@@ -6836,12 +7259,12 @@ FibonacciBackoffStrategy.prototype.reset_ = function() {
|
|
|
6836
7259
|
|
|
6837
7260
|
module.exports = FibonacciBackoffStrategy;
|
|
6838
7261
|
|
|
6839
|
-
},{"./strategy":
|
|
7262
|
+
},{"./strategy":44,"util":94}],44:[function(_dereq_,module,exports){
|
|
6840
7263
|
// Copyright (c) 2012 Mathieu Turcotte
|
|
6841
7264
|
// Licensed under the MIT license.
|
|
6842
7265
|
|
|
6843
|
-
var events =
|
|
6844
|
-
var util =
|
|
7266
|
+
var events = _dereq_('events');
|
|
7267
|
+
var util = _dereq_('util');
|
|
6845
7268
|
|
|
6846
7269
|
function isDef(value) {
|
|
6847
7270
|
return value !== undefined && value !== null;
|
|
@@ -6918,7 +7341,7 @@ BackoffStrategy.prototype.reset_ = function() {
|
|
|
6918
7341
|
|
|
6919
7342
|
module.exports = BackoffStrategy;
|
|
6920
7343
|
|
|
6921
|
-
},{"events":
|
|
7344
|
+
},{"events":54,"util":94}],45:[function(_dereq_,module,exports){
|
|
6922
7345
|
var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
6923
7346
|
|
|
6924
7347
|
;(function (exports) {
|
|
@@ -7044,11 +7467,11 @@ var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
|
7044
7467
|
exports.fromByteArray = uint8ToBase64
|
|
7045
7468
|
}(typeof exports === 'undefined' ? (this.base64js = {}) : exports))
|
|
7046
7469
|
|
|
7047
|
-
},{}],
|
|
7470
|
+
},{}],46:[function(_dereq_,module,exports){
|
|
7048
7471
|
|
|
7049
|
-
},{}],
|
|
7050
|
-
arguments[4][
|
|
7051
|
-
},{"dup":
|
|
7472
|
+
},{}],47:[function(_dereq_,module,exports){
|
|
7473
|
+
arguments[4][46][0].apply(exports,arguments)
|
|
7474
|
+
},{"dup":46}],48:[function(_dereq_,module,exports){
|
|
7052
7475
|
(function (global){
|
|
7053
7476
|
/*!
|
|
7054
7477
|
* The buffer module from node.js, for the browser.
|
|
@@ -7060,9 +7483,9 @@ arguments[4][41][0].apply(exports,arguments)
|
|
|
7060
7483
|
|
|
7061
7484
|
'use strict'
|
|
7062
7485
|
|
|
7063
|
-
var base64 =
|
|
7064
|
-
var ieee754 =
|
|
7065
|
-
var isArray =
|
|
7486
|
+
var base64 = _dereq_('base64-js')
|
|
7487
|
+
var ieee754 = _dereq_('ieee754')
|
|
7488
|
+
var isArray = _dereq_('isarray')
|
|
7066
7489
|
|
|
7067
7490
|
exports.Buffer = Buffer
|
|
7068
7491
|
exports.SlowBuffer = SlowBuffer
|
|
@@ -8600,14 +9023,14 @@ function blitBuffer (src, dst, offset, length) {
|
|
|
8600
9023
|
}
|
|
8601
9024
|
|
|
8602
9025
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
8603
|
-
},{"base64-js":
|
|
9026
|
+
},{"base64-js":45,"ieee754":56,"isarray":49}],49:[function(_dereq_,module,exports){
|
|
8604
9027
|
var toString = {}.toString;
|
|
8605
9028
|
|
|
8606
9029
|
module.exports = Array.isArray || function (arr) {
|
|
8607
9030
|
return toString.call(arr) == '[object Array]';
|
|
8608
9031
|
};
|
|
8609
9032
|
|
|
8610
|
-
},{}],
|
|
9033
|
+
},{}],50:[function(_dereq_,module,exports){
|
|
8611
9034
|
module.exports = {
|
|
8612
9035
|
"100": "Continue",
|
|
8613
9036
|
"101": "Switching Protocols",
|
|
@@ -8672,7 +9095,7 @@ module.exports = {
|
|
|
8672
9095
|
"511": "Network Authentication Required"
|
|
8673
9096
|
}
|
|
8674
9097
|
|
|
8675
|
-
},{}],
|
|
9098
|
+
},{}],51:[function(_dereq_,module,exports){
|
|
8676
9099
|
(function (Buffer){
|
|
8677
9100
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
8678
9101
|
//
|
|
@@ -8782,11 +9205,11 @@ function objectToString(o) {
|
|
|
8782
9205
|
return Object.prototype.toString.call(o);
|
|
8783
9206
|
}
|
|
8784
9207
|
|
|
8785
|
-
}).call(this,{"isBuffer":
|
|
8786
|
-
},{"../../is-buffer/index.js":
|
|
8787
|
-
module.exports =
|
|
9208
|
+
}).call(this,{"isBuffer":_dereq_("../../is-buffer/index.js")})
|
|
9209
|
+
},{"../../is-buffer/index.js":58}],52:[function(_dereq_,module,exports){
|
|
9210
|
+
module.exports = _dereq_('./lib');
|
|
8788
9211
|
|
|
8789
|
-
},{"./lib":
|
|
9212
|
+
},{"./lib":53}],53:[function(_dereq_,module,exports){
|
|
8790
9213
|
var FORMAT_REGEXP = /^PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?$/;
|
|
8791
9214
|
|
|
8792
9215
|
function matchToInteger(match){
|
|
@@ -8859,7 +9282,7 @@ exports.toSeconds = function(stringOrDuration) {
|
|
|
8859
9282
|
return duration.hours * 3600 + duration.minutes * 60 + duration.seconds;
|
|
8860
9283
|
};
|
|
8861
9284
|
|
|
8862
|
-
},{}],
|
|
9285
|
+
},{}],54:[function(_dereq_,module,exports){
|
|
8863
9286
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
8864
9287
|
//
|
|
8865
9288
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
@@ -9159,8 +9582,8 @@ function isUndefined(arg) {
|
|
|
9159
9582
|
return arg === void 0;
|
|
9160
9583
|
}
|
|
9161
9584
|
|
|
9162
|
-
},{}],
|
|
9163
|
-
var http =
|
|
9585
|
+
},{}],55:[function(_dereq_,module,exports){
|
|
9586
|
+
var http = _dereq_('http');
|
|
9164
9587
|
|
|
9165
9588
|
var https = module.exports;
|
|
9166
9589
|
|
|
@@ -9175,7 +9598,7 @@ https.request = function (params, cb) {
|
|
|
9175
9598
|
return http.request.call(this, params, cb);
|
|
9176
9599
|
}
|
|
9177
9600
|
|
|
9178
|
-
},{"http":
|
|
9601
|
+
},{"http":84}],56:[function(_dereq_,module,exports){
|
|
9179
9602
|
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
|
|
9180
9603
|
var e, m
|
|
9181
9604
|
var eLen = nBytes * 8 - mLen - 1
|
|
@@ -9261,7 +9684,7 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
|
|
|
9261
9684
|
buffer[offset + i - d] |= s * 128
|
|
9262
9685
|
}
|
|
9263
9686
|
|
|
9264
|
-
},{}],
|
|
9687
|
+
},{}],57:[function(_dereq_,module,exports){
|
|
9265
9688
|
if (typeof Object.create === 'function') {
|
|
9266
9689
|
// implementation from standard node.js 'util' module
|
|
9267
9690
|
module.exports = function inherits(ctor, superCtor) {
|
|
@@ -9286,7 +9709,7 @@ if (typeof Object.create === 'function') {
|
|
|
9286
9709
|
}
|
|
9287
9710
|
}
|
|
9288
9711
|
|
|
9289
|
-
},{}],
|
|
9712
|
+
},{}],58:[function(_dereq_,module,exports){
|
|
9290
9713
|
/**
|
|
9291
9714
|
* Determine if an object is Buffer
|
|
9292
9715
|
*
|
|
@@ -9305,12 +9728,7 @@ module.exports = function (obj) {
|
|
|
9305
9728
|
))
|
|
9306
9729
|
}
|
|
9307
9730
|
|
|
9308
|
-
},{}],
|
|
9309
|
-
module.exports = Array.isArray || function (arr) {
|
|
9310
|
-
return Object.prototype.toString.call(arr) == '[object Array]';
|
|
9311
|
-
};
|
|
9312
|
-
|
|
9313
|
-
},{}],55:[function(require,module,exports){
|
|
9731
|
+
},{}],59:[function(_dereq_,module,exports){
|
|
9314
9732
|
/*
|
|
9315
9733
|
|
|
9316
9734
|
Javascript State Machine Library - https://github.com/jakesgordon/javascript-state-machine
|
|
@@ -9522,7 +9940,7 @@ module.exports = Array.isArray || function (arr) {
|
|
|
9522
9940
|
// AMD/REQUIRE
|
|
9523
9941
|
//============
|
|
9524
9942
|
else if (typeof define === 'function' && define.amd) {
|
|
9525
|
-
define(function(
|
|
9943
|
+
define(function(_dereq_) { return StateMachine; });
|
|
9526
9944
|
}
|
|
9527
9945
|
//========
|
|
9528
9946
|
// BROWSER
|
|
@@ -9539,7 +9957,7 @@ module.exports = Array.isArray || function (arr) {
|
|
|
9539
9957
|
|
|
9540
9958
|
}());
|
|
9541
9959
|
|
|
9542
|
-
},{}],
|
|
9960
|
+
},{}],60:[function(_dereq_,module,exports){
|
|
9543
9961
|
/*
|
|
9544
9962
|
* loglevel - https://github.com/pimterry/loglevel
|
|
9545
9963
|
*
|
|
@@ -9548,7 +9966,7 @@ module.exports = Array.isArray || function (arr) {
|
|
|
9548
9966
|
*/
|
|
9549
9967
|
(function (root, definition) {
|
|
9550
9968
|
"use strict";
|
|
9551
|
-
if (typeof module === 'object' && module.exports && typeof
|
|
9969
|
+
if (typeof module === 'object' && module.exports && typeof _dereq_ === 'function') {
|
|
9552
9970
|
module.exports = definition();
|
|
9553
9971
|
} else if (typeof define === 'function' && typeof define.amd === 'object') {
|
|
9554
9972
|
define(definition);
|
|
@@ -9764,7 +10182,7 @@ module.exports = Array.isArray || function (arr) {
|
|
|
9764
10182
|
return defaultLogger;
|
|
9765
10183
|
}));
|
|
9766
10184
|
|
|
9767
|
-
},{}],
|
|
10185
|
+
},{}],61:[function(_dereq_,module,exports){
|
|
9768
10186
|
(function (global){
|
|
9769
10187
|
/*!
|
|
9770
10188
|
* Platform.js v1.3.1 <http://mths.be/platform>
|
|
@@ -10903,22 +11321,22 @@ module.exports = Array.isArray || function (arr) {
|
|
|
10903
11321
|
}.call(this));
|
|
10904
11322
|
|
|
10905
11323
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
10906
|
-
},{}],
|
|
11324
|
+
},{}],62:[function(_dereq_,module,exports){
|
|
10907
11325
|
/*
|
|
10908
11326
|
* Copyright (c) 2012 Mathieu Turcotte
|
|
10909
11327
|
* Licensed under the MIT license.
|
|
10910
11328
|
*/
|
|
10911
11329
|
|
|
10912
|
-
module.exports =
|
|
10913
|
-
},{"./lib/checks":
|
|
11330
|
+
module.exports = _dereq_('./lib/checks');
|
|
11331
|
+
},{"./lib/checks":63}],63:[function(_dereq_,module,exports){
|
|
10914
11332
|
/*
|
|
10915
11333
|
* Copyright (c) 2012 Mathieu Turcotte
|
|
10916
11334
|
* Licensed under the MIT license.
|
|
10917
11335
|
*/
|
|
10918
11336
|
|
|
10919
|
-
var util =
|
|
11337
|
+
var util = _dereq_('util');
|
|
10920
11338
|
|
|
10921
|
-
var errors = module.exports =
|
|
11339
|
+
var errors = module.exports = _dereq_('./errors');
|
|
10922
11340
|
|
|
10923
11341
|
function failCheck(ExceptionConstructor, callee, messageFormat, formatArgs) {
|
|
10924
11342
|
messageFormat = messageFormat || '';
|
|
@@ -11006,13 +11424,13 @@ module.exports.checkIsBoolean = typeCheck('boolean');
|
|
|
11006
11424
|
module.exports.checkIsFunction = typeCheck('function');
|
|
11007
11425
|
module.exports.checkIsObject = typeCheck('object');
|
|
11008
11426
|
|
|
11009
|
-
},{"./errors":
|
|
11427
|
+
},{"./errors":64,"util":94}],64:[function(_dereq_,module,exports){
|
|
11010
11428
|
/*
|
|
11011
11429
|
* Copyright (c) 2012 Mathieu Turcotte
|
|
11012
11430
|
* Licensed under the MIT license.
|
|
11013
11431
|
*/
|
|
11014
11432
|
|
|
11015
|
-
var util =
|
|
11433
|
+
var util = _dereq_('util');
|
|
11016
11434
|
|
|
11017
11435
|
function IllegalArgumentError(message) {
|
|
11018
11436
|
Error.call(this, message);
|
|
@@ -11032,7 +11450,7 @@ IllegalStateError.prototype.name = 'IllegalStateError';
|
|
|
11032
11450
|
|
|
11033
11451
|
module.exports.IllegalStateError = IllegalStateError;
|
|
11034
11452
|
module.exports.IllegalArgumentError = IllegalArgumentError;
|
|
11035
|
-
},{"util":
|
|
11453
|
+
},{"util":94}],65:[function(_dereq_,module,exports){
|
|
11036
11454
|
(function (process){
|
|
11037
11455
|
'use strict';
|
|
11038
11456
|
|
|
@@ -11055,8 +11473,8 @@ function nextTick(fn) {
|
|
|
11055
11473
|
});
|
|
11056
11474
|
}
|
|
11057
11475
|
|
|
11058
|
-
}).call(this,
|
|
11059
|
-
},{"_process":
|
|
11476
|
+
}).call(this,_dereq_('_process'))
|
|
11477
|
+
},{"_process":66}],66:[function(_dereq_,module,exports){
|
|
11060
11478
|
// shim for using process in browser
|
|
11061
11479
|
|
|
11062
11480
|
var process = module.exports = {};
|
|
@@ -11149,7 +11567,7 @@ process.chdir = function (dir) {
|
|
|
11149
11567
|
};
|
|
11150
11568
|
process.umask = function() { return 0; };
|
|
11151
11569
|
|
|
11152
|
-
},{}],
|
|
11570
|
+
},{}],67:[function(_dereq_,module,exports){
|
|
11153
11571
|
(function (global){
|
|
11154
11572
|
/*! https://mths.be/punycode v1.4.0 by @mathias */
|
|
11155
11573
|
;(function(root) {
|
|
@@ -11686,7 +12104,7 @@ process.umask = function() { return 0; };
|
|
|
11686
12104
|
}(this));
|
|
11687
12105
|
|
|
11688
12106
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
11689
|
-
},{}],
|
|
12107
|
+
},{}],68:[function(_dereq_,module,exports){
|
|
11690
12108
|
(function (process){
|
|
11691
12109
|
// vim:ts=4:sts=4:sw=4:
|
|
11692
12110
|
/*!
|
|
@@ -13737,8 +14155,8 @@ return Q;
|
|
|
13737
14155
|
|
|
13738
14156
|
});
|
|
13739
14157
|
|
|
13740
|
-
}).call(this,
|
|
13741
|
-
},{"_process":
|
|
14158
|
+
}).call(this,_dereq_('_process'))
|
|
14159
|
+
},{"_process":66}],69:[function(_dereq_,module,exports){
|
|
13742
14160
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
13743
14161
|
//
|
|
13744
14162
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
@@ -13824,7 +14242,7 @@ var isArray = Array.isArray || function (xs) {
|
|
|
13824
14242
|
return Object.prototype.toString.call(xs) === '[object Array]';
|
|
13825
14243
|
};
|
|
13826
14244
|
|
|
13827
|
-
},{}],
|
|
14245
|
+
},{}],70:[function(_dereq_,module,exports){
|
|
13828
14246
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
13829
14247
|
//
|
|
13830
14248
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
@@ -13911,13 +14329,13 @@ var objectKeys = Object.keys || function (obj) {
|
|
|
13911
14329
|
return res;
|
|
13912
14330
|
};
|
|
13913
14331
|
|
|
13914
|
-
},{}],
|
|
14332
|
+
},{}],71:[function(_dereq_,module,exports){
|
|
13915
14333
|
'use strict';
|
|
13916
14334
|
|
|
13917
|
-
exports.decode = exports.parse =
|
|
13918
|
-
exports.encode = exports.stringify =
|
|
14335
|
+
exports.decode = exports.parse = _dereq_('./decode');
|
|
14336
|
+
exports.encode = exports.stringify = _dereq_('./encode');
|
|
13919
14337
|
|
|
13920
|
-
},{"./decode":
|
|
14338
|
+
},{"./decode":69,"./encode":70}],72:[function(_dereq_,module,exports){
|
|
13921
14339
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
13922
14340
|
//
|
|
13923
14341
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
@@ -13941,15 +14359,15 @@ exports.encode = exports.stringify = require('./encode');
|
|
|
13941
14359
|
|
|
13942
14360
|
module.exports = Stream;
|
|
13943
14361
|
|
|
13944
|
-
var EE =
|
|
13945
|
-
var inherits =
|
|
14362
|
+
var EE = _dereq_('events').EventEmitter;
|
|
14363
|
+
var inherits = _dereq_('inherits');
|
|
13946
14364
|
|
|
13947
14365
|
inherits(Stream, EE);
|
|
13948
|
-
Stream.Readable =
|
|
13949
|
-
Stream.Writable =
|
|
13950
|
-
Stream.Duplex =
|
|
13951
|
-
Stream.Transform =
|
|
13952
|
-
Stream.PassThrough =
|
|
14366
|
+
Stream.Readable = _dereq_('readable-stream/readable.js');
|
|
14367
|
+
Stream.Writable = _dereq_('readable-stream/writable.js');
|
|
14368
|
+
Stream.Duplex = _dereq_('readable-stream/duplex.js');
|
|
14369
|
+
Stream.Transform = _dereq_('readable-stream/transform.js');
|
|
14370
|
+
Stream.PassThrough = _dereq_('readable-stream/passthrough.js');
|
|
13953
14371
|
|
|
13954
14372
|
// Backwards-compat with node 0.4.x
|
|
13955
14373
|
Stream.Stream = Stream;
|
|
@@ -14046,10 +14464,12 @@ Stream.prototype.pipe = function(dest, options) {
|
|
|
14046
14464
|
return dest;
|
|
14047
14465
|
};
|
|
14048
14466
|
|
|
14049
|
-
},{"events":
|
|
14050
|
-
|
|
14467
|
+
},{"events":54,"inherits":57,"readable-stream/duplex.js":74,"readable-stream/passthrough.js":80,"readable-stream/readable.js":81,"readable-stream/transform.js":82,"readable-stream/writable.js":83}],73:[function(_dereq_,module,exports){
|
|
14468
|
+
arguments[4][49][0].apply(exports,arguments)
|
|
14469
|
+
},{"dup":49}],74:[function(_dereq_,module,exports){
|
|
14470
|
+
module.exports = _dereq_("./lib/_stream_duplex.js")
|
|
14051
14471
|
|
|
14052
|
-
},{"./lib/_stream_duplex.js":
|
|
14472
|
+
},{"./lib/_stream_duplex.js":75}],75:[function(_dereq_,module,exports){
|
|
14053
14473
|
// a duplex stream is just a stream that is both readable and writable.
|
|
14054
14474
|
// Since JS doesn't have multiple prototypal inheritance, this class
|
|
14055
14475
|
// prototypally inherits from Readable, and then parasitically from
|
|
@@ -14058,55 +14478,49 @@ module.exports = require("./lib/_stream_duplex.js")
|
|
|
14058
14478
|
'use strict';
|
|
14059
14479
|
|
|
14060
14480
|
/*<replacement>*/
|
|
14481
|
+
|
|
14061
14482
|
var objectKeys = Object.keys || function (obj) {
|
|
14062
14483
|
var keys = [];
|
|
14063
|
-
for (var key in obj)
|
|
14064
|
-
|
|
14065
|
-
}
|
|
14484
|
+
for (var key in obj) {
|
|
14485
|
+
keys.push(key);
|
|
14486
|
+
}return keys;
|
|
14487
|
+
};
|
|
14066
14488
|
/*</replacement>*/
|
|
14067
14489
|
|
|
14068
|
-
|
|
14069
14490
|
module.exports = Duplex;
|
|
14070
14491
|
|
|
14071
14492
|
/*<replacement>*/
|
|
14072
|
-
var processNextTick =
|
|
14493
|
+
var processNextTick = _dereq_('process-nextick-args');
|
|
14073
14494
|
/*</replacement>*/
|
|
14074
14495
|
|
|
14075
|
-
|
|
14076
|
-
|
|
14077
14496
|
/*<replacement>*/
|
|
14078
|
-
var util =
|
|
14079
|
-
util.inherits =
|
|
14497
|
+
var util = _dereq_('core-util-is');
|
|
14498
|
+
util.inherits = _dereq_('inherits');
|
|
14080
14499
|
/*</replacement>*/
|
|
14081
14500
|
|
|
14082
|
-
var Readable =
|
|
14083
|
-
var Writable =
|
|
14501
|
+
var Readable = _dereq_('./_stream_readable');
|
|
14502
|
+
var Writable = _dereq_('./_stream_writable');
|
|
14084
14503
|
|
|
14085
14504
|
util.inherits(Duplex, Readable);
|
|
14086
14505
|
|
|
14087
14506
|
var keys = objectKeys(Writable.prototype);
|
|
14088
14507
|
for (var v = 0; v < keys.length; v++) {
|
|
14089
14508
|
var method = keys[v];
|
|
14090
|
-
if (!Duplex.prototype[method])
|
|
14091
|
-
Duplex.prototype[method] = Writable.prototype[method];
|
|
14509
|
+
if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
|
|
14092
14510
|
}
|
|
14093
14511
|
|
|
14094
14512
|
function Duplex(options) {
|
|
14095
|
-
if (!(this instanceof Duplex))
|
|
14096
|
-
return new Duplex(options);
|
|
14513
|
+
if (!(this instanceof Duplex)) return new Duplex(options);
|
|
14097
14514
|
|
|
14098
14515
|
Readable.call(this, options);
|
|
14099
14516
|
Writable.call(this, options);
|
|
14100
14517
|
|
|
14101
|
-
if (options && options.readable === false)
|
|
14102
|
-
this.readable = false;
|
|
14518
|
+
if (options && options.readable === false) this.readable = false;
|
|
14103
14519
|
|
|
14104
|
-
if (options && options.writable === false)
|
|
14105
|
-
this.writable = false;
|
|
14520
|
+
if (options && options.writable === false) this.writable = false;
|
|
14106
14521
|
|
|
14107
14522
|
this.allowHalfOpen = true;
|
|
14108
|
-
if (options && options.allowHalfOpen === false)
|
|
14109
|
-
this.allowHalfOpen = false;
|
|
14523
|
+
if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
|
|
14110
14524
|
|
|
14111
14525
|
this.once('end', onend);
|
|
14112
14526
|
}
|
|
@@ -14115,8 +14529,7 @@ function Duplex(options) {
|
|
|
14115
14529
|
function onend() {
|
|
14116
14530
|
// if we allow half-open state, or if the writable side ended,
|
|
14117
14531
|
// then we're ok.
|
|
14118
|
-
if (this.allowHalfOpen || this._writableState.ended)
|
|
14119
|
-
return;
|
|
14532
|
+
if (this.allowHalfOpen || this._writableState.ended) return;
|
|
14120
14533
|
|
|
14121
14534
|
// no more data can be written.
|
|
14122
14535
|
// But allow more writes to happen in this tick.
|
|
@@ -14127,13 +14540,12 @@ function onEndNT(self) {
|
|
|
14127
14540
|
self.end();
|
|
14128
14541
|
}
|
|
14129
14542
|
|
|
14130
|
-
function forEach
|
|
14543
|
+
function forEach(xs, f) {
|
|
14131
14544
|
for (var i = 0, l = xs.length; i < l; i++) {
|
|
14132
14545
|
f(xs[i], i);
|
|
14133
14546
|
}
|
|
14134
14547
|
}
|
|
14135
|
-
|
|
14136
|
-
},{"./_stream_readable":72,"./_stream_writable":74,"core-util-is":46,"inherits":52,"process-nextick-args":61}],71:[function(require,module,exports){
|
|
14548
|
+
},{"./_stream_readable":77,"./_stream_writable":79,"core-util-is":51,"inherits":57,"process-nextick-args":65}],76:[function(_dereq_,module,exports){
|
|
14137
14549
|
// a passthrough stream.
|
|
14138
14550
|
// basically just the most minimal sort of Transform stream.
|
|
14139
14551
|
// Every written chunk gets output as-is.
|
|
@@ -14142,80 +14554,73 @@ function forEach (xs, f) {
|
|
|
14142
14554
|
|
|
14143
14555
|
module.exports = PassThrough;
|
|
14144
14556
|
|
|
14145
|
-
var Transform =
|
|
14557
|
+
var Transform = _dereq_('./_stream_transform');
|
|
14146
14558
|
|
|
14147
14559
|
/*<replacement>*/
|
|
14148
|
-
var util =
|
|
14149
|
-
util.inherits =
|
|
14560
|
+
var util = _dereq_('core-util-is');
|
|
14561
|
+
util.inherits = _dereq_('inherits');
|
|
14150
14562
|
/*</replacement>*/
|
|
14151
14563
|
|
|
14152
14564
|
util.inherits(PassThrough, Transform);
|
|
14153
14565
|
|
|
14154
14566
|
function PassThrough(options) {
|
|
14155
|
-
if (!(this instanceof PassThrough))
|
|
14156
|
-
return new PassThrough(options);
|
|
14567
|
+
if (!(this instanceof PassThrough)) return new PassThrough(options);
|
|
14157
14568
|
|
|
14158
14569
|
Transform.call(this, options);
|
|
14159
14570
|
}
|
|
14160
14571
|
|
|
14161
|
-
PassThrough.prototype._transform = function(chunk, encoding, cb) {
|
|
14572
|
+
PassThrough.prototype._transform = function (chunk, encoding, cb) {
|
|
14162
14573
|
cb(null, chunk);
|
|
14163
14574
|
};
|
|
14164
|
-
|
|
14165
|
-
},{"./_stream_transform":73,"core-util-is":46,"inherits":52}],72:[function(require,module,exports){
|
|
14575
|
+
},{"./_stream_transform":78,"core-util-is":51,"inherits":57}],77:[function(_dereq_,module,exports){
|
|
14166
14576
|
(function (process){
|
|
14167
14577
|
'use strict';
|
|
14168
14578
|
|
|
14169
14579
|
module.exports = Readable;
|
|
14170
14580
|
|
|
14171
14581
|
/*<replacement>*/
|
|
14172
|
-
var processNextTick =
|
|
14582
|
+
var processNextTick = _dereq_('process-nextick-args');
|
|
14173
14583
|
/*</replacement>*/
|
|
14174
14584
|
|
|
14175
|
-
|
|
14176
14585
|
/*<replacement>*/
|
|
14177
|
-
var isArray =
|
|
14586
|
+
var isArray = _dereq_('isarray');
|
|
14178
14587
|
/*</replacement>*/
|
|
14179
14588
|
|
|
14180
|
-
|
|
14181
14589
|
/*<replacement>*/
|
|
14182
|
-
var Buffer =
|
|
14590
|
+
var Buffer = _dereq_('buffer').Buffer;
|
|
14183
14591
|
/*</replacement>*/
|
|
14184
14592
|
|
|
14185
14593
|
Readable.ReadableState = ReadableState;
|
|
14186
14594
|
|
|
14187
|
-
var EE =
|
|
14595
|
+
var EE = _dereq_('events');
|
|
14188
14596
|
|
|
14189
14597
|
/*<replacement>*/
|
|
14190
|
-
var EElistenerCount = function(emitter, type) {
|
|
14598
|
+
var EElistenerCount = function (emitter, type) {
|
|
14191
14599
|
return emitter.listeners(type).length;
|
|
14192
14600
|
};
|
|
14193
14601
|
/*</replacement>*/
|
|
14194
14602
|
|
|
14195
|
-
|
|
14196
|
-
|
|
14197
14603
|
/*<replacement>*/
|
|
14198
14604
|
var Stream;
|
|
14199
|
-
(function (){
|
|
14200
|
-
|
|
14201
|
-
|
|
14202
|
-
|
|
14203
|
-
Stream =
|
|
14204
|
-
}
|
|
14605
|
+
(function () {
|
|
14606
|
+
try {
|
|
14607
|
+
Stream = _dereq_('st' + 'ream');
|
|
14608
|
+
} catch (_) {} finally {
|
|
14609
|
+
if (!Stream) Stream = _dereq_('events').EventEmitter;
|
|
14610
|
+
}
|
|
14611
|
+
})();
|
|
14205
14612
|
/*</replacement>*/
|
|
14206
14613
|
|
|
14207
|
-
var Buffer =
|
|
14614
|
+
var Buffer = _dereq_('buffer').Buffer;
|
|
14208
14615
|
|
|
14209
14616
|
/*<replacement>*/
|
|
14210
|
-
var util =
|
|
14211
|
-
util.inherits =
|
|
14617
|
+
var util = _dereq_('core-util-is');
|
|
14618
|
+
util.inherits = _dereq_('inherits');
|
|
14212
14619
|
/*</replacement>*/
|
|
14213
14620
|
|
|
14214
|
-
|
|
14215
|
-
|
|
14216
14621
|
/*<replacement>*/
|
|
14217
|
-
var debugUtil =
|
|
14218
|
-
var debug;
|
|
14622
|
+
var debugUtil = _dereq_('util');
|
|
14623
|
+
var debug = undefined;
|
|
14219
14624
|
if (debugUtil && debugUtil.debuglog) {
|
|
14220
14625
|
debug = debugUtil.debuglog('stream');
|
|
14221
14626
|
} else {
|
|
@@ -14229,7 +14634,7 @@ util.inherits(Readable, Stream);
|
|
|
14229
14634
|
|
|
14230
14635
|
var Duplex;
|
|
14231
14636
|
function ReadableState(options, stream) {
|
|
14232
|
-
Duplex = Duplex ||
|
|
14637
|
+
Duplex = Duplex || _dereq_('./_stream_duplex');
|
|
14233
14638
|
|
|
14234
14639
|
options = options || {};
|
|
14235
14640
|
|
|
@@ -14237,17 +14642,16 @@ function ReadableState(options, stream) {
|
|
|
14237
14642
|
// make all the buffer merging and length checks go away
|
|
14238
14643
|
this.objectMode = !!options.objectMode;
|
|
14239
14644
|
|
|
14240
|
-
if (stream instanceof Duplex)
|
|
14241
|
-
this.objectMode = this.objectMode || !!options.readableObjectMode;
|
|
14645
|
+
if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
|
|
14242
14646
|
|
|
14243
14647
|
// the point at which it stops calling _read() to fill the buffer
|
|
14244
14648
|
// Note: 0 is a valid value, means "don't call _read preemptively ever"
|
|
14245
14649
|
var hwm = options.highWaterMark;
|
|
14246
14650
|
var defaultHwm = this.objectMode ? 16 : 16 * 1024;
|
|
14247
|
-
this.highWaterMark =
|
|
14651
|
+
this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
|
|
14248
14652
|
|
|
14249
14653
|
// cast to ints.
|
|
14250
|
-
this.highWaterMark =
|
|
14654
|
+
this.highWaterMark = ~ ~this.highWaterMark;
|
|
14251
14655
|
|
|
14252
14656
|
this.buffer = [];
|
|
14253
14657
|
this.length = 0;
|
|
@@ -14269,6 +14673,7 @@ function ReadableState(options, stream) {
|
|
|
14269
14673
|
this.needReadable = false;
|
|
14270
14674
|
this.emittedReadable = false;
|
|
14271
14675
|
this.readableListening = false;
|
|
14676
|
+
this.resumeScheduled = false;
|
|
14272
14677
|
|
|
14273
14678
|
// Crypto is kind of old and crusty. Historically, its default string
|
|
14274
14679
|
// encoding is 'binary' so we have to make this configurable.
|
|
@@ -14288,8 +14693,7 @@ function ReadableState(options, stream) {
|
|
|
14288
14693
|
this.decoder = null;
|
|
14289
14694
|
this.encoding = null;
|
|
14290
14695
|
if (options.encoding) {
|
|
14291
|
-
if (!StringDecoder)
|
|
14292
|
-
StringDecoder = require('string_decoder/').StringDecoder;
|
|
14696
|
+
if (!StringDecoder) StringDecoder = _dereq_('string_decoder/').StringDecoder;
|
|
14293
14697
|
this.decoder = new StringDecoder(options.encoding);
|
|
14294
14698
|
this.encoding = options.encoding;
|
|
14295
14699
|
}
|
|
@@ -14297,18 +14701,16 @@ function ReadableState(options, stream) {
|
|
|
14297
14701
|
|
|
14298
14702
|
var Duplex;
|
|
14299
14703
|
function Readable(options) {
|
|
14300
|
-
Duplex = Duplex ||
|
|
14704
|
+
Duplex = Duplex || _dereq_('./_stream_duplex');
|
|
14301
14705
|
|
|
14302
|
-
if (!(this instanceof Readable))
|
|
14303
|
-
return new Readable(options);
|
|
14706
|
+
if (!(this instanceof Readable)) return new Readable(options);
|
|
14304
14707
|
|
|
14305
14708
|
this._readableState = new ReadableState(options, this);
|
|
14306
14709
|
|
|
14307
14710
|
// legacy
|
|
14308
14711
|
this.readable = true;
|
|
14309
14712
|
|
|
14310
|
-
if (options && typeof options.read === 'function')
|
|
14311
|
-
this._read = options.read;
|
|
14713
|
+
if (options && typeof options.read === 'function') this._read = options.read;
|
|
14312
14714
|
|
|
14313
14715
|
Stream.call(this);
|
|
14314
14716
|
}
|
|
@@ -14317,7 +14719,7 @@ function Readable(options) {
|
|
|
14317
14719
|
// This returns true if the highWaterMark has not been hit yet,
|
|
14318
14720
|
// similar to how Writable.write() returns true if you should
|
|
14319
14721
|
// write() some more.
|
|
14320
|
-
Readable.prototype.push = function(chunk, encoding) {
|
|
14722
|
+
Readable.prototype.push = function (chunk, encoding) {
|
|
14321
14723
|
var state = this._readableState;
|
|
14322
14724
|
|
|
14323
14725
|
if (!state.objectMode && typeof chunk === 'string') {
|
|
@@ -14332,12 +14734,12 @@ Readable.prototype.push = function(chunk, encoding) {
|
|
|
14332
14734
|
};
|
|
14333
14735
|
|
|
14334
14736
|
// Unshift should *always* be something directly out of read()
|
|
14335
|
-
Readable.prototype.unshift = function(chunk) {
|
|
14737
|
+
Readable.prototype.unshift = function (chunk) {
|
|
14336
14738
|
var state = this._readableState;
|
|
14337
14739
|
return readableAddChunk(this, state, chunk, '', true);
|
|
14338
14740
|
};
|
|
14339
14741
|
|
|
14340
|
-
Readable.prototype.isPaused = function() {
|
|
14742
|
+
Readable.prototype.isPaused = function () {
|
|
14341
14743
|
return this._readableState.flowing === false;
|
|
14342
14744
|
};
|
|
14343
14745
|
|
|
@@ -14356,26 +14758,28 @@ function readableAddChunk(stream, state, chunk, encoding, addToFront) {
|
|
|
14356
14758
|
var e = new Error('stream.unshift() after end event');
|
|
14357
14759
|
stream.emit('error', e);
|
|
14358
14760
|
} else {
|
|
14359
|
-
|
|
14761
|
+
var skipAdd;
|
|
14762
|
+
if (state.decoder && !addToFront && !encoding) {
|
|
14360
14763
|
chunk = state.decoder.write(chunk);
|
|
14764
|
+
skipAdd = !state.objectMode && chunk.length === 0;
|
|
14765
|
+
}
|
|
14361
14766
|
|
|
14362
|
-
if (!addToFront)
|
|
14363
|
-
state.reading = false;
|
|
14767
|
+
if (!addToFront) state.reading = false;
|
|
14364
14768
|
|
|
14365
|
-
// if we
|
|
14366
|
-
|
|
14367
|
-
|
|
14368
|
-
|
|
14369
|
-
|
|
14370
|
-
|
|
14371
|
-
|
|
14372
|
-
|
|
14373
|
-
|
|
14374
|
-
|
|
14375
|
-
state.buffer.push(chunk);
|
|
14376
|
-
|
|
14377
|
-
|
|
14378
|
-
|
|
14769
|
+
// Don't add to the buffer if we've decoded to an empty string chunk and
|
|
14770
|
+
// we're not in object mode
|
|
14771
|
+
if (!skipAdd) {
|
|
14772
|
+
// if we want the data now, just emit it.
|
|
14773
|
+
if (state.flowing && state.length === 0 && !state.sync) {
|
|
14774
|
+
stream.emit('data', chunk);
|
|
14775
|
+
stream.read(0);
|
|
14776
|
+
} else {
|
|
14777
|
+
// update the buffer info.
|
|
14778
|
+
state.length += state.objectMode ? 1 : chunk.length;
|
|
14779
|
+
if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
|
|
14780
|
+
|
|
14781
|
+
if (state.needReadable) emitReadable(stream);
|
|
14782
|
+
}
|
|
14379
14783
|
}
|
|
14380
14784
|
|
|
14381
14785
|
maybeReadMore(stream, state);
|
|
@@ -14387,7 +14791,6 @@ function readableAddChunk(stream, state, chunk, encoding, addToFront) {
|
|
|
14387
14791
|
return needMoreData(state);
|
|
14388
14792
|
}
|
|
14389
14793
|
|
|
14390
|
-
|
|
14391
14794
|
// if it's past the high water mark, we can push in some more.
|
|
14392
14795
|
// Also, if we have no data yet, we can stand some
|
|
14393
14796
|
// more bytes. This is to work around cases where hwm=0,
|
|
@@ -14396,16 +14799,12 @@ function readableAddChunk(stream, state, chunk, encoding, addToFront) {
|
|
|
14396
14799
|
// needReadable was set, then we ought to push more, so that another
|
|
14397
14800
|
// 'readable' event will be triggered.
|
|
14398
14801
|
function needMoreData(state) {
|
|
14399
|
-
return !state.ended &&
|
|
14400
|
-
(state.needReadable ||
|
|
14401
|
-
state.length < state.highWaterMark ||
|
|
14402
|
-
state.length === 0);
|
|
14802
|
+
return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
|
|
14403
14803
|
}
|
|
14404
14804
|
|
|
14405
14805
|
// backwards compatibility.
|
|
14406
|
-
Readable.prototype.setEncoding = function(enc) {
|
|
14407
|
-
if (!StringDecoder)
|
|
14408
|
-
StringDecoder = require('string_decoder/').StringDecoder;
|
|
14806
|
+
Readable.prototype.setEncoding = function (enc) {
|
|
14807
|
+
if (!StringDecoder) StringDecoder = _dereq_('string_decoder/').StringDecoder;
|
|
14409
14808
|
this._readableState.decoder = new StringDecoder(enc);
|
|
14410
14809
|
this._readableState.encoding = enc;
|
|
14411
14810
|
return this;
|
|
@@ -14430,29 +14829,22 @@ function computeNewHighWaterMark(n) {
|
|
|
14430
14829
|
}
|
|
14431
14830
|
|
|
14432
14831
|
function howMuchToRead(n, state) {
|
|
14433
|
-
if (state.length === 0 && state.ended)
|
|
14434
|
-
return 0;
|
|
14832
|
+
if (state.length === 0 && state.ended) return 0;
|
|
14435
14833
|
|
|
14436
|
-
if (state.objectMode)
|
|
14437
|
-
return n === 0 ? 0 : 1;
|
|
14834
|
+
if (state.objectMode) return n === 0 ? 0 : 1;
|
|
14438
14835
|
|
|
14439
14836
|
if (n === null || isNaN(n)) {
|
|
14440
14837
|
// only flow one buffer at a time
|
|
14441
|
-
if (state.flowing && state.buffer.length)
|
|
14442
|
-
return state.buffer[0].length;
|
|
14443
|
-
else
|
|
14444
|
-
return state.length;
|
|
14838
|
+
if (state.flowing && state.buffer.length) return state.buffer[0].length;else return state.length;
|
|
14445
14839
|
}
|
|
14446
14840
|
|
|
14447
|
-
if (n <= 0)
|
|
14448
|
-
return 0;
|
|
14841
|
+
if (n <= 0) return 0;
|
|
14449
14842
|
|
|
14450
14843
|
// If we're asking for more than the target buffer level,
|
|
14451
14844
|
// then raise the water mark. Bump up to the next highest
|
|
14452
14845
|
// power of 2, to prevent increasing it excessively in tiny
|
|
14453
14846
|
// amounts.
|
|
14454
|
-
if (n > state.highWaterMark)
|
|
14455
|
-
state.highWaterMark = computeNewHighWaterMark(n);
|
|
14847
|
+
if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
|
|
14456
14848
|
|
|
14457
14849
|
// don't have that much. return null, unless we've ended.
|
|
14458
14850
|
if (n > state.length) {
|
|
@@ -14468,25 +14860,19 @@ function howMuchToRead(n, state) {
|
|
|
14468
14860
|
}
|
|
14469
14861
|
|
|
14470
14862
|
// you can override either this method, or the async _read(n) below.
|
|
14471
|
-
Readable.prototype.read = function(n) {
|
|
14863
|
+
Readable.prototype.read = function (n) {
|
|
14472
14864
|
debug('read', n);
|
|
14473
14865
|
var state = this._readableState;
|
|
14474
14866
|
var nOrig = n;
|
|
14475
14867
|
|
|
14476
|
-
if (typeof n !== 'number' || n > 0)
|
|
14477
|
-
state.emittedReadable = false;
|
|
14868
|
+
if (typeof n !== 'number' || n > 0) state.emittedReadable = false;
|
|
14478
14869
|
|
|
14479
14870
|
// if we're doing read(0) to trigger a readable event, but we
|
|
14480
14871
|
// already have a bunch of data in the buffer, then just trigger
|
|
14481
14872
|
// the 'readable' event and move on.
|
|
14482
|
-
if (n === 0 &&
|
|
14483
|
-
state.needReadable &&
|
|
14484
|
-
(state.length >= state.highWaterMark || state.ended)) {
|
|
14873
|
+
if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
|
|
14485
14874
|
debug('read: emitReadable', state.length, state.ended);
|
|
14486
|
-
if (state.length === 0 && state.ended)
|
|
14487
|
-
endReadable(this);
|
|
14488
|
-
else
|
|
14489
|
-
emitReadable(this);
|
|
14875
|
+
if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
|
|
14490
14876
|
return null;
|
|
14491
14877
|
}
|
|
14492
14878
|
|
|
@@ -14494,8 +14880,7 @@ Readable.prototype.read = function(n) {
|
|
|
14494
14880
|
|
|
14495
14881
|
// if we've ended, and we're now clear, then finish it up.
|
|
14496
14882
|
if (n === 0 && state.ended) {
|
|
14497
|
-
if (state.length === 0)
|
|
14498
|
-
endReadable(this);
|
|
14883
|
+
if (state.length === 0) endReadable(this);
|
|
14499
14884
|
return null;
|
|
14500
14885
|
}
|
|
14501
14886
|
|
|
@@ -14543,8 +14928,7 @@ Readable.prototype.read = function(n) {
|
|
|
14543
14928
|
state.reading = true;
|
|
14544
14929
|
state.sync = true;
|
|
14545
14930
|
// if the length is currently zero, then we *need* a readable event.
|
|
14546
|
-
if (state.length === 0)
|
|
14547
|
-
state.needReadable = true;
|
|
14931
|
+
if (state.length === 0) state.needReadable = true;
|
|
14548
14932
|
// call internal read method
|
|
14549
14933
|
this._read(state.highWaterMark);
|
|
14550
14934
|
state.sync = false;
|
|
@@ -14552,14 +14936,10 @@ Readable.prototype.read = function(n) {
|
|
|
14552
14936
|
|
|
14553
14937
|
// If _read pushed data synchronously, then `reading` will be false,
|
|
14554
14938
|
// and we need to re-evaluate how much data we can return to the user.
|
|
14555
|
-
if (doRead && !state.reading)
|
|
14556
|
-
n = howMuchToRead(nOrig, state);
|
|
14939
|
+
if (doRead && !state.reading) n = howMuchToRead(nOrig, state);
|
|
14557
14940
|
|
|
14558
14941
|
var ret;
|
|
14559
|
-
if (n > 0)
|
|
14560
|
-
ret = fromList(n, state);
|
|
14561
|
-
else
|
|
14562
|
-
ret = null;
|
|
14942
|
+
if (n > 0) ret = fromList(n, state);else ret = null;
|
|
14563
14943
|
|
|
14564
14944
|
if (ret === null) {
|
|
14565
14945
|
state.needReadable = true;
|
|
@@ -14570,32 +14950,24 @@ Readable.prototype.read = function(n) {
|
|
|
14570
14950
|
|
|
14571
14951
|
// If we have nothing in the buffer, then we want to know
|
|
14572
14952
|
// as soon as we *do* get something into the buffer.
|
|
14573
|
-
if (state.length === 0 && !state.ended)
|
|
14574
|
-
state.needReadable = true;
|
|
14953
|
+
if (state.length === 0 && !state.ended) state.needReadable = true;
|
|
14575
14954
|
|
|
14576
14955
|
// If we tried to read() past the EOF, then emit end on the next tick.
|
|
14577
|
-
if (nOrig !== n && state.ended && state.length === 0)
|
|
14578
|
-
endReadable(this);
|
|
14956
|
+
if (nOrig !== n && state.ended && state.length === 0) endReadable(this);
|
|
14579
14957
|
|
|
14580
|
-
if (ret !== null)
|
|
14581
|
-
this.emit('data', ret);
|
|
14958
|
+
if (ret !== null) this.emit('data', ret);
|
|
14582
14959
|
|
|
14583
14960
|
return ret;
|
|
14584
14961
|
};
|
|
14585
14962
|
|
|
14586
14963
|
function chunkInvalid(state, chunk) {
|
|
14587
14964
|
var er = null;
|
|
14588
|
-
if (!
|
|
14589
|
-
typeof chunk !== 'string' &&
|
|
14590
|
-
chunk !== null &&
|
|
14591
|
-
chunk !== undefined &&
|
|
14592
|
-
!state.objectMode) {
|
|
14965
|
+
if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) {
|
|
14593
14966
|
er = new TypeError('Invalid non-string/buffer chunk');
|
|
14594
14967
|
}
|
|
14595
14968
|
return er;
|
|
14596
14969
|
}
|
|
14597
14970
|
|
|
14598
|
-
|
|
14599
14971
|
function onEofChunk(stream, state) {
|
|
14600
14972
|
if (state.ended) return;
|
|
14601
14973
|
if (state.decoder) {
|
|
@@ -14620,10 +14992,7 @@ function emitReadable(stream) {
|
|
|
14620
14992
|
if (!state.emittedReadable) {
|
|
14621
14993
|
debug('emitReadable', state.flowing);
|
|
14622
14994
|
state.emittedReadable = true;
|
|
14623
|
-
if (state.sync)
|
|
14624
|
-
processNextTick(emitReadable_, stream);
|
|
14625
|
-
else
|
|
14626
|
-
emitReadable_(stream);
|
|
14995
|
+
if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream);
|
|
14627
14996
|
}
|
|
14628
14997
|
}
|
|
14629
14998
|
|
|
@@ -14633,7 +15002,6 @@ function emitReadable_(stream) {
|
|
|
14633
15002
|
flow(stream);
|
|
14634
15003
|
}
|
|
14635
15004
|
|
|
14636
|
-
|
|
14637
15005
|
// at this point, the user has presumably seen the 'readable' event,
|
|
14638
15006
|
// and called read() to consume some data. that may have triggered
|
|
14639
15007
|
// in turn another _read(n) call, in which case reading = true if
|
|
@@ -14649,15 +15017,12 @@ function maybeReadMore(stream, state) {
|
|
|
14649
15017
|
|
|
14650
15018
|
function maybeReadMore_(stream, state) {
|
|
14651
15019
|
var len = state.length;
|
|
14652
|
-
while (!state.reading && !state.flowing && !state.ended &&
|
|
14653
|
-
state.length < state.highWaterMark) {
|
|
15020
|
+
while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
|
|
14654
15021
|
debug('maybeReadMore read 0');
|
|
14655
15022
|
stream.read(0);
|
|
14656
15023
|
if (len === state.length)
|
|
14657
15024
|
// didn't get any data, stop spinning.
|
|
14658
|
-
break;
|
|
14659
|
-
else
|
|
14660
|
-
len = state.length;
|
|
15025
|
+
break;else len = state.length;
|
|
14661
15026
|
}
|
|
14662
15027
|
state.readingMore = false;
|
|
14663
15028
|
}
|
|
@@ -14666,11 +15031,11 @@ function maybeReadMore_(stream, state) {
|
|
|
14666
15031
|
// call cb(er, data) where data is <= n in length.
|
|
14667
15032
|
// for virtual (non-string, non-buffer) streams, "length" is somewhat
|
|
14668
15033
|
// arbitrary, and perhaps not very meaningful.
|
|
14669
|
-
Readable.prototype._read = function(n) {
|
|
15034
|
+
Readable.prototype._read = function (n) {
|
|
14670
15035
|
this.emit('error', new Error('not implemented'));
|
|
14671
15036
|
};
|
|
14672
15037
|
|
|
14673
|
-
Readable.prototype.pipe = function(dest, pipeOpts) {
|
|
15038
|
+
Readable.prototype.pipe = function (dest, pipeOpts) {
|
|
14674
15039
|
var src = this;
|
|
14675
15040
|
var state = this._readableState;
|
|
14676
15041
|
|
|
@@ -14688,15 +15053,10 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
|
|
|
14688
15053
|
state.pipesCount += 1;
|
|
14689
15054
|
debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
|
|
14690
15055
|
|
|
14691
|
-
var doEnd = (!pipeOpts || pipeOpts.end !== false) &&
|
|
14692
|
-
dest !== process.stdout &&
|
|
14693
|
-
dest !== process.stderr;
|
|
15056
|
+
var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
|
|
14694
15057
|
|
|
14695
15058
|
var endFn = doEnd ? onend : cleanup;
|
|
14696
|
-
if (state.endEmitted)
|
|
14697
|
-
processNextTick(endFn);
|
|
14698
|
-
else
|
|
14699
|
-
src.once('end', endFn);
|
|
15059
|
+
if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn);
|
|
14700
15060
|
|
|
14701
15061
|
dest.on('unpipe', onunpipe);
|
|
14702
15062
|
function onunpipe(readable) {
|
|
@@ -14738,9 +15098,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
|
|
|
14738
15098
|
// flowing again.
|
|
14739
15099
|
// So, if this is awaiting a drain, then we just call it now.
|
|
14740
15100
|
// If we don't know, then assume that we are waiting for one.
|
|
14741
|
-
if (state.awaitDrain &&
|
|
14742
|
-
(!dest._writableState || dest._writableState.needDrain))
|
|
14743
|
-
ondrain();
|
|
15101
|
+
if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
|
|
14744
15102
|
}
|
|
14745
15103
|
|
|
14746
15104
|
src.on('data', ondata);
|
|
@@ -14751,10 +15109,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
|
|
|
14751
15109
|
// If the user unpiped during `dest.write()`, it is possible
|
|
14752
15110
|
// to get stuck in a permanently paused state if that write
|
|
14753
15111
|
// also returned false.
|
|
14754
|
-
if (state.pipesCount === 1 &&
|
|
14755
|
-
state.pipes[0] === dest &&
|
|
14756
|
-
src.listenerCount('data') === 1 &&
|
|
14757
|
-
!cleanedUp) {
|
|
15112
|
+
if (state.pipesCount === 1 && state.pipes[0] === dest && src.listenerCount('data') === 1 && !cleanedUp) {
|
|
14758
15113
|
debug('false write response, pause', src._readableState.awaitDrain);
|
|
14759
15114
|
src._readableState.awaitDrain++;
|
|
14760
15115
|
}
|
|
@@ -14768,18 +15123,11 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
|
|
|
14768
15123
|
debug('onerror', er);
|
|
14769
15124
|
unpipe();
|
|
14770
15125
|
dest.removeListener('error', onerror);
|
|
14771
|
-
if (EElistenerCount(dest, 'error') === 0)
|
|
14772
|
-
dest.emit('error', er);
|
|
15126
|
+
if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
|
|
14773
15127
|
}
|
|
14774
15128
|
// This is a brutally ugly hack to make sure that our error handler
|
|
14775
15129
|
// is attached before any userland ones. NEVER DO THIS.
|
|
14776
|
-
if (!dest._events || !dest._events.error)
|
|
14777
|
-
dest.on('error', onerror);
|
|
14778
|
-
else if (isArray(dest._events.error))
|
|
14779
|
-
dest._events.error.unshift(onerror);
|
|
14780
|
-
else
|
|
14781
|
-
dest._events.error = [onerror, dest._events.error];
|
|
14782
|
-
|
|
15130
|
+
if (!dest._events || !dest._events.error) dest.on('error', onerror);else if (isArray(dest._events.error)) dest._events.error.unshift(onerror);else dest._events.error = [onerror, dest._events.error];
|
|
14783
15131
|
|
|
14784
15132
|
// Both close and finish should trigger unpipe, but only once.
|
|
14785
15133
|
function onclose() {
|
|
@@ -14812,11 +15160,10 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
|
|
|
14812
15160
|
};
|
|
14813
15161
|
|
|
14814
15162
|
function pipeOnDrain(src) {
|
|
14815
|
-
return function() {
|
|
15163
|
+
return function () {
|
|
14816
15164
|
var state = src._readableState;
|
|
14817
15165
|
debug('pipeOnDrain', state.awaitDrain);
|
|
14818
|
-
if (state.awaitDrain)
|
|
14819
|
-
state.awaitDrain--;
|
|
15166
|
+
if (state.awaitDrain) state.awaitDrain--;
|
|
14820
15167
|
if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
|
|
14821
15168
|
state.flowing = true;
|
|
14822
15169
|
flow(src);
|
|
@@ -14824,29 +15171,24 @@ function pipeOnDrain(src) {
|
|
|
14824
15171
|
};
|
|
14825
15172
|
}
|
|
14826
15173
|
|
|
14827
|
-
|
|
14828
|
-
Readable.prototype.unpipe = function(dest) {
|
|
15174
|
+
Readable.prototype.unpipe = function (dest) {
|
|
14829
15175
|
var state = this._readableState;
|
|
14830
15176
|
|
|
14831
15177
|
// if we're not piping anywhere, then do nothing.
|
|
14832
|
-
if (state.pipesCount === 0)
|
|
14833
|
-
return this;
|
|
15178
|
+
if (state.pipesCount === 0) return this;
|
|
14834
15179
|
|
|
14835
15180
|
// just one destination. most common case.
|
|
14836
15181
|
if (state.pipesCount === 1) {
|
|
14837
15182
|
// passed in one, but it's not the right one.
|
|
14838
|
-
if (dest && dest !== state.pipes)
|
|
14839
|
-
return this;
|
|
15183
|
+
if (dest && dest !== state.pipes) return this;
|
|
14840
15184
|
|
|
14841
|
-
if (!dest)
|
|
14842
|
-
dest = state.pipes;
|
|
15185
|
+
if (!dest) dest = state.pipes;
|
|
14843
15186
|
|
|
14844
15187
|
// got a match.
|
|
14845
15188
|
state.pipes = null;
|
|
14846
15189
|
state.pipesCount = 0;
|
|
14847
15190
|
state.flowing = false;
|
|
14848
|
-
if (dest)
|
|
14849
|
-
dest.emit('unpipe', this);
|
|
15191
|
+
if (dest) dest.emit('unpipe', this);
|
|
14850
15192
|
return this;
|
|
14851
15193
|
}
|
|
14852
15194
|
|
|
@@ -14860,20 +15202,18 @@ Readable.prototype.unpipe = function(dest) {
|
|
|
14860
15202
|
state.pipesCount = 0;
|
|
14861
15203
|
state.flowing = false;
|
|
14862
15204
|
|
|
14863
|
-
for (var
|
|
14864
|
-
dests[
|
|
14865
|
-
return this;
|
|
15205
|
+
for (var _i = 0; _i < len; _i++) {
|
|
15206
|
+
dests[_i].emit('unpipe', this);
|
|
15207
|
+
}return this;
|
|
14866
15208
|
}
|
|
14867
15209
|
|
|
14868
15210
|
// try to find the right one.
|
|
14869
15211
|
var i = indexOf(state.pipes, dest);
|
|
14870
|
-
if (i === -1)
|
|
14871
|
-
return this;
|
|
15212
|
+
if (i === -1) return this;
|
|
14872
15213
|
|
|
14873
15214
|
state.pipes.splice(i, 1);
|
|
14874
15215
|
state.pipesCount -= 1;
|
|
14875
|
-
if (state.pipesCount === 1)
|
|
14876
|
-
state.pipes = state.pipes[0];
|
|
15216
|
+
if (state.pipesCount === 1) state.pipes = state.pipes[0];
|
|
14877
15217
|
|
|
14878
15218
|
dest.emit('unpipe', this);
|
|
14879
15219
|
|
|
@@ -14882,7 +15222,7 @@ Readable.prototype.unpipe = function(dest) {
|
|
|
14882
15222
|
|
|
14883
15223
|
// set up data events if they are asked for
|
|
14884
15224
|
// Ensure readable listeners eventually get something
|
|
14885
|
-
Readable.prototype.on = function(ev, fn) {
|
|
15225
|
+
Readable.prototype.on = function (ev, fn) {
|
|
14886
15226
|
var res = Stream.prototype.on.call(this, ev, fn);
|
|
14887
15227
|
|
|
14888
15228
|
// If listening to data, and it has not explicitly been paused,
|
|
@@ -14891,7 +15231,7 @@ Readable.prototype.on = function(ev, fn) {
|
|
|
14891
15231
|
this.resume();
|
|
14892
15232
|
}
|
|
14893
15233
|
|
|
14894
|
-
if (ev === 'readable' && this.
|
|
15234
|
+
if (ev === 'readable' && !this._readableState.endEmitted) {
|
|
14895
15235
|
var state = this._readableState;
|
|
14896
15236
|
if (!state.readableListening) {
|
|
14897
15237
|
state.readableListening = true;
|
|
@@ -14916,7 +15256,7 @@ function nReadingNextTick(self) {
|
|
|
14916
15256
|
|
|
14917
15257
|
// pause() and resume() are remnants of the legacy readable stream API
|
|
14918
15258
|
// If the user uses them, then switch into old mode.
|
|
14919
|
-
Readable.prototype.resume = function() {
|
|
15259
|
+
Readable.prototype.resume = function () {
|
|
14920
15260
|
var state = this._readableState;
|
|
14921
15261
|
if (!state.flowing) {
|
|
14922
15262
|
debug('resume');
|
|
@@ -14942,11 +15282,10 @@ function resume_(stream, state) {
|
|
|
14942
15282
|
state.resumeScheduled = false;
|
|
14943
15283
|
stream.emit('resume');
|
|
14944
15284
|
flow(stream);
|
|
14945
|
-
if (state.flowing && !state.reading)
|
|
14946
|
-
stream.read(0);
|
|
15285
|
+
if (state.flowing && !state.reading) stream.read(0);
|
|
14947
15286
|
}
|
|
14948
15287
|
|
|
14949
|
-
Readable.prototype.pause = function() {
|
|
15288
|
+
Readable.prototype.pause = function () {
|
|
14950
15289
|
debug('call pause flowing=%j', this._readableState.flowing);
|
|
14951
15290
|
if (false !== this._readableState.flowing) {
|
|
14952
15291
|
debug('pause');
|
|
@@ -14969,32 +15308,27 @@ function flow(stream) {
|
|
|
14969
15308
|
// wrap an old-style stream as the async data source.
|
|
14970
15309
|
// This is *not* part of the readable stream interface.
|
|
14971
15310
|
// It is an ugly unfortunate mess of history.
|
|
14972
|
-
Readable.prototype.wrap = function(stream) {
|
|
15311
|
+
Readable.prototype.wrap = function (stream) {
|
|
14973
15312
|
var state = this._readableState;
|
|
14974
15313
|
var paused = false;
|
|
14975
15314
|
|
|
14976
15315
|
var self = this;
|
|
14977
|
-
stream.on('end', function() {
|
|
15316
|
+
stream.on('end', function () {
|
|
14978
15317
|
debug('wrapped end');
|
|
14979
15318
|
if (state.decoder && !state.ended) {
|
|
14980
15319
|
var chunk = state.decoder.end();
|
|
14981
|
-
if (chunk && chunk.length)
|
|
14982
|
-
self.push(chunk);
|
|
15320
|
+
if (chunk && chunk.length) self.push(chunk);
|
|
14983
15321
|
}
|
|
14984
15322
|
|
|
14985
15323
|
self.push(null);
|
|
14986
15324
|
});
|
|
14987
15325
|
|
|
14988
|
-
stream.on('data', function(chunk) {
|
|
15326
|
+
stream.on('data', function (chunk) {
|
|
14989
15327
|
debug('wrapped data');
|
|
14990
|
-
if (state.decoder)
|
|
14991
|
-
chunk = state.decoder.write(chunk);
|
|
15328
|
+
if (state.decoder) chunk = state.decoder.write(chunk);
|
|
14992
15329
|
|
|
14993
15330
|
// don't skip over falsy values in objectMode
|
|
14994
|
-
if (state.objectMode && (chunk === null || chunk === undefined))
|
|
14995
|
-
return;
|
|
14996
|
-
else if (!state.objectMode && (!chunk || !chunk.length))
|
|
14997
|
-
return;
|
|
15331
|
+
if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
|
|
14998
15332
|
|
|
14999
15333
|
var ret = self.push(chunk);
|
|
15000
15334
|
if (!ret) {
|
|
@@ -15007,21 +15341,23 @@ Readable.prototype.wrap = function(stream) {
|
|
|
15007
15341
|
// important when wrapping filters and duplexes.
|
|
15008
15342
|
for (var i in stream) {
|
|
15009
15343
|
if (this[i] === undefined && typeof stream[i] === 'function') {
|
|
15010
|
-
this[i] = function(method) {
|
|
15011
|
-
return
|
|
15012
|
-
|
|
15344
|
+
this[i] = function (method) {
|
|
15345
|
+
return function () {
|
|
15346
|
+
return stream[method].apply(stream, arguments);
|
|
15347
|
+
};
|
|
15348
|
+
}(i);
|
|
15013
15349
|
}
|
|
15014
15350
|
}
|
|
15015
15351
|
|
|
15016
15352
|
// proxy certain important events.
|
|
15017
15353
|
var events = ['error', 'close', 'destroy', 'pause', 'resume'];
|
|
15018
|
-
forEach(events, function(ev) {
|
|
15354
|
+
forEach(events, function (ev) {
|
|
15019
15355
|
stream.on(ev, self.emit.bind(self, ev));
|
|
15020
15356
|
});
|
|
15021
15357
|
|
|
15022
15358
|
// when we try to consume some more bytes, simply unpause the
|
|
15023
15359
|
// underlying stream.
|
|
15024
|
-
self._read = function(n) {
|
|
15360
|
+
self._read = function (n) {
|
|
15025
15361
|
debug('wrapped _read', n);
|
|
15026
15362
|
if (paused) {
|
|
15027
15363
|
paused = false;
|
|
@@ -15032,7 +15368,6 @@ Readable.prototype.wrap = function(stream) {
|
|
|
15032
15368
|
return self;
|
|
15033
15369
|
};
|
|
15034
15370
|
|
|
15035
|
-
|
|
15036
15371
|
// exposed for testing purposes only.
|
|
15037
15372
|
Readable._fromList = fromList;
|
|
15038
15373
|
|
|
@@ -15046,21 +15381,11 @@ function fromList(n, state) {
|
|
|
15046
15381
|
var ret;
|
|
15047
15382
|
|
|
15048
15383
|
// nothing in the list, definitely empty.
|
|
15049
|
-
if (list.length === 0)
|
|
15050
|
-
return null;
|
|
15384
|
+
if (list.length === 0) return null;
|
|
15051
15385
|
|
|
15052
|
-
if (length === 0)
|
|
15053
|
-
ret = null;
|
|
15054
|
-
else if (objectMode)
|
|
15055
|
-
ret = list.shift();
|
|
15056
|
-
else if (!n || n >= length) {
|
|
15386
|
+
if (length === 0) ret = null;else if (objectMode) ret = list.shift();else if (!n || n >= length) {
|
|
15057
15387
|
// read it all, truncate the array.
|
|
15058
|
-
if (stringMode)
|
|
15059
|
-
ret = list.join('');
|
|
15060
|
-
else if (list.length === 1)
|
|
15061
|
-
ret = list[0];
|
|
15062
|
-
else
|
|
15063
|
-
ret = Buffer.concat(list, length);
|
|
15388
|
+
if (stringMode) ret = list.join('');else if (list.length === 1) ret = list[0];else ret = Buffer.concat(list, length);
|
|
15064
15389
|
list.length = 0;
|
|
15065
15390
|
} else {
|
|
15066
15391
|
// read just some of it.
|
|
@@ -15076,25 +15401,16 @@ function fromList(n, state) {
|
|
|
15076
15401
|
} else {
|
|
15077
15402
|
// complex case.
|
|
15078
15403
|
// we have enough to cover it, but it spans past the first buffer.
|
|
15079
|
-
if (stringMode)
|
|
15080
|
-
ret = '';
|
|
15081
|
-
else
|
|
15082
|
-
ret = new Buffer(n);
|
|
15404
|
+
if (stringMode) ret = '';else ret = new Buffer(n);
|
|
15083
15405
|
|
|
15084
15406
|
var c = 0;
|
|
15085
15407
|
for (var i = 0, l = list.length; i < l && c < n; i++) {
|
|
15086
15408
|
var buf = list[0];
|
|
15087
15409
|
var cpy = Math.min(n - c, buf.length);
|
|
15088
15410
|
|
|
15089
|
-
if (stringMode)
|
|
15090
|
-
ret += buf.slice(0, cpy);
|
|
15091
|
-
else
|
|
15092
|
-
buf.copy(ret, c, 0, cpy);
|
|
15411
|
+
if (stringMode) ret += buf.slice(0, cpy);else buf.copy(ret, c, 0, cpy);
|
|
15093
15412
|
|
|
15094
|
-
if (cpy < buf.length)
|
|
15095
|
-
list[0] = buf.slice(cpy);
|
|
15096
|
-
else
|
|
15097
|
-
list.shift();
|
|
15413
|
+
if (cpy < buf.length) list[0] = buf.slice(cpy);else list.shift();
|
|
15098
15414
|
|
|
15099
15415
|
c += cpy;
|
|
15100
15416
|
}
|
|
@@ -15109,8 +15425,7 @@ function endReadable(stream) {
|
|
|
15109
15425
|
|
|
15110
15426
|
// If we get here before consuming all the bytes, then that is a
|
|
15111
15427
|
// bug in node. Should never happen.
|
|
15112
|
-
if (state.length > 0)
|
|
15113
|
-
throw new Error('endReadable called on non-empty stream');
|
|
15428
|
+
if (state.length > 0) throw new Error('endReadable called on non-empty stream');
|
|
15114
15429
|
|
|
15115
15430
|
if (!state.endEmitted) {
|
|
15116
15431
|
state.ended = true;
|
|
@@ -15127,21 +15442,20 @@ function endReadableNT(state, stream) {
|
|
|
15127
15442
|
}
|
|
15128
15443
|
}
|
|
15129
15444
|
|
|
15130
|
-
function forEach
|
|
15445
|
+
function forEach(xs, f) {
|
|
15131
15446
|
for (var i = 0, l = xs.length; i < l; i++) {
|
|
15132
15447
|
f(xs[i], i);
|
|
15133
15448
|
}
|
|
15134
15449
|
}
|
|
15135
15450
|
|
|
15136
|
-
function indexOf
|
|
15451
|
+
function indexOf(xs, x) {
|
|
15137
15452
|
for (var i = 0, l = xs.length; i < l; i++) {
|
|
15138
15453
|
if (xs[i] === x) return i;
|
|
15139
15454
|
}
|
|
15140
15455
|
return -1;
|
|
15141
15456
|
}
|
|
15142
|
-
|
|
15143
|
-
}
|
|
15144
|
-
},{"./_stream_duplex":70,"_process":62,"buffer":43,"core-util-is":46,"events":49,"inherits":52,"isarray":54,"process-nextick-args":61,"string_decoder/":83,"util":41}],73:[function(require,module,exports){
|
|
15457
|
+
}).call(this,_dereq_('_process'))
|
|
15458
|
+
},{"./_stream_duplex":75,"_process":66,"buffer":48,"core-util-is":51,"events":54,"inherits":57,"isarray":73,"process-nextick-args":65,"string_decoder/":88,"util":46}],78:[function(_dereq_,module,exports){
|
|
15145
15459
|
// a transform stream is a readable/writable stream where you do
|
|
15146
15460
|
// something with the data. Sometimes it's called a "filter",
|
|
15147
15461
|
// but that's not a great name for it, since that implies a thing where
|
|
@@ -15188,18 +15502,17 @@ function indexOf (xs, x) {
|
|
|
15188
15502
|
|
|
15189
15503
|
module.exports = Transform;
|
|
15190
15504
|
|
|
15191
|
-
var Duplex =
|
|
15505
|
+
var Duplex = _dereq_('./_stream_duplex');
|
|
15192
15506
|
|
|
15193
15507
|
/*<replacement>*/
|
|
15194
|
-
var util =
|
|
15195
|
-
util.inherits =
|
|
15508
|
+
var util = _dereq_('core-util-is');
|
|
15509
|
+
util.inherits = _dereq_('inherits');
|
|
15196
15510
|
/*</replacement>*/
|
|
15197
15511
|
|
|
15198
15512
|
util.inherits(Transform, Duplex);
|
|
15199
15513
|
|
|
15200
|
-
|
|
15201
15514
|
function TransformState(stream) {
|
|
15202
|
-
this.afterTransform = function(er, data) {
|
|
15515
|
+
this.afterTransform = function (er, data) {
|
|
15203
15516
|
return afterTransform(stream, er, data);
|
|
15204
15517
|
};
|
|
15205
15518
|
|
|
@@ -15207,6 +15520,7 @@ function TransformState(stream) {
|
|
|
15207
15520
|
this.transforming = false;
|
|
15208
15521
|
this.writecb = null;
|
|
15209
15522
|
this.writechunk = null;
|
|
15523
|
+
this.writeencoding = null;
|
|
15210
15524
|
}
|
|
15211
15525
|
|
|
15212
15526
|
function afterTransform(stream, er, data) {
|
|
@@ -15215,17 +15529,14 @@ function afterTransform(stream, er, data) {
|
|
|
15215
15529
|
|
|
15216
15530
|
var cb = ts.writecb;
|
|
15217
15531
|
|
|
15218
|
-
if (!cb)
|
|
15219
|
-
return stream.emit('error', new Error('no writecb in Transform class'));
|
|
15532
|
+
if (!cb) return stream.emit('error', new Error('no writecb in Transform class'));
|
|
15220
15533
|
|
|
15221
15534
|
ts.writechunk = null;
|
|
15222
15535
|
ts.writecb = null;
|
|
15223
15536
|
|
|
15224
|
-
if (data !== null && data !== undefined)
|
|
15225
|
-
stream.push(data);
|
|
15537
|
+
if (data !== null && data !== undefined) stream.push(data);
|
|
15226
15538
|
|
|
15227
|
-
|
|
15228
|
-
cb(er);
|
|
15539
|
+
cb(er);
|
|
15229
15540
|
|
|
15230
15541
|
var rs = stream._readableState;
|
|
15231
15542
|
rs.reading = false;
|
|
@@ -15234,10 +15545,8 @@ function afterTransform(stream, er, data) {
|
|
|
15234
15545
|
}
|
|
15235
15546
|
}
|
|
15236
15547
|
|
|
15237
|
-
|
|
15238
15548
|
function Transform(options) {
|
|
15239
|
-
if (!(this instanceof Transform))
|
|
15240
|
-
return new Transform(options);
|
|
15549
|
+
if (!(this instanceof Transform)) return new Transform(options);
|
|
15241
15550
|
|
|
15242
15551
|
Duplex.call(this, options);
|
|
15243
15552
|
|
|
@@ -15255,24 +15564,19 @@ function Transform(options) {
|
|
|
15255
15564
|
this._readableState.sync = false;
|
|
15256
15565
|
|
|
15257
15566
|
if (options) {
|
|
15258
|
-
if (typeof options.transform === 'function')
|
|
15259
|
-
this._transform = options.transform;
|
|
15567
|
+
if (typeof options.transform === 'function') this._transform = options.transform;
|
|
15260
15568
|
|
|
15261
|
-
if (typeof options.flush === 'function')
|
|
15262
|
-
this._flush = options.flush;
|
|
15569
|
+
if (typeof options.flush === 'function') this._flush = options.flush;
|
|
15263
15570
|
}
|
|
15264
15571
|
|
|
15265
|
-
this.once('prefinish', function() {
|
|
15266
|
-
if (typeof this._flush === 'function')
|
|
15267
|
-
|
|
15268
|
-
|
|
15269
|
-
});
|
|
15270
|
-
else
|
|
15271
|
-
done(stream);
|
|
15572
|
+
this.once('prefinish', function () {
|
|
15573
|
+
if (typeof this._flush === 'function') this._flush(function (er) {
|
|
15574
|
+
done(stream, er);
|
|
15575
|
+
});else done(stream);
|
|
15272
15576
|
});
|
|
15273
15577
|
}
|
|
15274
15578
|
|
|
15275
|
-
Transform.prototype.push = function(chunk, encoding) {
|
|
15579
|
+
Transform.prototype.push = function (chunk, encoding) {
|
|
15276
15580
|
this._transformState.needTransform = false;
|
|
15277
15581
|
return Duplex.prototype.push.call(this, chunk, encoding);
|
|
15278
15582
|
};
|
|
@@ -15287,28 +15591,25 @@ Transform.prototype.push = function(chunk, encoding) {
|
|
|
15287
15591
|
// Call `cb(err)` when you are done with this chunk. If you pass
|
|
15288
15592
|
// an error, then that'll put the hurt on the whole operation. If you
|
|
15289
15593
|
// never call cb(), then you'll never get another chunk.
|
|
15290
|
-
Transform.prototype._transform = function(chunk, encoding, cb) {
|
|
15594
|
+
Transform.prototype._transform = function (chunk, encoding, cb) {
|
|
15291
15595
|
throw new Error('not implemented');
|
|
15292
15596
|
};
|
|
15293
15597
|
|
|
15294
|
-
Transform.prototype._write = function(chunk, encoding, cb) {
|
|
15598
|
+
Transform.prototype._write = function (chunk, encoding, cb) {
|
|
15295
15599
|
var ts = this._transformState;
|
|
15296
15600
|
ts.writecb = cb;
|
|
15297
15601
|
ts.writechunk = chunk;
|
|
15298
15602
|
ts.writeencoding = encoding;
|
|
15299
15603
|
if (!ts.transforming) {
|
|
15300
15604
|
var rs = this._readableState;
|
|
15301
|
-
if (ts.needTransform ||
|
|
15302
|
-
rs.needReadable ||
|
|
15303
|
-
rs.length < rs.highWaterMark)
|
|
15304
|
-
this._read(rs.highWaterMark);
|
|
15605
|
+
if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
|
|
15305
15606
|
}
|
|
15306
15607
|
};
|
|
15307
15608
|
|
|
15308
15609
|
// Doesn't matter what the args are here.
|
|
15309
15610
|
// _transform does all the work.
|
|
15310
15611
|
// That we got here means that the readable side wants more data.
|
|
15311
|
-
Transform.prototype._read = function(n) {
|
|
15612
|
+
Transform.prototype._read = function (n) {
|
|
15312
15613
|
var ts = this._transformState;
|
|
15313
15614
|
|
|
15314
15615
|
if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
|
|
@@ -15321,26 +15622,22 @@ Transform.prototype._read = function(n) {
|
|
|
15321
15622
|
}
|
|
15322
15623
|
};
|
|
15323
15624
|
|
|
15324
|
-
|
|
15325
15625
|
function done(stream, er) {
|
|
15326
|
-
if (er)
|
|
15327
|
-
return stream.emit('error', er);
|
|
15626
|
+
if (er) return stream.emit('error', er);
|
|
15328
15627
|
|
|
15329
15628
|
// if there's nothing in the write buffer, then that means
|
|
15330
15629
|
// that nothing more will ever be provided
|
|
15331
15630
|
var ws = stream._writableState;
|
|
15332
15631
|
var ts = stream._transformState;
|
|
15333
15632
|
|
|
15334
|
-
if (ws.length)
|
|
15335
|
-
throw new Error('calling transform done when ws.length != 0');
|
|
15633
|
+
if (ws.length) throw new Error('calling transform done when ws.length != 0');
|
|
15336
15634
|
|
|
15337
|
-
if (ts.transforming)
|
|
15338
|
-
throw new Error('calling transform done when still transforming');
|
|
15635
|
+
if (ts.transforming) throw new Error('calling transform done when still transforming');
|
|
15339
15636
|
|
|
15340
15637
|
return stream.push(null);
|
|
15341
15638
|
}
|
|
15342
|
-
|
|
15343
|
-
|
|
15639
|
+
},{"./_stream_duplex":75,"core-util-is":51,"inherits":57}],79:[function(_dereq_,module,exports){
|
|
15640
|
+
(function (process){
|
|
15344
15641
|
// A bit simpler than readable streams.
|
|
15345
15642
|
// Implement an async ._write(chunk, encoding, cb), and it'll handle all
|
|
15346
15643
|
// the drain event emission and buffering.
|
|
@@ -15350,42 +15647,42 @@ function done(stream, er) {
|
|
|
15350
15647
|
module.exports = Writable;
|
|
15351
15648
|
|
|
15352
15649
|
/*<replacement>*/
|
|
15353
|
-
var processNextTick =
|
|
15650
|
+
var processNextTick = _dereq_('process-nextick-args');
|
|
15354
15651
|
/*</replacement>*/
|
|
15355
15652
|
|
|
15653
|
+
/*<replacement>*/
|
|
15654
|
+
var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick;
|
|
15655
|
+
/*</replacement>*/
|
|
15356
15656
|
|
|
15357
15657
|
/*<replacement>*/
|
|
15358
|
-
var Buffer =
|
|
15658
|
+
var Buffer = _dereq_('buffer').Buffer;
|
|
15359
15659
|
/*</replacement>*/
|
|
15360
15660
|
|
|
15361
15661
|
Writable.WritableState = WritableState;
|
|
15362
15662
|
|
|
15363
|
-
|
|
15364
15663
|
/*<replacement>*/
|
|
15365
|
-
var util =
|
|
15366
|
-
util.inherits =
|
|
15664
|
+
var util = _dereq_('core-util-is');
|
|
15665
|
+
util.inherits = _dereq_('inherits');
|
|
15367
15666
|
/*</replacement>*/
|
|
15368
15667
|
|
|
15369
|
-
|
|
15370
15668
|
/*<replacement>*/
|
|
15371
15669
|
var internalUtil = {
|
|
15372
|
-
deprecate:
|
|
15670
|
+
deprecate: _dereq_('util-deprecate')
|
|
15373
15671
|
};
|
|
15374
15672
|
/*</replacement>*/
|
|
15375
15673
|
|
|
15376
|
-
|
|
15377
|
-
|
|
15378
15674
|
/*<replacement>*/
|
|
15379
15675
|
var Stream;
|
|
15380
|
-
(function (){
|
|
15381
|
-
|
|
15382
|
-
|
|
15383
|
-
|
|
15384
|
-
Stream =
|
|
15385
|
-
}
|
|
15676
|
+
(function () {
|
|
15677
|
+
try {
|
|
15678
|
+
Stream = _dereq_('st' + 'ream');
|
|
15679
|
+
} catch (_) {} finally {
|
|
15680
|
+
if (!Stream) Stream = _dereq_('events').EventEmitter;
|
|
15681
|
+
}
|
|
15682
|
+
})();
|
|
15386
15683
|
/*</replacement>*/
|
|
15387
15684
|
|
|
15388
|
-
var Buffer =
|
|
15685
|
+
var Buffer = _dereq_('buffer').Buffer;
|
|
15389
15686
|
|
|
15390
15687
|
util.inherits(Writable, Stream);
|
|
15391
15688
|
|
|
@@ -15400,7 +15697,7 @@ function WriteReq(chunk, encoding, cb) {
|
|
|
15400
15697
|
|
|
15401
15698
|
var Duplex;
|
|
15402
15699
|
function WritableState(options, stream) {
|
|
15403
|
-
Duplex = Duplex ||
|
|
15700
|
+
Duplex = Duplex || _dereq_('./_stream_duplex');
|
|
15404
15701
|
|
|
15405
15702
|
options = options || {};
|
|
15406
15703
|
|
|
@@ -15408,18 +15705,17 @@ function WritableState(options, stream) {
|
|
|
15408
15705
|
// contains buffers or objects.
|
|
15409
15706
|
this.objectMode = !!options.objectMode;
|
|
15410
15707
|
|
|
15411
|
-
if (stream instanceof Duplex)
|
|
15412
|
-
this.objectMode = this.objectMode || !!options.writableObjectMode;
|
|
15708
|
+
if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
|
|
15413
15709
|
|
|
15414
15710
|
// the point at which write() starts returning false
|
|
15415
15711
|
// Note: 0 is a valid value, means that we always return false if
|
|
15416
15712
|
// the entire buffer is not flushed immediately on write()
|
|
15417
15713
|
var hwm = options.highWaterMark;
|
|
15418
15714
|
var defaultHwm = this.objectMode ? 16 : 16 * 1024;
|
|
15419
|
-
this.highWaterMark =
|
|
15715
|
+
this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
|
|
15420
15716
|
|
|
15421
15717
|
// cast to ints.
|
|
15422
|
-
this.highWaterMark =
|
|
15718
|
+
this.highWaterMark = ~ ~this.highWaterMark;
|
|
15423
15719
|
|
|
15424
15720
|
this.needDrain = false;
|
|
15425
15721
|
// at the start of calling end()
|
|
@@ -15463,7 +15759,7 @@ function WritableState(options, stream) {
|
|
|
15463
15759
|
this.bufferProcessing = false;
|
|
15464
15760
|
|
|
15465
15761
|
// the callback that's passed to _write(chunk,cb)
|
|
15466
|
-
this.onwrite = function(er) {
|
|
15762
|
+
this.onwrite = function (er) {
|
|
15467
15763
|
onwrite(stream, er);
|
|
15468
15764
|
};
|
|
15469
15765
|
|
|
@@ -15486,6 +15782,14 @@ function WritableState(options, stream) {
|
|
|
15486
15782
|
|
|
15487
15783
|
// True if the error was already emitted and should not be thrown again
|
|
15488
15784
|
this.errorEmitted = false;
|
|
15785
|
+
|
|
15786
|
+
// count buffered requests
|
|
15787
|
+
this.bufferedRequestCount = 0;
|
|
15788
|
+
|
|
15789
|
+
// create the two objects needed to store the corked requests
|
|
15790
|
+
// they are not a linked list, as no new elements are inserted in there
|
|
15791
|
+
this.corkedRequestsFree = new CorkedRequest(this);
|
|
15792
|
+
this.corkedRequestsFree.next = new CorkedRequest(this);
|
|
15489
15793
|
}
|
|
15490
15794
|
|
|
15491
15795
|
WritableState.prototype.getBuffer = function writableStateGetBuffer() {
|
|
@@ -15498,24 +15802,23 @@ WritableState.prototype.getBuffer = function writableStateGetBuffer() {
|
|
|
15498
15802
|
return out;
|
|
15499
15803
|
};
|
|
15500
15804
|
|
|
15501
|
-
(function ()
|
|
15502
|
-
|
|
15503
|
-
|
|
15504
|
-
|
|
15505
|
-
|
|
15506
|
-
|
|
15507
|
-
});
|
|
15508
|
-
}catch(_){}
|
|
15509
|
-
|
|
15805
|
+
(function () {
|
|
15806
|
+
try {
|
|
15807
|
+
Object.defineProperty(WritableState.prototype, 'buffer', {
|
|
15808
|
+
get: internalUtil.deprecate(function () {
|
|
15809
|
+
return this.getBuffer();
|
|
15810
|
+
}, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.')
|
|
15811
|
+
});
|
|
15812
|
+
} catch (_) {}
|
|
15813
|
+
})();
|
|
15510
15814
|
|
|
15511
15815
|
var Duplex;
|
|
15512
15816
|
function Writable(options) {
|
|
15513
|
-
Duplex = Duplex ||
|
|
15817
|
+
Duplex = Duplex || _dereq_('./_stream_duplex');
|
|
15514
15818
|
|
|
15515
15819
|
// Writable ctor is applied to Duplexes, though they're not
|
|
15516
15820
|
// instanceof Writable, they're instanceof Readable.
|
|
15517
|
-
if (!(this instanceof Writable) && !(this instanceof Duplex))
|
|
15518
|
-
return new Writable(options);
|
|
15821
|
+
if (!(this instanceof Writable) && !(this instanceof Duplex)) return new Writable(options);
|
|
15519
15822
|
|
|
15520
15823
|
this._writableState = new WritableState(options, this);
|
|
15521
15824
|
|
|
@@ -15523,22 +15826,19 @@ function Writable(options) {
|
|
|
15523
15826
|
this.writable = true;
|
|
15524
15827
|
|
|
15525
15828
|
if (options) {
|
|
15526
|
-
if (typeof options.write === 'function')
|
|
15527
|
-
this._write = options.write;
|
|
15829
|
+
if (typeof options.write === 'function') this._write = options.write;
|
|
15528
15830
|
|
|
15529
|
-
if (typeof options.writev === 'function')
|
|
15530
|
-
this._writev = options.writev;
|
|
15831
|
+
if (typeof options.writev === 'function') this._writev = options.writev;
|
|
15531
15832
|
}
|
|
15532
15833
|
|
|
15533
15834
|
Stream.call(this);
|
|
15534
15835
|
}
|
|
15535
15836
|
|
|
15536
15837
|
// Otherwise people can pipe Writable streams, which is just wrong.
|
|
15537
|
-
Writable.prototype.pipe = function() {
|
|
15838
|
+
Writable.prototype.pipe = function () {
|
|
15538
15839
|
this.emit('error', new Error('Cannot pipe. Not readable.'));
|
|
15539
15840
|
};
|
|
15540
15841
|
|
|
15541
|
-
|
|
15542
15842
|
function writeAfterEnd(stream, cb) {
|
|
15543
15843
|
var er = new Error('write after end');
|
|
15544
15844
|
// TODO: defer error events consistently everywhere, not just the cb
|
|
@@ -15554,11 +15854,7 @@ function writeAfterEnd(stream, cb) {
|
|
|
15554
15854
|
function validChunk(stream, state, chunk, cb) {
|
|
15555
15855
|
var valid = true;
|
|
15556
15856
|
|
|
15557
|
-
if (!
|
|
15558
|
-
typeof chunk !== 'string' &&
|
|
15559
|
-
chunk !== null &&
|
|
15560
|
-
chunk !== undefined &&
|
|
15561
|
-
!state.objectMode) {
|
|
15857
|
+
if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) {
|
|
15562
15858
|
var er = new TypeError('Invalid non-string/buffer chunk');
|
|
15563
15859
|
stream.emit('error', er);
|
|
15564
15860
|
processNextTick(cb, er);
|
|
@@ -15567,7 +15863,7 @@ function validChunk(stream, state, chunk, cb) {
|
|
|
15567
15863
|
return valid;
|
|
15568
15864
|
}
|
|
15569
15865
|
|
|
15570
|
-
Writable.prototype.write = function(chunk, encoding, cb) {
|
|
15866
|
+
Writable.prototype.write = function (chunk, encoding, cb) {
|
|
15571
15867
|
var state = this._writableState;
|
|
15572
15868
|
var ret = false;
|
|
15573
15869
|
|
|
@@ -15576,17 +15872,11 @@ Writable.prototype.write = function(chunk, encoding, cb) {
|
|
|
15576
15872
|
encoding = null;
|
|
15577
15873
|
}
|
|
15578
15874
|
|
|
15579
|
-
if (Buffer.isBuffer(chunk))
|
|
15580
|
-
encoding = 'buffer';
|
|
15581
|
-
else if (!encoding)
|
|
15582
|
-
encoding = state.defaultEncoding;
|
|
15875
|
+
if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
|
|
15583
15876
|
|
|
15584
|
-
if (typeof cb !== 'function')
|
|
15585
|
-
cb = nop;
|
|
15877
|
+
if (typeof cb !== 'function') cb = nop;
|
|
15586
15878
|
|
|
15587
|
-
if (state.ended)
|
|
15588
|
-
writeAfterEnd(this, cb);
|
|
15589
|
-
else if (validChunk(this, state, chunk, cb)) {
|
|
15879
|
+
if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) {
|
|
15590
15880
|
state.pendingcb++;
|
|
15591
15881
|
ret = writeOrBuffer(this, state, chunk, encoding, cb);
|
|
15592
15882
|
}
|
|
@@ -15594,42 +15884,31 @@ Writable.prototype.write = function(chunk, encoding, cb) {
|
|
|
15594
15884
|
return ret;
|
|
15595
15885
|
};
|
|
15596
15886
|
|
|
15597
|
-
Writable.prototype.cork = function() {
|
|
15887
|
+
Writable.prototype.cork = function () {
|
|
15598
15888
|
var state = this._writableState;
|
|
15599
15889
|
|
|
15600
15890
|
state.corked++;
|
|
15601
15891
|
};
|
|
15602
15892
|
|
|
15603
|
-
Writable.prototype.uncork = function() {
|
|
15893
|
+
Writable.prototype.uncork = function () {
|
|
15604
15894
|
var state = this._writableState;
|
|
15605
15895
|
|
|
15606
15896
|
if (state.corked) {
|
|
15607
15897
|
state.corked--;
|
|
15608
15898
|
|
|
15609
|
-
if (!state.writing &&
|
|
15610
|
-
!state.corked &&
|
|
15611
|
-
!state.finished &&
|
|
15612
|
-
!state.bufferProcessing &&
|
|
15613
|
-
state.bufferedRequest)
|
|
15614
|
-
clearBuffer(this, state);
|
|
15899
|
+
if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
|
|
15615
15900
|
}
|
|
15616
15901
|
};
|
|
15617
15902
|
|
|
15618
15903
|
Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
|
|
15619
15904
|
// node::ParseEncoding() requires lower case.
|
|
15620
|
-
if (typeof encoding === 'string')
|
|
15621
|
-
|
|
15622
|
-
if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64',
|
|
15623
|
-
'ucs2', 'ucs-2','utf16le', 'utf-16le', 'raw']
|
|
15624
|
-
.indexOf((encoding + '').toLowerCase()) > -1))
|
|
15625
|
-
throw new TypeError('Unknown encoding: ' + encoding);
|
|
15905
|
+
if (typeof encoding === 'string') encoding = encoding.toLowerCase();
|
|
15906
|
+
if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding);
|
|
15626
15907
|
this._writableState.defaultEncoding = encoding;
|
|
15627
15908
|
};
|
|
15628
15909
|
|
|
15629
15910
|
function decodeChunk(state, chunk, encoding) {
|
|
15630
|
-
if (!state.objectMode &&
|
|
15631
|
-
state.decodeStrings !== false &&
|
|
15632
|
-
typeof chunk === 'string') {
|
|
15911
|
+
if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
|
|
15633
15912
|
chunk = new Buffer(chunk, encoding);
|
|
15634
15913
|
}
|
|
15635
15914
|
return chunk;
|
|
@@ -15641,16 +15920,14 @@ function decodeChunk(state, chunk, encoding) {
|
|
|
15641
15920
|
function writeOrBuffer(stream, state, chunk, encoding, cb) {
|
|
15642
15921
|
chunk = decodeChunk(state, chunk, encoding);
|
|
15643
15922
|
|
|
15644
|
-
if (Buffer.isBuffer(chunk))
|
|
15645
|
-
encoding = 'buffer';
|
|
15923
|
+
if (Buffer.isBuffer(chunk)) encoding = 'buffer';
|
|
15646
15924
|
var len = state.objectMode ? 1 : chunk.length;
|
|
15647
15925
|
|
|
15648
15926
|
state.length += len;
|
|
15649
15927
|
|
|
15650
15928
|
var ret = state.length < state.highWaterMark;
|
|
15651
15929
|
// we must ensure that previous needDrain will not be reset to false.
|
|
15652
|
-
if (!ret)
|
|
15653
|
-
state.needDrain = true;
|
|
15930
|
+
if (!ret) state.needDrain = true;
|
|
15654
15931
|
|
|
15655
15932
|
if (state.writing || state.corked) {
|
|
15656
15933
|
var last = state.lastBufferedRequest;
|
|
@@ -15660,6 +15937,7 @@ function writeOrBuffer(stream, state, chunk, encoding, cb) {
|
|
|
15660
15937
|
} else {
|
|
15661
15938
|
state.bufferedRequest = state.lastBufferedRequest;
|
|
15662
15939
|
}
|
|
15940
|
+
state.bufferedRequestCount += 1;
|
|
15663
15941
|
} else {
|
|
15664
15942
|
doWrite(stream, state, false, len, chunk, encoding, cb);
|
|
15665
15943
|
}
|
|
@@ -15672,19 +15950,13 @@ function doWrite(stream, state, writev, len, chunk, encoding, cb) {
|
|
|
15672
15950
|
state.writecb = cb;
|
|
15673
15951
|
state.writing = true;
|
|
15674
15952
|
state.sync = true;
|
|
15675
|
-
if (writev)
|
|
15676
|
-
stream._writev(chunk, state.onwrite);
|
|
15677
|
-
else
|
|
15678
|
-
stream._write(chunk, encoding, state.onwrite);
|
|
15953
|
+
if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
|
|
15679
15954
|
state.sync = false;
|
|
15680
15955
|
}
|
|
15681
15956
|
|
|
15682
15957
|
function onwriteError(stream, state, sync, er, cb) {
|
|
15683
15958
|
--state.pendingcb;
|
|
15684
|
-
if (sync)
|
|
15685
|
-
processNextTick(cb, er);
|
|
15686
|
-
else
|
|
15687
|
-
cb(er);
|
|
15959
|
+
if (sync) processNextTick(cb, er);else cb(er);
|
|
15688
15960
|
|
|
15689
15961
|
stream._writableState.errorEmitted = true;
|
|
15690
15962
|
stream.emit('error', er);
|
|
@@ -15704,30 +15976,26 @@ function onwrite(stream, er) {
|
|
|
15704
15976
|
|
|
15705
15977
|
onwriteStateUpdate(state);
|
|
15706
15978
|
|
|
15707
|
-
if (er)
|
|
15708
|
-
onwriteError(stream, state, sync, er, cb);
|
|
15709
|
-
else {
|
|
15979
|
+
if (er) onwriteError(stream, state, sync, er, cb);else {
|
|
15710
15980
|
// Check if we're actually ready to finish, but don't emit yet
|
|
15711
15981
|
var finished = needFinish(state);
|
|
15712
15982
|
|
|
15713
|
-
if (!finished &&
|
|
15714
|
-
!state.corked &&
|
|
15715
|
-
!state.bufferProcessing &&
|
|
15716
|
-
state.bufferedRequest) {
|
|
15983
|
+
if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
|
|
15717
15984
|
clearBuffer(stream, state);
|
|
15718
15985
|
}
|
|
15719
15986
|
|
|
15720
15987
|
if (sync) {
|
|
15721
|
-
|
|
15988
|
+
/*<replacement>*/
|
|
15989
|
+
asyncWrite(afterWrite, stream, state, finished, cb);
|
|
15990
|
+
/*</replacement>*/
|
|
15722
15991
|
} else {
|
|
15723
|
-
|
|
15724
|
-
|
|
15992
|
+
afterWrite(stream, state, finished, cb);
|
|
15993
|
+
}
|
|
15725
15994
|
}
|
|
15726
15995
|
}
|
|
15727
15996
|
|
|
15728
15997
|
function afterWrite(stream, state, finished, cb) {
|
|
15729
|
-
if (!finished)
|
|
15730
|
-
onwriteDrain(stream, state);
|
|
15998
|
+
if (!finished) onwriteDrain(stream, state);
|
|
15731
15999
|
state.pendingcb--;
|
|
15732
16000
|
cb();
|
|
15733
16001
|
finishMaybe(stream, state);
|
|
@@ -15743,7 +16011,6 @@ function onwriteDrain(stream, state) {
|
|
|
15743
16011
|
}
|
|
15744
16012
|
}
|
|
15745
16013
|
|
|
15746
|
-
|
|
15747
16014
|
// if there's something in the buffer waiting, then process it
|
|
15748
16015
|
function clearBuffer(stream, state) {
|
|
15749
16016
|
state.bufferProcessing = true;
|
|
@@ -15751,26 +16018,26 @@ function clearBuffer(stream, state) {
|
|
|
15751
16018
|
|
|
15752
16019
|
if (stream._writev && entry && entry.next) {
|
|
15753
16020
|
// Fast case, write everything using _writev()
|
|
15754
|
-
var
|
|
15755
|
-
var
|
|
16021
|
+
var l = state.bufferedRequestCount;
|
|
16022
|
+
var buffer = new Array(l);
|
|
16023
|
+
var holder = state.corkedRequestsFree;
|
|
16024
|
+
holder.entry = entry;
|
|
16025
|
+
|
|
16026
|
+
var count = 0;
|
|
15756
16027
|
while (entry) {
|
|
15757
|
-
|
|
15758
|
-
buffer.push(entry);
|
|
16028
|
+
buffer[count] = entry;
|
|
15759
16029
|
entry = entry.next;
|
|
16030
|
+
count += 1;
|
|
15760
16031
|
}
|
|
15761
16032
|
|
|
15762
|
-
|
|
15763
|
-
|
|
16033
|
+
doWrite(stream, state, true, state.length, buffer, '', holder.finish);
|
|
16034
|
+
|
|
16035
|
+
// doWrite is always async, defer these to save a bit of time
|
|
16036
|
+
// as the hot path ends with doWrite
|
|
15764
16037
|
state.pendingcb++;
|
|
15765
16038
|
state.lastBufferedRequest = null;
|
|
15766
|
-
|
|
15767
|
-
|
|
15768
|
-
state.pendingcb--;
|
|
15769
|
-
cbs[i](err);
|
|
15770
|
-
}
|
|
15771
|
-
});
|
|
15772
|
-
|
|
15773
|
-
// Clear buffer
|
|
16039
|
+
state.corkedRequestsFree = holder.next;
|
|
16040
|
+
holder.next = null;
|
|
15774
16041
|
} else {
|
|
15775
16042
|
// Slow case, write chunks one-by-one
|
|
15776
16043
|
while (entry) {
|
|
@@ -15790,20 +16057,21 @@ function clearBuffer(stream, state) {
|
|
|
15790
16057
|
}
|
|
15791
16058
|
}
|
|
15792
16059
|
|
|
15793
|
-
if (entry === null)
|
|
15794
|
-
state.lastBufferedRequest = null;
|
|
16060
|
+
if (entry === null) state.lastBufferedRequest = null;
|
|
15795
16061
|
}
|
|
16062
|
+
|
|
16063
|
+
state.bufferedRequestCount = 0;
|
|
15796
16064
|
state.bufferedRequest = entry;
|
|
15797
16065
|
state.bufferProcessing = false;
|
|
15798
16066
|
}
|
|
15799
16067
|
|
|
15800
|
-
Writable.prototype._write = function(chunk, encoding, cb) {
|
|
16068
|
+
Writable.prototype._write = function (chunk, encoding, cb) {
|
|
15801
16069
|
cb(new Error('not implemented'));
|
|
15802
16070
|
};
|
|
15803
16071
|
|
|
15804
16072
|
Writable.prototype._writev = null;
|
|
15805
16073
|
|
|
15806
|
-
Writable.prototype.end = function(chunk, encoding, cb) {
|
|
16074
|
+
Writable.prototype.end = function (chunk, encoding, cb) {
|
|
15807
16075
|
var state = this._writableState;
|
|
15808
16076
|
|
|
15809
16077
|
if (typeof chunk === 'function') {
|
|
@@ -15815,8 +16083,7 @@ Writable.prototype.end = function(chunk, encoding, cb) {
|
|
|
15815
16083
|
encoding = null;
|
|
15816
16084
|
}
|
|
15817
16085
|
|
|
15818
|
-
if (chunk !== null && chunk !== undefined)
|
|
15819
|
-
this.write(chunk, encoding);
|
|
16086
|
+
if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
|
|
15820
16087
|
|
|
15821
16088
|
// .end() fully uncorks
|
|
15822
16089
|
if (state.corked) {
|
|
@@ -15825,17 +16092,11 @@ Writable.prototype.end = function(chunk, encoding, cb) {
|
|
|
15825
16092
|
}
|
|
15826
16093
|
|
|
15827
16094
|
// ignore unnecessary end() calls.
|
|
15828
|
-
if (!state.ending && !state.finished)
|
|
15829
|
-
endWritable(this, state, cb);
|
|
16095
|
+
if (!state.ending && !state.finished) endWritable(this, state, cb);
|
|
15830
16096
|
};
|
|
15831
16097
|
|
|
15832
|
-
|
|
15833
16098
|
function needFinish(state) {
|
|
15834
|
-
return
|
|
15835
|
-
state.length === 0 &&
|
|
15836
|
-
state.bufferedRequest === null &&
|
|
15837
|
-
!state.finished &&
|
|
15838
|
-
!state.writing);
|
|
16099
|
+
return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
|
|
15839
16100
|
}
|
|
15840
16101
|
|
|
15841
16102
|
function prefinish(stream, state) {
|
|
@@ -15863,43 +16124,66 @@ function endWritable(stream, state, cb) {
|
|
|
15863
16124
|
state.ending = true;
|
|
15864
16125
|
finishMaybe(stream, state);
|
|
15865
16126
|
if (cb) {
|
|
15866
|
-
if (state.finished)
|
|
15867
|
-
processNextTick(cb);
|
|
15868
|
-
else
|
|
15869
|
-
stream.once('finish', cb);
|
|
16127
|
+
if (state.finished) processNextTick(cb);else stream.once('finish', cb);
|
|
15870
16128
|
}
|
|
15871
16129
|
state.ended = true;
|
|
16130
|
+
stream.writable = false;
|
|
15872
16131
|
}
|
|
15873
16132
|
|
|
15874
|
-
|
|
15875
|
-
|
|
16133
|
+
// It seems a linked list but it is not
|
|
16134
|
+
// there will be only 2 of these for each stream
|
|
16135
|
+
function CorkedRequest(state) {
|
|
16136
|
+
var _this = this;
|
|
16137
|
+
|
|
16138
|
+
this.next = null;
|
|
16139
|
+
this.entry = null;
|
|
16140
|
+
|
|
16141
|
+
this.finish = function (err) {
|
|
16142
|
+
var entry = _this.entry;
|
|
16143
|
+
_this.entry = null;
|
|
16144
|
+
while (entry) {
|
|
16145
|
+
var cb = entry.callback;
|
|
16146
|
+
state.pendingcb--;
|
|
16147
|
+
cb(err);
|
|
16148
|
+
entry = entry.next;
|
|
16149
|
+
}
|
|
16150
|
+
if (state.corkedRequestsFree) {
|
|
16151
|
+
state.corkedRequestsFree.next = _this;
|
|
16152
|
+
} else {
|
|
16153
|
+
state.corkedRequestsFree = _this;
|
|
16154
|
+
}
|
|
16155
|
+
};
|
|
16156
|
+
}
|
|
16157
|
+
}).call(this,_dereq_('_process'))
|
|
16158
|
+
},{"./_stream_duplex":75,"_process":66,"buffer":48,"core-util-is":51,"events":54,"inherits":57,"process-nextick-args":65,"util-deprecate":92}],80:[function(_dereq_,module,exports){
|
|
16159
|
+
module.exports = _dereq_("./lib/_stream_passthrough.js")
|
|
15876
16160
|
|
|
15877
|
-
},{"./lib/_stream_passthrough.js":
|
|
16161
|
+
},{"./lib/_stream_passthrough.js":76}],81:[function(_dereq_,module,exports){
|
|
15878
16162
|
var Stream = (function (){
|
|
15879
16163
|
try {
|
|
15880
|
-
return
|
|
16164
|
+
return _dereq_('st' + 'ream'); // hack to fix a circular dependency issue when used with browserify
|
|
15881
16165
|
} catch(_){}
|
|
15882
16166
|
}());
|
|
15883
|
-
exports = module.exports =
|
|
16167
|
+
exports = module.exports = _dereq_('./lib/_stream_readable.js');
|
|
15884
16168
|
exports.Stream = Stream || exports;
|
|
15885
16169
|
exports.Readable = exports;
|
|
15886
|
-
exports.Writable =
|
|
15887
|
-
exports.Duplex =
|
|
15888
|
-
exports.Transform =
|
|
15889
|
-
exports.PassThrough =
|
|
16170
|
+
exports.Writable = _dereq_('./lib/_stream_writable.js');
|
|
16171
|
+
exports.Duplex = _dereq_('./lib/_stream_duplex.js');
|
|
16172
|
+
exports.Transform = _dereq_('./lib/_stream_transform.js');
|
|
16173
|
+
exports.PassThrough = _dereq_('./lib/_stream_passthrough.js');
|
|
15890
16174
|
|
|
15891
|
-
},{"./lib/_stream_duplex.js":
|
|
15892
|
-
module.exports =
|
|
16175
|
+
},{"./lib/_stream_duplex.js":75,"./lib/_stream_passthrough.js":76,"./lib/_stream_readable.js":77,"./lib/_stream_transform.js":78,"./lib/_stream_writable.js":79}],82:[function(_dereq_,module,exports){
|
|
16176
|
+
module.exports = _dereq_("./lib/_stream_transform.js")
|
|
15893
16177
|
|
|
15894
|
-
},{"./lib/_stream_transform.js":
|
|
15895
|
-
module.exports =
|
|
16178
|
+
},{"./lib/_stream_transform.js":78}],83:[function(_dereq_,module,exports){
|
|
16179
|
+
module.exports = _dereq_("./lib/_stream_writable.js")
|
|
15896
16180
|
|
|
15897
|
-
},{"./lib/_stream_writable.js":
|
|
16181
|
+
},{"./lib/_stream_writable.js":79}],84:[function(_dereq_,module,exports){
|
|
15898
16182
|
(function (global){
|
|
15899
|
-
var ClientRequest =
|
|
15900
|
-
var extend =
|
|
15901
|
-
var statusCodes =
|
|
15902
|
-
var url =
|
|
16183
|
+
var ClientRequest = _dereq_('./lib/request')
|
|
16184
|
+
var extend = _dereq_('xtend')
|
|
16185
|
+
var statusCodes = _dereq_('builtin-status-codes')
|
|
16186
|
+
var url = _dereq_('url')
|
|
15903
16187
|
|
|
15904
16188
|
var http = exports
|
|
15905
16189
|
|
|
@@ -15976,7 +16260,7 @@ http.METHODS = [
|
|
|
15976
16260
|
'UNSUBSCRIBE'
|
|
15977
16261
|
]
|
|
15978
16262
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
15979
|
-
},{"./lib/request":
|
|
16263
|
+
},{"./lib/request":86,"builtin-status-codes":50,"url":90,"xtend":97}],85:[function(_dereq_,module,exports){
|
|
15980
16264
|
(function (global){
|
|
15981
16265
|
exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableByteStream)
|
|
15982
16266
|
|
|
@@ -16020,14 +16304,14 @@ function isFunction (value) {
|
|
|
16020
16304
|
xhr = null // Help gc
|
|
16021
16305
|
|
|
16022
16306
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
16023
|
-
},{}],
|
|
16307
|
+
},{}],86:[function(_dereq_,module,exports){
|
|
16024
16308
|
(function (process,global,Buffer){
|
|
16025
16309
|
// var Base64 = require('Base64')
|
|
16026
|
-
var capability =
|
|
16027
|
-
var inherits =
|
|
16028
|
-
var response =
|
|
16029
|
-
var stream =
|
|
16030
|
-
var toArrayBuffer =
|
|
16310
|
+
var capability = _dereq_('./capability')
|
|
16311
|
+
var inherits = _dereq_('inherits')
|
|
16312
|
+
var response = _dereq_('./response')
|
|
16313
|
+
var stream = _dereq_('stream')
|
|
16314
|
+
var toArrayBuffer = _dereq_('to-arraybuffer')
|
|
16031
16315
|
|
|
16032
16316
|
var IncomingMessage = response.IncomingMessage
|
|
16033
16317
|
var rStates = response.readyStates
|
|
@@ -16301,12 +16585,12 @@ var unsafeHeaders = [
|
|
|
16301
16585
|
'via'
|
|
16302
16586
|
]
|
|
16303
16587
|
|
|
16304
|
-
}).call(this,
|
|
16305
|
-
},{"./capability":
|
|
16588
|
+
}).call(this,_dereq_('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},_dereq_("buffer").Buffer)
|
|
16589
|
+
},{"./capability":85,"./response":87,"_process":66,"buffer":48,"inherits":57,"stream":72,"to-arraybuffer":89}],87:[function(_dereq_,module,exports){
|
|
16306
16590
|
(function (process,global,Buffer){
|
|
16307
|
-
var capability =
|
|
16308
|
-
var inherits =
|
|
16309
|
-
var stream =
|
|
16591
|
+
var capability = _dereq_('./capability')
|
|
16592
|
+
var inherits = _dereq_('inherits')
|
|
16593
|
+
var stream = _dereq_('stream')
|
|
16310
16594
|
|
|
16311
16595
|
var rStates = exports.readyStates = {
|
|
16312
16596
|
UNSENT: 0,
|
|
@@ -16373,10 +16657,16 @@ var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode) {
|
|
|
16373
16657
|
var matches = header.match(/^([^:]+):\s*(.*)/)
|
|
16374
16658
|
if (matches) {
|
|
16375
16659
|
var key = matches[1].toLowerCase()
|
|
16376
|
-
if (
|
|
16660
|
+
if (key === 'set-cookie') {
|
|
16661
|
+
if (self.headers[key] === undefined) {
|
|
16662
|
+
self.headers[key] = []
|
|
16663
|
+
}
|
|
16664
|
+
self.headers[key].push(matches[2])
|
|
16665
|
+
} else if (self.headers[key] !== undefined) {
|
|
16377
16666
|
self.headers[key] += ', ' + matches[2]
|
|
16378
|
-
else
|
|
16667
|
+
} else {
|
|
16379
16668
|
self.headers[key] = matches[2]
|
|
16669
|
+
}
|
|
16380
16670
|
self.rawHeaders.push(matches[1], matches[2])
|
|
16381
16671
|
}
|
|
16382
16672
|
})
|
|
@@ -16477,8 +16767,8 @@ IncomingMessage.prototype._onXHRProgress = function () {
|
|
|
16477
16767
|
}
|
|
16478
16768
|
}
|
|
16479
16769
|
|
|
16480
|
-
}).call(this,
|
|
16481
|
-
},{"./capability":
|
|
16770
|
+
}).call(this,_dereq_('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},_dereq_("buffer").Buffer)
|
|
16771
|
+
},{"./capability":85,"_process":66,"buffer":48,"inherits":57,"stream":72}],88:[function(_dereq_,module,exports){
|
|
16482
16772
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
16483
16773
|
//
|
|
16484
16774
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
@@ -16500,7 +16790,7 @@ IncomingMessage.prototype._onXHRProgress = function () {
|
|
|
16500
16790
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
16501
16791
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
16502
16792
|
|
|
16503
|
-
var Buffer =
|
|
16793
|
+
var Buffer = _dereq_('buffer').Buffer;
|
|
16504
16794
|
|
|
16505
16795
|
var isBufferEncoding = Buffer.isEncoding
|
|
16506
16796
|
|| function(encoding) {
|
|
@@ -16701,8 +16991,8 @@ function base64DetectIncompleteChar(buffer) {
|
|
|
16701
16991
|
this.charLength = this.charReceived ? 3 : 0;
|
|
16702
16992
|
}
|
|
16703
16993
|
|
|
16704
|
-
},{"buffer":
|
|
16705
|
-
var Buffer =
|
|
16994
|
+
},{"buffer":48}],89:[function(_dereq_,module,exports){
|
|
16995
|
+
var Buffer = _dereq_('buffer').Buffer
|
|
16706
16996
|
|
|
16707
16997
|
module.exports = function (buf) {
|
|
16708
16998
|
// If the buffer is backed by a Uint8Array, a faster version will work
|
|
@@ -16730,323 +17020,7 @@ module.exports = function (buf) {
|
|
|
16730
17020
|
}
|
|
16731
17021
|
}
|
|
16732
17022
|
|
|
16733
|
-
},{"buffer":
|
|
16734
|
-
(function (Buffer){
|
|
16735
|
-
'use strict';
|
|
16736
|
-
|
|
16737
|
-
var EventEmitter = require('events').EventEmitter;
|
|
16738
|
-
var inherits = require('util').inherits;
|
|
16739
|
-
|
|
16740
|
-
/**
|
|
16741
|
-
* Construct an {@link AccessManager} from an initial Access Token.
|
|
16742
|
-
* @class
|
|
16743
|
-
* @classdesc An {@link AccessManager} manages everything necessary for a
|
|
16744
|
-
* Twilio Client to access Twilio. Namely, the {@link AccessManager} manages
|
|
16745
|
-
* Access Tokens, and raises Access Token expiration events in the form of
|
|
16746
|
-
* {@link AccessManager#event:tokenExpired}.
|
|
16747
|
-
* @param {string} initialToken - The initial Access Token
|
|
16748
|
-
* @property {?string} identity - The identity granted by the current Access
|
|
16749
|
-
* Token; this value is populated asynchronously and is initially null
|
|
16750
|
-
* @property {string} token - The current Access Token
|
|
16751
|
-
* @property {boolean} isExpired - Whether or not the current Access Token is
|
|
16752
|
-
* expired
|
|
16753
|
-
* @property {?Date} expires - The time at which he current Access Token
|
|
16754
|
-
* expires; this value is populated asynchronously and is initially null
|
|
16755
|
-
* @fires AccessManager#error
|
|
16756
|
-
* @fires AccessManager#tokenExpired
|
|
16757
|
-
* @fires AccessManager#tokenUpdated
|
|
16758
|
-
*/
|
|
16759
|
-
function AccessManager(initialToken) {
|
|
16760
|
-
if (!(this instanceof AccessManager)) {
|
|
16761
|
-
return new AccessManager(initialToken);
|
|
16762
|
-
}
|
|
16763
|
-
EventEmitter.call(this);
|
|
16764
|
-
var expires = null;
|
|
16765
|
-
var identity = null;
|
|
16766
|
-
var isExpired = false;
|
|
16767
|
-
var pendingUpdate = null;
|
|
16768
|
-
var token = initialToken;
|
|
16769
|
-
var tokenExpiredTimer = null;
|
|
16770
|
-
var tokenUpdatedTimer = null;
|
|
16771
|
-
var tokenPayload = null;
|
|
16772
|
-
Object.defineProperties(this, {
|
|
16773
|
-
_expires: {
|
|
16774
|
-
get: function() {
|
|
16775
|
-
return expires;
|
|
16776
|
-
},
|
|
16777
|
-
set: function(_expires) {
|
|
16778
|
-
expires = _expires;
|
|
16779
|
-
}
|
|
16780
|
-
},
|
|
16781
|
-
_identity: {
|
|
16782
|
-
get: function() {
|
|
16783
|
-
return identity;
|
|
16784
|
-
},
|
|
16785
|
-
set: function(_identity) {
|
|
16786
|
-
identity = _identity;
|
|
16787
|
-
}
|
|
16788
|
-
},
|
|
16789
|
-
_isExpired: {
|
|
16790
|
-
get: function() {
|
|
16791
|
-
return isExpired;
|
|
16792
|
-
},
|
|
16793
|
-
set: function(_isExpired) {
|
|
16794
|
-
isExpired = _isExpired;
|
|
16795
|
-
}
|
|
16796
|
-
},
|
|
16797
|
-
_pendingUpdate: {
|
|
16798
|
-
get: function() {
|
|
16799
|
-
return pendingUpdate;
|
|
16800
|
-
},
|
|
16801
|
-
set: function(_pendingUpdate) {
|
|
16802
|
-
pendingUpdate = _pendingUpdate;
|
|
16803
|
-
}
|
|
16804
|
-
},
|
|
16805
|
-
_token: {
|
|
16806
|
-
get: function() {
|
|
16807
|
-
return token;
|
|
16808
|
-
},
|
|
16809
|
-
set: function(_token) {
|
|
16810
|
-
token = _token;
|
|
16811
|
-
}
|
|
16812
|
-
},
|
|
16813
|
-
_tokenExpiredTimer: {
|
|
16814
|
-
get: function() {
|
|
16815
|
-
return tokenExpiredTimer;
|
|
16816
|
-
},
|
|
16817
|
-
set: function(_tokenExpiredTimer) {
|
|
16818
|
-
tokenExpiredTimer = _tokenExpiredTimer;
|
|
16819
|
-
}
|
|
16820
|
-
},
|
|
16821
|
-
_tokenUpdatedTimer: {
|
|
16822
|
-
get: function() {
|
|
16823
|
-
return tokenUpdatedTimer;
|
|
16824
|
-
},
|
|
16825
|
-
set: function(_tokenUpdatedTimer) {
|
|
16826
|
-
tokenUpdatedTimer = _tokenUpdatedTimer;
|
|
16827
|
-
}
|
|
16828
|
-
},
|
|
16829
|
-
_tokenPayload: {
|
|
16830
|
-
get: function() {
|
|
16831
|
-
return tokenPayload;
|
|
16832
|
-
},
|
|
16833
|
-
set: function(_tokenPayload) {
|
|
16834
|
-
tokenPayload = _tokenPayload;
|
|
16835
|
-
}
|
|
16836
|
-
},
|
|
16837
|
-
expires: {
|
|
16838
|
-
enumerable: true,
|
|
16839
|
-
get: function() {
|
|
16840
|
-
return expires;
|
|
16841
|
-
}
|
|
16842
|
-
},
|
|
16843
|
-
identity: {
|
|
16844
|
-
enumerable: true,
|
|
16845
|
-
get: function() {
|
|
16846
|
-
return identity;
|
|
16847
|
-
}
|
|
16848
|
-
},
|
|
16849
|
-
isExpired: {
|
|
16850
|
-
enumerable: true,
|
|
16851
|
-
get: function() {
|
|
16852
|
-
return isExpired;
|
|
16853
|
-
}
|
|
16854
|
-
},
|
|
16855
|
-
token: {
|
|
16856
|
-
enumerable: true,
|
|
16857
|
-
get: function() {
|
|
16858
|
-
return token;
|
|
16859
|
-
}
|
|
16860
|
-
}
|
|
16861
|
-
});
|
|
16862
|
-
var _pendingUpdate = this.updateToken(initialToken);
|
|
16863
|
-
_pendingUpdate.catch(function(error) {
|
|
16864
|
-
if (this._pendingUpdate === _pendingUpdate) {
|
|
16865
|
-
this.emit('error', error);
|
|
16866
|
-
}
|
|
16867
|
-
}.bind(this));
|
|
16868
|
-
}
|
|
16869
|
-
|
|
16870
|
-
inherits(AccessManager, EventEmitter);
|
|
16871
|
-
|
|
16872
|
-
/**
|
|
16873
|
-
* Update the {@link AccessManager}'s current Access Token.
|
|
16874
|
-
* @param {string} newToken - A new Access Token
|
|
16875
|
-
* @returns {Promise<this>}
|
|
16876
|
-
* @fires AccessManager#tokenUpdated
|
|
16877
|
-
*/
|
|
16878
|
-
AccessManager.prototype.updateToken = function updateToken(newToken) {
|
|
16879
|
-
var self = this;
|
|
16880
|
-
|
|
16881
|
-
var pendingUpdate = new Promise(function(resolve) {
|
|
16882
|
-
|
|
16883
|
-
var payload = parsePayload(newToken);
|
|
16884
|
-
|
|
16885
|
-
// Set the identity.
|
|
16886
|
-
self._identity = getIdentity(payload);
|
|
16887
|
-
|
|
16888
|
-
// Emit the tokenUpdated event after the Promise resolves.
|
|
16889
|
-
clearTimeout(self._tokenUpdatedTimer);
|
|
16890
|
-
self._tokenUpdatedTimer = setTimeout(function tokenUpdated() {
|
|
16891
|
-
self._tokenUpdatedTimer = null;
|
|
16892
|
-
self.emit('tokenUpdated', self);
|
|
16893
|
-
});
|
|
16894
|
-
|
|
16895
|
-
// Set expires, isExpired, and tokenExpired timer.
|
|
16896
|
-
self._expires = new Date(payload.exp * 1000);
|
|
16897
|
-
self._isExpired = Date.now() >= self.expires;
|
|
16898
|
-
clearTimeout(self._tokenExpiredTimer);
|
|
16899
|
-
self._tokenExpiredTimer = setTimeout(function tokenExpiredTimer() {
|
|
16900
|
-
self._isExpired = true;
|
|
16901
|
-
self._tokenExpiredTimer = null;
|
|
16902
|
-
self.emit('tokenExpired', self);
|
|
16903
|
-
}, self.expires - Date.now());
|
|
16904
|
-
|
|
16905
|
-
// Update the token and tokenPayload.
|
|
16906
|
-
self._token = newToken;
|
|
16907
|
-
self._tokenPayload = payload;
|
|
16908
|
-
|
|
16909
|
-
resolve(self);
|
|
16910
|
-
});
|
|
16911
|
-
|
|
16912
|
-
this._pendingUpdate = pendingUpdate;
|
|
16913
|
-
|
|
16914
|
-
return pendingUpdate;
|
|
16915
|
-
};
|
|
16916
|
-
|
|
16917
|
-
/**
|
|
16918
|
-
* Parse the payload of a JSON Web Token (JWT).
|
|
16919
|
-
* @private
|
|
16920
|
-
* @param {string} jwt
|
|
16921
|
-
* @returns {object}
|
|
16922
|
-
*/
|
|
16923
|
-
function parsePayload(jwt) {
|
|
16924
|
-
var segments = jwt.split('.');
|
|
16925
|
-
if (segments.length !== 3) {
|
|
16926
|
-
throw new Error('Token is invalid or malformed');
|
|
16927
|
-
}
|
|
16928
|
-
var encodedPayloadString = segments[1];
|
|
16929
|
-
var payloadString = decodeBase64URL(encodedPayloadString);
|
|
16930
|
-
var payload = JSON.parse(payloadString);
|
|
16931
|
-
return payload;
|
|
16932
|
-
}
|
|
16933
|
-
|
|
16934
|
-
/**
|
|
16935
|
-
* Decode a base64url-encoded string.
|
|
16936
|
-
* @private
|
|
16937
|
-
* @param {string} encoded
|
|
16938
|
-
* @returns {string}
|
|
16939
|
-
*/
|
|
16940
|
-
function decodeBase64URL(encoded) {
|
|
16941
|
-
var remainder = encoded.length % 4;
|
|
16942
|
-
if (remainder > 0) {
|
|
16943
|
-
var padlen = 4 - remainder;
|
|
16944
|
-
encoded += new Array(padlen + 1).join('=');
|
|
16945
|
-
}
|
|
16946
|
-
encoded = encoded.replace(/-/g, '+')
|
|
16947
|
-
.replace(/_/g, '/');
|
|
16948
|
-
return decodeBase64(encoded);
|
|
16949
|
-
}
|
|
16950
|
-
|
|
16951
|
-
/**
|
|
16952
|
-
* Decode a base64-encoded string.
|
|
16953
|
-
* @private
|
|
16954
|
-
* @param {string} encoded
|
|
16955
|
-
* @returns {string}
|
|
16956
|
-
*/
|
|
16957
|
-
function decodeBase64(encoded) {
|
|
16958
|
-
return new Buffer(encoded, 'base64').toString();
|
|
16959
|
-
}
|
|
16960
|
-
|
|
16961
|
-
/**
|
|
16962
|
-
* Get the identity from the payload of an Access Token.
|
|
16963
|
-
* @private
|
|
16964
|
-
* @param {object} payload
|
|
16965
|
-
* @returns {?string}
|
|
16966
|
-
*/
|
|
16967
|
-
function getIdentity(payload) {
|
|
16968
|
-
var identity = null;
|
|
16969
|
-
if (!payload.grants && payload.scope) {
|
|
16970
|
-
identity = getIdentityFromCapabilityTokenScope(payload.scope);
|
|
16971
|
-
} else if (payload.grants instanceof Array) {
|
|
16972
|
-
identity = getIdentityFromSATGrants(payload.grants);
|
|
16973
|
-
} else if (typeof payload.grants === 'object') {
|
|
16974
|
-
identity = getIdentityFromFPAGrants(payload.grants);
|
|
16975
|
-
}
|
|
16976
|
-
return identity;
|
|
16977
|
-
}
|
|
16978
|
-
|
|
16979
|
-
/**
|
|
16980
|
-
* Get the identity from a Capability Token's Scope.
|
|
16981
|
-
* @private
|
|
16982
|
-
* @param {String} scope
|
|
16983
|
-
* @returns {?string}
|
|
16984
|
-
*/
|
|
16985
|
-
// TODO(rrowland): Remove this function as soon as we move to FPA.
|
|
16986
|
-
function getIdentityFromCapabilityTokenScope(scope) {
|
|
16987
|
-
var match = decodeURIComponent(scope).match(/identity=(.*?)(&|$)/i);
|
|
16988
|
-
return match && decodeURIComponent(match[1]);
|
|
16989
|
-
}
|
|
16990
|
-
|
|
16991
|
-
/**
|
|
16992
|
-
* Get the identity from Scoped Access Token (SAT) grants.
|
|
16993
|
-
* @private
|
|
16994
|
-
* @param {Array<Object>} grants
|
|
16995
|
-
* @returns {?string}
|
|
16996
|
-
*/
|
|
16997
|
-
// TODO(mroberts): Remove this function as soon as we move to FPA.
|
|
16998
|
-
function getIdentityFromSATGrants(grants) {
|
|
16999
|
-
var identity = null;
|
|
17000
|
-
for (var i = 0; i < grants.length; i++) {
|
|
17001
|
-
var grant = grants[i];
|
|
17002
|
-
if (grant && typeof grant.res === 'string') {
|
|
17003
|
-
var match = grant.res.match(/^sip:(.*)@/);
|
|
17004
|
-
if (match) {
|
|
17005
|
-
identity = decodeURIComponent(match[1]);
|
|
17006
|
-
break;
|
|
17007
|
-
}
|
|
17008
|
-
}
|
|
17009
|
-
}
|
|
17010
|
-
return identity;
|
|
17011
|
-
}
|
|
17012
|
-
|
|
17013
|
-
/**
|
|
17014
|
-
* Get the identity from First-Person Access Token (FPA) grants.
|
|
17015
|
-
* @private
|
|
17016
|
-
* @param {object} grants
|
|
17017
|
-
* @returns {?string}
|
|
17018
|
-
*/
|
|
17019
|
-
function getIdentityFromFPAGrants(grants) {
|
|
17020
|
-
return grants.identity || null;
|
|
17021
|
-
}
|
|
17022
|
-
|
|
17023
|
-
/**
|
|
17024
|
-
* An error occurred.
|
|
17025
|
-
* @param {Error} error
|
|
17026
|
-
* @event AccessManager#error
|
|
17027
|
-
*/
|
|
17028
|
-
|
|
17029
|
-
/**
|
|
17030
|
-
* The Access Token expired.
|
|
17031
|
-
* @param {AccessManager} manager
|
|
17032
|
-
* @event AccessManager#tokenExpired
|
|
17033
|
-
*/
|
|
17034
|
-
|
|
17035
|
-
/**
|
|
17036
|
-
* The Access Token was updated.
|
|
17037
|
-
* @param {AccessManager} manager
|
|
17038
|
-
* @event AccessManager#tokenUpdated
|
|
17039
|
-
*/
|
|
17040
|
-
|
|
17041
|
-
module.exports = AccessManager;
|
|
17042
|
-
|
|
17043
|
-
}).call(this,require("buffer").Buffer)
|
|
17044
|
-
},{"buffer":43,"events":49,"util":91}],86:[function(require,module,exports){
|
|
17045
|
-
'use strict';
|
|
17046
|
-
|
|
17047
|
-
module.exports.AccessManager = require('./accessmanager');
|
|
17048
|
-
|
|
17049
|
-
},{"./accessmanager":85}],87:[function(require,module,exports){
|
|
17023
|
+
},{"buffer":48}],90:[function(_dereq_,module,exports){
|
|
17050
17024
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
17051
17025
|
//
|
|
17052
17026
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
@@ -17070,8 +17044,8 @@ module.exports.AccessManager = require('./accessmanager');
|
|
|
17070
17044
|
|
|
17071
17045
|
'use strict';
|
|
17072
17046
|
|
|
17073
|
-
var punycode =
|
|
17074
|
-
var util =
|
|
17047
|
+
var punycode = _dereq_('punycode');
|
|
17048
|
+
var util = _dereq_('./util');
|
|
17075
17049
|
|
|
17076
17050
|
exports.parse = urlParse;
|
|
17077
17051
|
exports.resolve = urlResolve;
|
|
@@ -17146,7 +17120,7 @@ var protocolPattern = /^([a-z0-9.+-]+:)/i,
|
|
|
17146
17120
|
'gopher:': true,
|
|
17147
17121
|
'file:': true
|
|
17148
17122
|
},
|
|
17149
|
-
querystring =
|
|
17123
|
+
querystring = _dereq_('querystring');
|
|
17150
17124
|
|
|
17151
17125
|
function urlParse(url, parseQueryString, slashesDenoteHost) {
|
|
17152
17126
|
if (url && util.isObject(url) && url instanceof Url) return url;
|
|
@@ -17780,7 +17754,7 @@ Url.prototype.parseHost = function() {
|
|
|
17780
17754
|
if (host) this.hostname = host;
|
|
17781
17755
|
};
|
|
17782
17756
|
|
|
17783
|
-
},{"./util":
|
|
17757
|
+
},{"./util":91,"punycode":67,"querystring":71}],91:[function(_dereq_,module,exports){
|
|
17784
17758
|
'use strict';
|
|
17785
17759
|
|
|
17786
17760
|
module.exports = {
|
|
@@ -17798,7 +17772,7 @@ module.exports = {
|
|
|
17798
17772
|
}
|
|
17799
17773
|
};
|
|
17800
17774
|
|
|
17801
|
-
},{}],
|
|
17775
|
+
},{}],92:[function(_dereq_,module,exports){
|
|
17802
17776
|
(function (global){
|
|
17803
17777
|
|
|
17804
17778
|
/**
|
|
@@ -17869,14 +17843,14 @@ function config (name) {
|
|
|
17869
17843
|
}
|
|
17870
17844
|
|
|
17871
17845
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
17872
|
-
},{}],
|
|
17846
|
+
},{}],93:[function(_dereq_,module,exports){
|
|
17873
17847
|
module.exports = function isBuffer(arg) {
|
|
17874
17848
|
return arg && typeof arg === 'object'
|
|
17875
17849
|
&& typeof arg.copy === 'function'
|
|
17876
17850
|
&& typeof arg.fill === 'function'
|
|
17877
17851
|
&& typeof arg.readUInt8 === 'function';
|
|
17878
17852
|
}
|
|
17879
|
-
},{}],
|
|
17853
|
+
},{}],94:[function(_dereq_,module,exports){
|
|
17880
17854
|
(function (process,global){
|
|
17881
17855
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
17882
17856
|
//
|
|
@@ -18403,7 +18377,7 @@ function isPrimitive(arg) {
|
|
|
18403
18377
|
}
|
|
18404
18378
|
exports.isPrimitive = isPrimitive;
|
|
18405
18379
|
|
|
18406
|
-
exports.isBuffer =
|
|
18380
|
+
exports.isBuffer = _dereq_('./support/isBuffer');
|
|
18407
18381
|
|
|
18408
18382
|
function objectToString(o) {
|
|
18409
18383
|
return Object.prototype.toString.call(o);
|
|
@@ -18447,7 +18421,7 @@ exports.log = function() {
|
|
|
18447
18421
|
* prototype.
|
|
18448
18422
|
* @param {function} superCtor Constructor function to inherit prototype from.
|
|
18449
18423
|
*/
|
|
18450
|
-
exports.inherits =
|
|
18424
|
+
exports.inherits = _dereq_('inherits');
|
|
18451
18425
|
|
|
18452
18426
|
exports._extend = function(origin, add) {
|
|
18453
18427
|
// Don't do anything if add isn't an object
|
|
@@ -18465,8 +18439,8 @@ function hasOwnProperty(obj, prop) {
|
|
|
18465
18439
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
18466
18440
|
}
|
|
18467
18441
|
|
|
18468
|
-
}).call(this,
|
|
18469
|
-
},{"./support/isBuffer":
|
|
18442
|
+
}).call(this,_dereq_('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
18443
|
+
},{"./support/isBuffer":93,"_process":66,"inherits":57}],95:[function(_dereq_,module,exports){
|
|
18470
18444
|
|
|
18471
18445
|
/**
|
|
18472
18446
|
* Module dependencies.
|
|
@@ -18511,7 +18485,7 @@ function ws(uri, protocols, opts) {
|
|
|
18511
18485
|
|
|
18512
18486
|
if (WebSocket) ws.prototype = WebSocket.prototype;
|
|
18513
18487
|
|
|
18514
|
-
},{}],
|
|
18488
|
+
},{}],96:[function(_dereq_,module,exports){
|
|
18515
18489
|
(function (process,Buffer){
|
|
18516
18490
|
/**
|
|
18517
18491
|
* Wrapper for built-in http.js to emulate the browser XMLHttpRequest object.
|
|
@@ -18526,9 +18500,9 @@ if (WebSocket) ws.prototype = WebSocket.prototype;
|
|
|
18526
18500
|
* @license MIT
|
|
18527
18501
|
*/
|
|
18528
18502
|
|
|
18529
|
-
var Url =
|
|
18530
|
-
var spawn =
|
|
18531
|
-
var fs =
|
|
18503
|
+
var Url = _dereq_("url");
|
|
18504
|
+
var spawn = _dereq_("child_process").spawn;
|
|
18505
|
+
var fs = _dereq_("fs");
|
|
18532
18506
|
|
|
18533
18507
|
exports.XMLHttpRequest = function() {
|
|
18534
18508
|
"use strict";
|
|
@@ -18537,8 +18511,8 @@ exports.XMLHttpRequest = function() {
|
|
|
18537
18511
|
* Private variables
|
|
18538
18512
|
*/
|
|
18539
18513
|
var self = this;
|
|
18540
|
-
var http =
|
|
18541
|
-
var https =
|
|
18514
|
+
var http = _dereq_("http");
|
|
18515
|
+
var https = _dereq_("https");
|
|
18542
18516
|
|
|
18543
18517
|
// Holds http.js objects
|
|
18544
18518
|
var request;
|
|
@@ -19134,8 +19108,8 @@ exports.XMLHttpRequest = function() {
|
|
|
19134
19108
|
};
|
|
19135
19109
|
};
|
|
19136
19110
|
|
|
19137
|
-
}).call(this,
|
|
19138
|
-
},{"_process":
|
|
19111
|
+
}).call(this,_dereq_('_process'),_dereq_("buffer").Buffer)
|
|
19112
|
+
},{"_process":66,"buffer":48,"child_process":47,"fs":47,"http":84,"https":55,"url":90}],97:[function(_dereq_,module,exports){
|
|
19139
19113
|
module.exports = extend
|
|
19140
19114
|
|
|
19141
19115
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
@@ -19156,10 +19130,10 @@ function extend() {
|
|
|
19156
19130
|
return target
|
|
19157
19131
|
}
|
|
19158
19132
|
|
|
19159
|
-
},{}],
|
|
19133
|
+
},{}],98:[function(_dereq_,module,exports){
|
|
19160
19134
|
module.exports={
|
|
19161
19135
|
"name": "twilio-ip-messaging",
|
|
19162
|
-
"version": "0.
|
|
19136
|
+
"version": "0.10.0",
|
|
19163
19137
|
"description": "A library for Twilio IP messaging",
|
|
19164
19138
|
"main": "lib/index.js",
|
|
19165
19139
|
"repository": {
|
|
@@ -19169,7 +19143,7 @@ module.exports={
|
|
|
19169
19143
|
"scripts": {
|
|
19170
19144
|
"postinstall": "node ./scripts/postinstall.js"
|
|
19171
19145
|
},
|
|
19172
|
-
"author": "
|
|
19146
|
+
"author": "Twilio",
|
|
19173
19147
|
"license": "MIT",
|
|
19174
19148
|
"dependencies": {
|
|
19175
19149
|
"backoff": "^2.4.1",
|
|
@@ -19179,11 +19153,11 @@ module.exports={
|
|
|
19179
19153
|
"platform": "^1.3.0",
|
|
19180
19154
|
"q": "^1.4.1",
|
|
19181
19155
|
"twilio": "^2.5.1",
|
|
19182
|
-
"twilio-common": "^0.1.4",
|
|
19183
19156
|
"ws": "^0.8.0",
|
|
19184
19157
|
"xmlhttprequest": "^1.7.0"
|
|
19185
19158
|
},
|
|
19186
19159
|
"devDependencies": {
|
|
19160
|
+
"async": "^2.0.0-rc.1",
|
|
19187
19161
|
"babel-eslint": "^4.1.3",
|
|
19188
19162
|
"babel-preset-es2015": "^6.3.13",
|
|
19189
19163
|
"babelify": "^7.2.0",
|
|
@@ -19195,6 +19169,7 @@ module.exports={
|
|
|
19195
19169
|
"event-to-promise": "^0.6.0",
|
|
19196
19170
|
"express": "^4.13.3",
|
|
19197
19171
|
"gulp": "^3.9.0",
|
|
19172
|
+
"gulp-derequire": "^2.1.0",
|
|
19198
19173
|
"gulp-eslint": "^1.0.0",
|
|
19199
19174
|
"gulp-exit": "0.0.2",
|
|
19200
19175
|
"gulp-insert": "^0.5.0",
|
|
@@ -19220,24 +19195,24 @@ module.exports={
|
|
|
19220
19195
|
}
|
|
19221
19196
|
}
|
|
19222
19197
|
|
|
19223
|
-
},{}],
|
|
19198
|
+
},{}]},{},[38])(38)
|
|
19199
|
+
});
|
|
19200
|
+
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
19201
|
+
},{}],2:[function(require,module,exports){
|
|
19224
19202
|
(function (global){
|
|
19225
|
-
'use strict';
|
|
19226
|
-
|
|
19227
19203
|
/* eslint strict:0 */
|
|
19228
|
-
(function
|
|
19229
|
-
var IPMessaging = require('../lib');
|
|
19204
|
+
(function(root) {
|
|
19230
19205
|
/* globals define */
|
|
19231
19206
|
if (typeof define === 'function' && define.amd) {
|
|
19232
|
-
define([], function
|
|
19233
|
-
return
|
|
19207
|
+
define([], function() {
|
|
19208
|
+
return require('./twilio-ip-messaging-bundle.js');
|
|
19234
19209
|
});
|
|
19235
19210
|
} else {
|
|
19236
19211
|
var Twilio = root.Twilio = root.Twilio || {};
|
|
19237
|
-
Twilio.
|
|
19238
|
-
Twilio.IPMessaging = Twilio.IPMessaging || IPMessaging;
|
|
19212
|
+
Twilio.IPMessaging = Twilio.IPMessaging || require('./twilio-ip-messaging-bundle.js');
|
|
19239
19213
|
}
|
|
19240
|
-
})(typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global :
|
|
19214
|
+
})(typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : this);
|
|
19215
|
+
|
|
19241
19216
|
|
|
19242
19217
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
19243
|
-
},{"
|
|
19218
|
+
},{"./twilio-ip-messaging-bundle.js":1}]},{},[2]);
|