@twilio/conversations 1.3.0-rc8 → 2.0.0-rc.4
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.
- package/CHANGELOG.md +210 -0
- package/README.md +22 -17
- package/dist/browser.js +7873 -0
- package/dist/browser.js.map +1 -0
- package/dist/docs/assets/css/main.css +2660 -0
- package/dist/docs/assets/images/icons.png +0 -0
- package/dist/docs/assets/images/icons@2x.png +0 -0
- package/dist/docs/assets/images/widgets.png +0 -0
- package/dist/docs/assets/images/widgets@2x.png +0 -0
- package/dist/docs/assets/js/main.js +248 -0
- package/dist/docs/assets/js/search.js +1 -0
- package/dist/docs/classes/AggregatedDeliveryReceipt.html +3286 -0
- package/dist/docs/classes/Client.html +4181 -0
- package/dist/docs/classes/Conversation.html +4397 -0
- package/dist/docs/classes/DetailedDeliveryReceipt.html +3265 -0
- package/dist/docs/classes/Media.html +3295 -0
- package/dist/docs/classes/Message.html +3713 -0
- package/dist/docs/classes/MessageBuilder.html +3280 -0
- package/dist/docs/classes/Participant.html +3517 -0
- package/dist/docs/classes/PushNotification.html +3232 -0
- package/dist/docs/classes/RestPaginator.html +3262 -0
- package/dist/docs/classes/UnsentMessage.html +3144 -0
- package/dist/docs/classes/User.html +3451 -0
- package/dist/docs/index.html +3394 -212
- package/dist/docs/interfaces/ClientOptions.html +3136 -0
- package/dist/docs/interfaces/ConversationState.html +3152 -0
- package/dist/docs/interfaces/CreateConversationOptions.html +3168 -0
- package/dist/docs/interfaces/LastMessage.html +3152 -0
- package/dist/docs/interfaces/Paginator.html +3243 -0
- package/dist/docs/interfaces/PushNotificationData.html +3168 -0
- package/dist/docs/interfaces/SendEmailOptions.html +3136 -0
- package/dist/docs/interfaces/SendMediaOptions.html +3170 -0
- package/dist/docs/modules.html +3425 -0
- package/dist/lib.d.ts +1952 -0
- package/dist/lib.js +7873 -0
- package/dist/lib.js.map +1 -0
- package/dist/post-install.js +29 -0
- package/dist/react-native.js +4038 -0
- package/dist/react-native.js.map +1 -0
- package/dist/twilio-conversations.js +40912 -0
- package/dist/twilio-conversations.min.js +156 -0
- package/package.json +59 -48
- package/.circleci/config.yml +0 -650
- package/.deepsource.toml +0 -6
- package/.env.example +0 -13
- package/browser/aggregateddeliveryreceipt.js +0 -152
- package/browser/client.js +0 -991
- package/browser/configuration.js +0 -80
- package/browser/conversation.js +0 -1826
- package/browser/data/conversations.js +0 -632
- package/browser/data/messages.js +0 -522
- package/browser/data/participants.js +0 -411
- package/browser/data/users.js +0 -281
- package/browser/detaileddeliveryreceipt.js +0 -44
- package/browser/index.js +0 -4
- package/browser/interfaces/limits.js +0 -3
- package/browser/interfaces/notificationtypes.js +0 -21
- package/browser/interfaces/paginator.js +0 -53
- package/browser/interfaces/responsecodes.js +0 -20
- package/browser/interfaces/transport.js +0 -3
- package/browser/logger.js +0 -141
- package/browser/media.js +0 -198
- package/browser/message.js +0 -685
- package/browser/participant.js +0 -415
- package/browser/pushnotification.js +0 -49
- package/browser/restpaginator.js +0 -74
- package/browser/services/network.js +0 -223
- package/browser/services/readhorizon.js +0 -181
- package/browser/services/typingindicator.js +0 -142
- package/browser/session.js +0 -505
- package/browser/sessionerror.js +0 -93
- package/browser/sri.json +0 -1
- package/browser/synclist.js +0 -90
- package/browser/synclistdescriptor.js +0 -29
- package/browser/syncpaginator.js +0 -63
- package/browser/user.js +0 -431
- package/browser/util/deferred.js +0 -56
- package/browser/util/index.js +0 -108
- package/dist/@twilio/conversations.js +0 -35533
- package/dist/@twilio/conversations.min.js +0 -204
- package/dist/docs/AggregatedDeliveryReceipt.html +0 -948
- package/dist/docs/Client.html +0 -5075
- package/dist/docs/Conversation.html +0 -6018
- package/dist/docs/DetailedDeliveryReceipt.html +0 -641
- package/dist/docs/Media.html +0 -694
- package/dist/docs/Message.html +0 -1934
- package/dist/docs/Paginator.html +0 -605
- package/dist/docs/Participant.html +0 -1510
- package/dist/docs/PushNotification.html +0 -836
- package/dist/docs/SessionError.html +0 -379
- package/dist/docs/User.html +0 -1315
- package/dist/docs/classes.list.html +0 -4431
- package/dist/docs/fonts/glyphicons-halflings-regular.eot +0 -0
- package/dist/docs/fonts/glyphicons-halflings-regular.svg +0 -288
- package/dist/docs/fonts/glyphicons-halflings-regular.ttf +0 -0
- package/dist/docs/fonts/glyphicons-halflings-regular.woff +0 -0
- package/dist/docs/fonts/glyphicons-halflings-regular.woff2 +0 -0
- package/dist/docs/img/glyphicons-halflings-white.png +0 -0
- package/dist/docs/img/glyphicons-halflings.png +0 -0
- package/dist/docs/quicksearch.html +0 -31
- package/dist/docs/scripts/docstrap.lib.js +0 -11
- package/dist/docs/scripts/fulltext-search-ui.js +0 -89
- package/dist/docs/scripts/fulltext-search.js +0 -36
- package/dist/docs/scripts/lunr.min.js +0 -6
- package/dist/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
- package/dist/docs/scripts/prettify/jquery.min.js +0 -6
- package/dist/docs/scripts/prettify/lang-css.js +0 -21
- package/dist/docs/scripts/prettify/prettify.js +0 -496
- package/dist/docs/scripts/sunlight.js +0 -1157
- package/dist/docs/scripts/toc.js +0 -203
- package/dist/docs/styles/darkstrap.css +0 -960
- package/dist/docs/styles/prettify-tomorrow.css +0 -132
- package/dist/docs/styles/site.cerulean.css +0 -7008
- package/dist/docs/styles/site.cosmo.css +0 -7061
- package/dist/docs/styles/site.cyborg.css +0 -7048
- package/dist/docs/styles/site.darkly.css +0 -7171
- package/dist/docs/styles/site.darkstrap.css +0 -5638
- package/dist/docs/styles/site.dibs-bootstrap.css +0 -5899
- package/dist/docs/styles/site.flatly.css +0 -7147
- package/dist/docs/styles/site.journal.css +0 -6973
- package/dist/docs/styles/site.lumen.css +0 -7298
- package/dist/docs/styles/site.paper.css +0 -7623
- package/dist/docs/styles/site.readable.css +0 -6997
- package/dist/docs/styles/site.sandstone.css +0 -7035
- package/dist/docs/styles/site.simplex.css +0 -7023
- package/dist/docs/styles/site.slate.css +0 -7343
- package/dist/docs/styles/site.spacelab.css +0 -7055
- package/dist/docs/styles/site.superhero.css +0 -7131
- package/dist/docs/styles/site.united.css +0 -6895
- package/dist/docs/styles/site.yeti.css +0 -7195
- package/dist/docs/styles/sunlight.dark.css +0 -345
- package/dist/docs/styles/sunlight.default.css +0 -344
- package/dist/sri.json +0 -1
- package/lib/aggregateddeliveryreceipt.d.ts +0 -98
- package/lib/aggregateddeliveryreceipt.js +0 -112
- package/lib/client.d.ts +0 -317
- package/lib/client.js +0 -633
- package/lib/configuration.d.ts +0 -21
- package/lib/configuration.js +0 -41
- package/lib/conversation.d.ts +0 -460
- package/lib/conversation.js +0 -940
- package/lib/data/conversations.d.ts +0 -57
- package/lib/data/conversations.js +0 -296
- package/lib/data/messages.d.ts +0 -75
- package/lib/data/messages.js +0 -208
- package/lib/data/participants.d.ts +0 -94
- package/lib/data/participants.js +0 -204
- package/lib/data/users.d.ts +0 -42
- package/lib/data/users.js +0 -113
- package/lib/detaileddeliveryreceipt.d.ts +0 -45
- package/lib/detaileddeliveryreceipt.js +0 -34
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -3
- package/lib/interfaces/limits.d.ts +0 -8
- package/lib/interfaces/limits.js +0 -2
- package/lib/interfaces/notificationtypes.d.ts +0 -8
- package/lib/interfaces/notificationtypes.js +0 -11
- package/lib/interfaces/paginator.d.ts +0 -52
- package/lib/interfaces/paginator.js +0 -28
- package/lib/interfaces/responsecodes.d.ts +0 -8
- package/lib/interfaces/responsecodes.js +0 -10
- package/lib/interfaces/transport.d.ts +0 -13
- package/lib/interfaces/transport.js +0 -2
- package/lib/logger.d.ts +0 -18
- package/lib/logger.js +0 -35
- package/lib/media.d.ts +0 -52
- package/lib/media.js +0 -69
- package/lib/message.d.ts +0 -136
- package/lib/message.js +0 -305
- package/lib/participant.d.ts +0 -142
- package/lib/participant.js +0 -219
- package/lib/pushnotification.d.ts +0 -48
- package/lib/pushnotification.js +0 -39
- package/lib/restpaginator.d.ts +0 -19
- package/lib/restpaginator.js +0 -36
- package/lib/services/network.d.ts +0 -22
- package/lib/services/network.js +0 -87
- package/lib/services/readhorizon.d.ts +0 -28
- package/lib/services/readhorizon.js +0 -112
- package/lib/services/typingindicator.d.ts +0 -50
- package/lib/services/typingindicator.js +0 -102
- package/lib/session.d.ts +0 -63
- package/lib/session.js +0 -213
- package/lib/sessionerror.d.ts +0 -12
- package/lib/sessionerror.js +0 -24
- package/lib/sri.json +0 -1
- package/lib/synclist.d.ts +0 -24
- package/lib/synclist.js +0 -28
- package/lib/synclistdescriptor.d.ts +0 -27
- package/lib/synclistdescriptor.js +0 -19
- package/lib/syncpaginator.d.ts +0 -22
- package/lib/syncpaginator.js +0 -37
- package/lib/user.d.ts +0 -98
- package/lib/user.js +0 -219
- package/lib/util/deferred.d.ts +0 -12
- package/lib/util/deferred.js +0 -22
- package/lib/util/index.d.ts +0 -28
- package/lib/util/index.js +0 -82
- package/tools/rtd-sdk-cdn-pin/.gitrepo +0 -12
- package/tools/rtd-sdk-cdn-pin/README.md +0 -54
- package/tools/rtd-sdk-cdn-pin/bintray-settings.xml.template +0 -16
- package/tools/rtd-sdk-cdn-pin/cdn-common/cdn-prepare.sh +0 -67
- package/tools/rtd-sdk-cdn-pin/cdn-pin-latest.sh +0 -19
- package/tools/rtd-sdk-cdn-pin/cdn-pin.sh +0 -19
- package/tools/rtd-sdk-cdn-pin/cdn-upload.sh +0 -13
- package/tools/rtd-sdk-cdn-pin/fetch/common/fetch-bintray-android.sh +0 -34
- package/tools/rtd-sdk-cdn-pin/fetch/common/fetch-npm.sh +0 -18
- package/tools/rtd-sdk-cdn-pin/fetch/twilio-chat-android.sh +0 -5
- package/tools/rtd-sdk-cdn-pin/fetch/twilio-chat-js.sh +0 -5
- package/tools/rtd-sdk-cdn-pin/fetch/twilio-conversations-android.sh +0 -6
- package/tools/rtd-sdk-cdn-pin/fetch/twilio-conversations-js.sh +0 -5
- package/tools/rtd-sdk-cdn-pin/fetch/twilio-sync-android.sh +0 -5
- package/tools/rtd-sdk-cdn-pin/fetch/twilio-sync-js.sh +0 -5
- package/tools/rtd-sdk-cdn-pin/fetch-artifact.sh +0 -26
- package/tools/sdk-release-tool/.gitrepo +0 -12
- package/tools/sdk-release-tool/Makefile +0 -49
- package/tools/sdk-release-tool/README.md +0 -275
- package/tools/sdk-release-tool/delete +0 -3
- package/tools/sdk-release-tool/download +0 -3
- package/tools/sdk-release-tool/get-cors +0 -3
- package/tools/sdk-release-tool/list +0 -3
- package/tools/sdk-release-tool/pin +0 -3
- package/tools/sdk-release-tool/pin-latest +0 -3
- package/tools/sdk-release-tool/requirements.txt +0 -4
- package/tools/sdk-release-tool/sdk-release-tool +0 -3
- package/tools/sdk-release-tool/sdk_release_tools/__init__.py +0 -0
- package/tools/sdk-release-tool/sdk_release_tools/__main__.py +0 -110
- package/tools/sdk-release-tool/sdk_release_tools/aws.py +0 -70
- package/tools/sdk-release-tool/sdk_release_tools/cli.py +0 -181
- package/tools/sdk-release-tool/sdk_release_tools/log.py +0 -24
- package/tools/sdk-release-tool/sdk_release_tools/ops.py +0 -295
- package/tools/sdk-release-tool/sdk_release_tools/rpm.py +0 -28
- package/tools/sdk-release-tool/sdk_release_tools/util.py +0 -186
- package/tools/sdk-release-tool/sdk_release_tools/versions.py +0 -362
- package/tools/sdk-release-tool/signal-sdk-js.json +0 -28
- package/tools/sdk-release-tool/tests/test_versions.py +0 -94
- package/tools/sdk-release-tool/twilio-accessmanager-android.json +0 -19
- package/tools/sdk-release-tool/twilio-accessmanager-ios.json +0 -26
- package/tools/sdk-release-tool/twilio-auth-ios.json +0 -29
- package/tools/sdk-release-tool/twilio-authenticator-ios.json +0 -29
- package/tools/sdk-release-tool/twilio-chat-android-2.json +0 -19
- package/tools/sdk-release-tool/twilio-chat-android.json +0 -22
- package/tools/sdk-release-tool/twilio-chat-ios.json +0 -26
- package/tools/sdk-release-tool/twilio-chat-js.json +0 -27
- package/tools/sdk-release-tool/twilio-client-android-aar.json +0 -22
- package/tools/sdk-release-tool/twilio-client-android.json +0 -22
- package/tools/sdk-release-tool/twilio-client-ios.json +0 -20
- package/tools/sdk-release-tool/twilio-client-js.json +0 -17
- package/tools/sdk-release-tool/twilio-client-sounds-js.json +0 -14
- package/tools/sdk-release-tool/twilio-common-android-maven.json +0 -16
- package/tools/sdk-release-tool/twilio-common-android.json +0 -22
- package/tools/sdk-release-tool/twilio-common-ios-rtc.json +0 -25
- package/tools/sdk-release-tool/twilio-common-ios.json +0 -25
- package/tools/sdk-release-tool/twilio-common-js.json +0 -19
- package/tools/sdk-release-tool/twilio-conversations-android.json +0 -22
- package/tools/sdk-release-tool/twilio-conversations-ios.json +0 -26
- package/tools/sdk-release-tool/twilio-conversations-js.json +0 -27
- package/tools/sdk-release-tool/twilio-flex-js.json +0 -20
- package/tools/sdk-release-tool/twilio-flex-webchat-js.json +0 -16
- package/tools/sdk-release-tool/twilio-frame-chat-android.json +0 -22
- package/tools/sdk-release-tool/twilio-frame-chat-ios.json +0 -23
- package/tools/sdk-release-tool/twilio-frame-chat-js.json +0 -23
- package/tools/sdk-release-tool/twilio-ip-messaging-android-maven.json +0 -16
- package/tools/sdk-release-tool/twilio-ip-messaging-android.json +0 -22
- package/tools/sdk-release-tool/twilio-ip-messaging-ios.json +0 -25
- package/tools/sdk-release-tool/twilio-ip-messaging-js.json +0 -21
- package/tools/sdk-release-tool/twilio-sync-android.json +0 -22
- package/tools/sdk-release-tool/twilio-sync-ios.json +0 -26
- package/tools/sdk-release-tool/twilio-sync-js.json +0 -39
- package/tools/sdk-release-tool/twilio-taskrouter-js.json +0 -17
- package/tools/sdk-release-tool/twilio-video-android.json +0 -22
- package/tools/sdk-release-tool/twilio-video-cpp-linux-cross-rootfs.json +0 -13
- package/tools/sdk-release-tool/twilio-video-cpp.json +0 -33
- package/tools/sdk-release-tool/twilio-video-ios.json +0 -25
- package/tools/sdk-release-tool/twilio-video-js.json +0 -19
- package/tools/sdk-release-tool/twilio-video-jsdocs.json +0 -14
- package/tools/sdk-release-tool/twilio-voice-android.json +0 -22
- package/tools/sdk-release-tool/twilio-voice-ios.json +0 -29
- package/tools/sdk-release-tool/unpin +0 -3
- package/tools/sdk-release-tool/unpin-latest +0 -3
- package/tools/sdk-release-tool/upload +0 -3
- package/twilio-chat.js.iml +0 -9
package/browser/client.js
DELETED
@@ -1,991 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _regenerator = require("babel-runtime/regenerator");
|
4
|
-
|
5
|
-
var _regenerator2 = _interopRequireDefault(_regenerator);
|
6
|
-
|
7
|
-
var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator");
|
8
|
-
|
9
|
-
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
|
10
|
-
|
11
|
-
var _promise = require("babel-runtime/core-js/promise");
|
12
|
-
|
13
|
-
var _promise2 = _interopRequireDefault(_promise);
|
14
|
-
|
15
|
-
var _assign = require("babel-runtime/core-js/object/assign");
|
16
|
-
|
17
|
-
var _assign2 = _interopRequireDefault(_assign);
|
18
|
-
|
19
|
-
var _getPrototypeOf = require("babel-runtime/core-js/object/get-prototype-of");
|
20
|
-
|
21
|
-
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
|
22
|
-
|
23
|
-
var _createClass2 = require("babel-runtime/helpers/createClass");
|
24
|
-
|
25
|
-
var _createClass3 = _interopRequireDefault(_createClass2);
|
26
|
-
|
27
|
-
var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");
|
28
|
-
|
29
|
-
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
|
30
|
-
|
31
|
-
var _inherits2 = require("babel-runtime/helpers/inherits");
|
32
|
-
|
33
|
-
var _inherits3 = _interopRequireDefault(_inherits2);
|
34
|
-
|
35
|
-
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
|
36
|
-
|
37
|
-
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
38
|
-
|
39
|
-
var _metadata = require("babel-runtime/core-js/reflect/metadata");
|
40
|
-
|
41
|
-
var _metadata2 = _interopRequireDefault(_metadata);
|
42
|
-
|
43
|
-
var _defineProperty = require("babel-runtime/core-js/object/define-property");
|
44
|
-
|
45
|
-
var _defineProperty2 = _interopRequireDefault(_defineProperty);
|
46
|
-
|
47
|
-
var _typeof2 = require("babel-runtime/helpers/typeof");
|
48
|
-
|
49
|
-
var _typeof3 = _interopRequireDefault(_typeof2);
|
50
|
-
|
51
|
-
var _getOwnPropertyDescriptor = require("babel-runtime/core-js/object/get-own-property-descriptor");
|
52
|
-
|
53
|
-
var _getOwnPropertyDescriptor2 = _interopRequireDefault(_getOwnPropertyDescriptor);
|
54
|
-
|
55
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
56
|
-
|
57
|
-
var __decorate = undefined && undefined.__decorate || function (decorators, target, key, desc) {
|
58
|
-
var c = arguments.length,
|
59
|
-
r = c < 3 ? target : desc === null ? desc = (0, _getOwnPropertyDescriptor2.default)(target, key) : desc,
|
60
|
-
d;
|
61
|
-
if ((typeof Reflect === "undefined" ? "undefined" : (0, _typeof3.default)(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
|
62
|
-
if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
63
|
-
}return c > 3 && r && (0, _defineProperty2.default)(target, key, r), r;
|
64
|
-
};
|
65
|
-
var __metadata = undefined && undefined.__metadata || function (k, v) {
|
66
|
-
if ((typeof Reflect === "undefined" ? "undefined" : (0, _typeof3.default)(Reflect)) === "object" && typeof _metadata2.default === "function") return (0, _metadata2.default)(k, v);
|
67
|
-
};
|
68
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
69
|
-
var events_1 = require("events");
|
70
|
-
var logger_1 = require("./logger");
|
71
|
-
var configuration_1 = require("./configuration");
|
72
|
-
var user_1 = require("./user");
|
73
|
-
exports.User = user_1.User;
|
74
|
-
var network_1 = require("./services/network");
|
75
|
-
var notificationtypes_1 = require("./interfaces/notificationtypes");
|
76
|
-
var synclist_1 = require("./synclist");
|
77
|
-
var twilsock_1 = require("twilsock");
|
78
|
-
var twilio_notifications_1 = require("twilio-notifications");
|
79
|
-
var twilio_sync_1 = require("twilio-sync");
|
80
|
-
var twilio_mcs_client_1 = require("twilio-mcs-client");
|
81
|
-
var session_1 = require("./session");
|
82
|
-
var conversations_1 = require("./data/conversations");
|
83
|
-
var users_1 = require("./data/users");
|
84
|
-
var typingindicator_1 = require("./services/typingindicator");
|
85
|
-
var readhorizon_1 = require("./services/readhorizon");
|
86
|
-
var pushnotification_1 = require("./pushnotification");
|
87
|
-
exports.PushNotification = pushnotification_1.PushNotification;
|
88
|
-
var util_1 = require("./util");
|
89
|
-
var telemetrytracker_1 = require("twilsock/lib/services/telemetrytracker");
|
90
|
-
var twilio_sdk_type_validator_1 = require("twilio-sdk-type-validator");
|
91
|
-
var log = logger_1.Logger.scope('Client');
|
92
|
-
var SDK_VERSION = require('./../package.json').version;
|
93
|
-
|
94
|
-
var ClientServices = function ClientServices() {
|
95
|
-
(0, _classCallCheck3.default)(this, ClientServices);
|
96
|
-
};
|
97
|
-
/**
|
98
|
-
* A Client is a starting point to access Twilio Conversations functionality.
|
99
|
-
*
|
100
|
-
* @property {Client#ConnectionState} connectionState - Client connection state
|
101
|
-
* @property {Boolean} reachabilityEnabled - Client reachability state
|
102
|
-
* @property {User} user - Information for logged in user
|
103
|
-
* @property {String} version - Current version of Conversations client
|
104
|
-
*
|
105
|
-
* @fires Client#connectionError
|
106
|
-
* @fires Client#connectionStateChanged
|
107
|
-
* @fires Client#conversationAdded
|
108
|
-
* @fires Client#conversationJoined
|
109
|
-
* @fires Client#conversationLeft
|
110
|
-
* @fires Client#conversationRemoved
|
111
|
-
* @fires Client#conversationUpdated
|
112
|
-
* @fires Client#participantJoined
|
113
|
-
* @fires Client#participantLeft
|
114
|
-
* @fires Client#participantUpdated
|
115
|
-
* @fires Client#messageAdded
|
116
|
-
* @fires Client#messageRemoved
|
117
|
-
* @fires Client#messageUpdated
|
118
|
-
* @fires Client#pushNotification
|
119
|
-
* @fires Client#tokenAboutToExpire
|
120
|
-
* @fires Client#tokenExpired
|
121
|
-
* @fires Client#typingEnded
|
122
|
-
* @fires Client#typingStarted
|
123
|
-
* @fires Client#userSubscribed
|
124
|
-
* @fires Client#userUnsubscribed
|
125
|
-
* @fires Client#userUpdated
|
126
|
-
*/
|
127
|
-
|
128
|
-
|
129
|
-
var Client = function (_events_1$EventEmitte) {
|
130
|
-
(0, _inherits3.default)(Client, _events_1$EventEmitte);
|
131
|
-
|
132
|
-
/**
|
133
|
-
* These options can be passed to Client constructor.
|
134
|
-
* @typedef {Object} Client#ClientOptions
|
135
|
-
* @property {String} [logLevel='error'] - The level of logging to enable. Valid options
|
136
|
-
* (from strictest to broadest): ['silent', 'error', 'warn', 'info', 'debug', 'trace']
|
137
|
-
*/
|
138
|
-
/**
|
139
|
-
* These options can be passed to {@link Client#createConversation}.
|
140
|
-
* @typedef {Object} Client#CreateConversationOptions
|
141
|
-
* @property {any} [attributes] - Any custom attributes to attach to the Conversation
|
142
|
-
* @property {String} [friendlyName] - The non-unique display name of the Conversation
|
143
|
-
* @property {String} [uniqueName] - The unique identifier of the Conversation
|
144
|
-
*/
|
145
|
-
/**
|
146
|
-
* Connection state of Client.
|
147
|
-
* @typedef {('connecting'|'connected'|'disconnecting'|'disconnected'|'denied')} Client#ConnectionState
|
148
|
-
*/
|
149
|
-
/**
|
150
|
-
* Notifications channel type.
|
151
|
-
* @typedef {('fcm'|'apn')} Client#NotificationsChannelType
|
152
|
-
*/
|
153
|
-
function Client(token, options) {
|
154
|
-
(0, _classCallCheck3.default)(this, Client);
|
155
|
-
|
156
|
-
var _this = (0, _possibleConstructorReturn3.default)(this, (Client.__proto__ || (0, _getPrototypeOf2.default)(Client)).call(this));
|
157
|
-
|
158
|
-
_this.connectionState = 'connecting';
|
159
|
-
_this.sessionPromise = null;
|
160
|
-
_this.conversationsPromise = null;
|
161
|
-
_this.version = SDK_VERSION;
|
162
|
-
_this.parsePushNotification = Client.parsePushNotification;
|
163
|
-
_this.options = options || {};
|
164
|
-
if (!_this.options.disableDeepClone) {
|
165
|
-
var _options = (0, _assign2.default)((0, _assign2.default)({}, _this.options), { transport: undefined, twilsockClient: undefined });
|
166
|
-
_options = util_1.deepClone(_options);
|
167
|
-
_options.transport = _this.options.transport;
|
168
|
-
_options.twilsockClient = _this.options.twilsockClient;
|
169
|
-
_this.options = _options;
|
170
|
-
}
|
171
|
-
_this.options.logLevel = _this.options.logLevel || 'silent';
|
172
|
-
log.setLevel(_this.options.logLevel);
|
173
|
-
var productId = _this.options.productId = 'ip_messaging';
|
174
|
-
// Filling ClientMetadata
|
175
|
-
_this.options.clientMetadata = _this.options.clientMetadata || {};
|
176
|
-
if (!_this.options.clientMetadata.hasOwnProperty('type')) {
|
177
|
-
_this.options.clientMetadata.type = 'conversations';
|
178
|
-
}
|
179
|
-
if (!_this.options.clientMetadata.hasOwnProperty('sdk')) {
|
180
|
-
_this.options.clientMetadata.sdk = 'JS';
|
181
|
-
_this.options.clientMetadata.sdkv = SDK_VERSION;
|
182
|
-
}
|
183
|
-
// Enable session local storage for Sync
|
184
|
-
_this.options.Sync = _this.options.Sync || {};
|
185
|
-
if (typeof _this.options.Sync.enableSessionStorage === 'undefined') {
|
186
|
-
_this.options.Sync.enableSessionStorage = true;
|
187
|
-
}
|
188
|
-
if (_this.options.region) {
|
189
|
-
_this.options.Sync.region = _this.options.region;
|
190
|
-
}
|
191
|
-
if (!token) {
|
192
|
-
throw new Error('A valid Twilio token should be provided');
|
193
|
-
}
|
194
|
-
_this.services = new ClientServices();
|
195
|
-
_this.config = new configuration_1.Configuration(_this.options);
|
196
|
-
_this.options.twilsockClient = _this.options.twilsockClient || new twilsock_1.Twilsock(token, productId, _this.options);
|
197
|
-
_this.options.transport = _this.options.transport || _this.options.twilsockClient;
|
198
|
-
_this.options.notificationsClient = _this.options.notificationsClient || new twilio_notifications_1.Notifications(token, _this.options);
|
199
|
-
_this.options.syncClient = _this.options.syncClient || new twilio_sync_1.SyncClient(token, _this.options);
|
200
|
-
_this.services.syncClient = _this.options.syncClient;
|
201
|
-
_this.services.transport = _this.options.transport;
|
202
|
-
_this.services.twilsockClient = _this.options.twilsockClient;
|
203
|
-
_this.services.notificationClient = _this.options.notificationsClient;
|
204
|
-
_this.services.session = new session_1.Session(_this.services, _this.config);
|
205
|
-
_this.sessionPromise = _this.services.session.initialize();
|
206
|
-
_this.services.network = new network_1.Network(_this.config, _this.services);
|
207
|
-
_this.services.users = new users_1.Users({
|
208
|
-
session: _this.services.session,
|
209
|
-
network: _this.services.network,
|
210
|
-
syncClient: _this.services.syncClient
|
211
|
-
});
|
212
|
-
_this.services.users.on('userSubscribed', _this.emit.bind(_this, 'userSubscribed'));
|
213
|
-
_this.services.users.on('userUpdated', function (args) {
|
214
|
-
return _this.emit('userUpdated', args);
|
215
|
-
});
|
216
|
-
_this.services.users.on('userUnsubscribed', _this.emit.bind(_this, 'userUnsubscribed'));
|
217
|
-
_this.services.twilsockClient.on('tokenAboutToExpire', function (ttl) {
|
218
|
-
return _this.emit('tokenAboutToExpire', ttl);
|
219
|
-
});
|
220
|
-
_this.services.twilsockClient.on('tokenExpired', function () {
|
221
|
-
return _this.emit('tokenExpired');
|
222
|
-
});
|
223
|
-
_this.services.twilsockClient.on('connectionError', function (error) {
|
224
|
-
return _this.emit('connectionError', error);
|
225
|
-
});
|
226
|
-
_this.services.readHorizon = new readhorizon_1.ReadHorizon(_this.services);
|
227
|
-
_this.services.typingIndicator = new typingindicator_1.TypingIndicator(_this.config, {
|
228
|
-
transport: _this.services.twilsockClient,
|
229
|
-
notificationClient: _this.services.notificationClient
|
230
|
-
}, _this.getConversationBySid.bind(_this));
|
231
|
-
_this.services.syncList = new synclist_1.SyncList(_this.services);
|
232
|
-
_this.conversations = new conversations_1.Conversations(_this.services);
|
233
|
-
_this.conversationsPromise = _this.sessionPromise.then(function () {
|
234
|
-
_this.conversations.on('conversationAdded', _this.emit.bind(_this, 'conversationAdded'));
|
235
|
-
_this.conversations.on('conversationRemoved', _this.emit.bind(_this, 'conversationRemoved'));
|
236
|
-
_this.conversations.on('conversationJoined', _this.emit.bind(_this, 'conversationJoined'));
|
237
|
-
_this.conversations.on('conversationLeft', _this.emit.bind(_this, 'conversationLeft'));
|
238
|
-
_this.conversations.on('conversationUpdated', function (args) {
|
239
|
-
return _this.emit('conversationUpdated', args);
|
240
|
-
});
|
241
|
-
_this.conversations.on('participantJoined', _this.emit.bind(_this, 'participantJoined'));
|
242
|
-
_this.conversations.on('participantLeft', _this.emit.bind(_this, 'participantLeft'));
|
243
|
-
_this.conversations.on('participantUpdated', function (args) {
|
244
|
-
return _this.emit('participantUpdated', args);
|
245
|
-
});
|
246
|
-
_this.conversations.on('messageAdded', _this.emit.bind(_this, 'messageAdded'));
|
247
|
-
_this.conversations.on('messageUpdated', function (args) {
|
248
|
-
return _this.emit('messageUpdated', args);
|
249
|
-
});
|
250
|
-
_this.conversations.on('messageRemoved', _this.emit.bind(_this, 'messageRemoved'));
|
251
|
-
_this.conversations.on('typingStarted', _this.emit.bind(_this, 'typingStarted'));
|
252
|
-
_this.conversations.on('typingEnded', _this.emit.bind(_this, 'typingEnded'));
|
253
|
-
return _this.conversations.fetchConversations();
|
254
|
-
}).then(function () {
|
255
|
-
return _this.conversations;
|
256
|
-
});
|
257
|
-
_this.services.notificationClient.on('connectionStateChanged', function (state) {
|
258
|
-
var changedConnectionState = null;
|
259
|
-
switch (state) {
|
260
|
-
case 'connected':
|
261
|
-
changedConnectionState = 'connected';
|
262
|
-
break;
|
263
|
-
case 'denied':
|
264
|
-
changedConnectionState = 'denied';
|
265
|
-
break;
|
266
|
-
case 'disconnecting':
|
267
|
-
changedConnectionState = 'disconnecting';
|
268
|
-
break;
|
269
|
-
case 'disconnected':
|
270
|
-
changedConnectionState = 'disconnected';
|
271
|
-
break;
|
272
|
-
default:
|
273
|
-
changedConnectionState = 'connecting';
|
274
|
-
}
|
275
|
-
if (changedConnectionState !== _this.connectionState) {
|
276
|
-
_this.connectionState = changedConnectionState;
|
277
|
-
_this.emit('connectionStateChanged', _this.connectionState);
|
278
|
-
}
|
279
|
-
});
|
280
|
-
_this.fpaToken = token;
|
281
|
-
return _this;
|
282
|
-
}
|
283
|
-
/**
|
284
|
-
* Factory method to create Conversations client instance.
|
285
|
-
*
|
286
|
-
* @param {String} token - Access token
|
287
|
-
* @param {Client#ClientOptions} [options] - Options to customize the Client
|
288
|
-
* @returns {Promise<Client>}
|
289
|
-
*/
|
290
|
-
|
291
|
-
|
292
|
-
(0, _createClass3.default)(Client, [{
|
293
|
-
key: "subscribeToPushNotifications",
|
294
|
-
value: function subscribeToPushNotifications(channelType) {
|
295
|
-
var _this2 = this;
|
296
|
-
|
297
|
-
var subscriptions = [];
|
298
|
-
[notificationtypes_1.NotificationTypes.NEW_MESSAGE, notificationtypes_1.NotificationTypes.ADDED_TO_CONVERSATION, notificationtypes_1.NotificationTypes.REMOVED_FROM_CONVERSATION, notificationtypes_1.NotificationTypes.TYPING_INDICATOR, notificationtypes_1.NotificationTypes.CONSUMPTION_UPDATE].forEach(function (messageType) {
|
299
|
-
subscriptions.push(_this2.services.notificationClient.subscribe(messageType, channelType));
|
300
|
-
});
|
301
|
-
return _promise2.default.all(subscriptions);
|
302
|
-
}
|
303
|
-
}, {
|
304
|
-
key: "unsubscribeFromPushNotifications",
|
305
|
-
value: function unsubscribeFromPushNotifications(channelType) {
|
306
|
-
var _this3 = this;
|
307
|
-
|
308
|
-
var subscriptions = [];
|
309
|
-
[notificationtypes_1.NotificationTypes.NEW_MESSAGE, notificationtypes_1.NotificationTypes.ADDED_TO_CONVERSATION, notificationtypes_1.NotificationTypes.REMOVED_FROM_CONVERSATION, notificationtypes_1.NotificationTypes.TYPING_INDICATOR, notificationtypes_1.NotificationTypes.CONSUMPTION_UPDATE].forEach(function (messageType) {
|
310
|
-
subscriptions.push(_this3.services.notificationClient.unsubscribe(messageType, channelType));
|
311
|
-
});
|
312
|
-
return _promise2.default.all(subscriptions);
|
313
|
-
}
|
314
|
-
}, {
|
315
|
-
key: "initialize",
|
316
|
-
value: function () {
|
317
|
-
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
|
318
|
-
var _this4 = this;
|
319
|
-
|
320
|
-
var links, options;
|
321
|
-
return _regenerator2.default.wrap(function _callee$(_context) {
|
322
|
-
while (1) {
|
323
|
-
switch (_context.prev = _context.next) {
|
324
|
-
case 0:
|
325
|
-
_context.next = 2;
|
326
|
-
return this.sessionPromise;
|
327
|
-
|
328
|
-
case 2:
|
329
|
-
Client.supportedPushChannels.forEach(function (channelType) {
|
330
|
-
return _this4.subscribeToPushNotifications(channelType);
|
331
|
-
});
|
332
|
-
_context.next = 5;
|
333
|
-
return this.services.session.getSessionLinks();
|
334
|
-
|
335
|
-
case 5:
|
336
|
-
links = _context.sent;
|
337
|
-
options = (0, _assign2.default)(this.options);
|
338
|
-
|
339
|
-
options.transport = null;
|
340
|
-
this.services.mcsClient = new twilio_mcs_client_1.McsClient(this.fpaToken, links.mediaServiceUrl, links.mediaSetServiceUrl, options);
|
341
|
-
_context.next = 11;
|
342
|
-
return this.services.typingIndicator.initialize();
|
343
|
-
|
344
|
-
case 11:
|
345
|
-
case "end":
|
346
|
-
return _context.stop();
|
347
|
-
}
|
348
|
-
}
|
349
|
-
}, _callee, this);
|
350
|
-
}));
|
351
|
-
|
352
|
-
function initialize() {
|
353
|
-
return _ref.apply(this, arguments);
|
354
|
-
}
|
355
|
-
|
356
|
-
return initialize;
|
357
|
-
}()
|
358
|
-
/**
|
359
|
-
* Gracefully shutting down library instance.
|
360
|
-
* @public
|
361
|
-
* @returns {Promise<void>}
|
362
|
-
*/
|
363
|
-
|
364
|
-
}, {
|
365
|
-
key: "shutdown",
|
366
|
-
value: function () {
|
367
|
-
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
|
368
|
-
return _regenerator2.default.wrap(function _callee2$(_context2) {
|
369
|
-
while (1) {
|
370
|
-
switch (_context2.prev = _context2.next) {
|
371
|
-
case 0:
|
372
|
-
_context2.next = 2;
|
373
|
-
return this.services.twilsockClient.disconnect();
|
374
|
-
|
375
|
-
case 2:
|
376
|
-
case "end":
|
377
|
-
return _context2.stop();
|
378
|
-
}
|
379
|
-
}
|
380
|
-
}, _callee2, this);
|
381
|
-
}));
|
382
|
-
|
383
|
-
function shutdown() {
|
384
|
-
return _ref2.apply(this, arguments);
|
385
|
-
}
|
386
|
-
|
387
|
-
return shutdown;
|
388
|
-
}()
|
389
|
-
/**
|
390
|
-
* Update the token used by the Client and re-register with Conversations services.
|
391
|
-
* @param {String} token - Access token
|
392
|
-
* @public
|
393
|
-
* @returns {Promise<Client>}
|
394
|
-
*/
|
395
|
-
|
396
|
-
}, {
|
397
|
-
key: "updateToken",
|
398
|
-
value: function () {
|
399
|
-
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(token) {
|
400
|
-
var _this5 = this;
|
401
|
-
|
402
|
-
return _regenerator2.default.wrap(function _callee3$(_context3) {
|
403
|
-
while (1) {
|
404
|
-
switch (_context3.prev = _context3.next) {
|
405
|
-
case 0:
|
406
|
-
log.info('updateToken');
|
407
|
-
|
408
|
-
if (!(this.fpaToken === token)) {
|
409
|
-
_context3.next = 3;
|
410
|
-
break;
|
411
|
-
}
|
412
|
-
|
413
|
-
return _context3.abrupt("return", this);
|
414
|
-
|
415
|
-
case 3:
|
416
|
-
_context3.next = 5;
|
417
|
-
return this.services.twilsockClient.updateToken(token).then(function () {
|
418
|
-
return _this5.fpaToken = token;
|
419
|
-
}).then(function () {
|
420
|
-
return _this5.services.mcsClient.updateToken(token);
|
421
|
-
}).then(function () {
|
422
|
-
return _this5.sessionPromise;
|
423
|
-
});
|
424
|
-
|
425
|
-
case 5:
|
426
|
-
return _context3.abrupt("return", this);
|
427
|
-
|
428
|
-
case 6:
|
429
|
-
case "end":
|
430
|
-
return _context3.stop();
|
431
|
-
}
|
432
|
-
}
|
433
|
-
}, _callee3, this);
|
434
|
-
}));
|
435
|
-
|
436
|
-
function updateToken(_x) {
|
437
|
-
return _ref3.apply(this, arguments);
|
438
|
-
}
|
439
|
-
|
440
|
-
return updateToken;
|
441
|
-
}()
|
442
|
-
/**
|
443
|
-
* Get a known Conversation by its SID.
|
444
|
-
* @param {String} conversationSid - Conversation sid
|
445
|
-
* @returns {Promise<Conversation>}
|
446
|
-
*/
|
447
|
-
|
448
|
-
}, {
|
449
|
-
key: "getConversationBySid",
|
450
|
-
value: function () {
|
451
|
-
var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(conversationSid) {
|
452
|
-
var conversation;
|
453
|
-
return _regenerator2.default.wrap(function _callee4$(_context4) {
|
454
|
-
while (1) {
|
455
|
-
switch (_context4.prev = _context4.next) {
|
456
|
-
case 0:
|
457
|
-
_context4.next = 2;
|
458
|
-
return this.conversations.syncListRead.promise;
|
459
|
-
|
460
|
-
case 2:
|
461
|
-
_context4.next = 4;
|
462
|
-
return this.conversations.getConversation(conversationSid);
|
463
|
-
|
464
|
-
case 4:
|
465
|
-
conversation = _context4.sent;
|
466
|
-
|
467
|
-
if (conversation) {
|
468
|
-
_context4.next = 9;
|
469
|
-
break;
|
470
|
-
}
|
471
|
-
|
472
|
-
_context4.next = 8;
|
473
|
-
return this.conversations.getWhisperConversation(conversationSid);
|
474
|
-
|
475
|
-
case 8:
|
476
|
-
conversation = _context4.sent;
|
477
|
-
|
478
|
-
case 9:
|
479
|
-
if (conversation) {
|
480
|
-
_context4.next = 11;
|
481
|
-
break;
|
482
|
-
}
|
483
|
-
|
484
|
-
throw new Error("Conversation with SID " + conversationSid + " is not found.");
|
485
|
-
|
486
|
-
case 11:
|
487
|
-
return _context4.abrupt("return", conversation);
|
488
|
-
|
489
|
-
case 12:
|
490
|
-
case "end":
|
491
|
-
return _context4.stop();
|
492
|
-
}
|
493
|
-
}
|
494
|
-
}, _callee4, this);
|
495
|
-
}));
|
496
|
-
|
497
|
-
function getConversationBySid(_x2) {
|
498
|
-
return _ref4.apply(this, arguments);
|
499
|
-
}
|
500
|
-
|
501
|
-
return getConversationBySid;
|
502
|
-
}()
|
503
|
-
/**
|
504
|
-
* Get a known Conversation by its unique identifier name.
|
505
|
-
* @param {String} uniqueName - The unique identifier name of the Conversation to get
|
506
|
-
* @returns {Promise<Conversation>}
|
507
|
-
*/
|
508
|
-
|
509
|
-
}, {
|
510
|
-
key: "getConversationByUniqueName",
|
511
|
-
value: function () {
|
512
|
-
var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5(uniqueName) {
|
513
|
-
var conversation;
|
514
|
-
return _regenerator2.default.wrap(function _callee5$(_context5) {
|
515
|
-
while (1) {
|
516
|
-
switch (_context5.prev = _context5.next) {
|
517
|
-
case 0:
|
518
|
-
_context5.next = 2;
|
519
|
-
return this.conversations.syncListRead.promise;
|
520
|
-
|
521
|
-
case 2:
|
522
|
-
_context5.next = 4;
|
523
|
-
return this.conversations.getConversationByUniqueName(uniqueName);
|
524
|
-
|
525
|
-
case 4:
|
526
|
-
conversation = _context5.sent;
|
527
|
-
|
528
|
-
if (conversation) {
|
529
|
-
_context5.next = 7;
|
530
|
-
break;
|
531
|
-
}
|
532
|
-
|
533
|
-
throw new Error("Conversation with unique name " + uniqueName + " is not found.");
|
534
|
-
|
535
|
-
case 7:
|
536
|
-
return _context5.abrupt("return", conversation);
|
537
|
-
|
538
|
-
case 8:
|
539
|
-
case "end":
|
540
|
-
return _context5.stop();
|
541
|
-
}
|
542
|
-
}
|
543
|
-
}, _callee5, this);
|
544
|
-
}));
|
545
|
-
|
546
|
-
function getConversationByUniqueName(_x3) {
|
547
|
-
return _ref5.apply(this, arguments);
|
548
|
-
}
|
549
|
-
|
550
|
-
return getConversationByUniqueName;
|
551
|
-
}()
|
552
|
-
/**
|
553
|
-
* Get the current list of all subscribed Conversations.
|
554
|
-
* @returns {Promise<Paginator<Conversation>>}
|
555
|
-
*/
|
556
|
-
|
557
|
-
}, {
|
558
|
-
key: "getSubscribedConversations",
|
559
|
-
value: function getSubscribedConversations(args) {
|
560
|
-
return this.conversationsPromise.then(function (conversations) {
|
561
|
-
return conversations.getConversations(args);
|
562
|
-
});
|
563
|
-
}
|
564
|
-
/**
|
565
|
-
* Create a Conversation on the server and subscribe to its events.
|
566
|
-
* The default is a Conversation with an empty friendlyName.
|
567
|
-
* @param {Client#CreateConversationOptions} [options] - Options for the Conversation
|
568
|
-
* @returns {Promise<Conversation>}
|
569
|
-
*/
|
570
|
-
|
571
|
-
}, {
|
572
|
-
key: "createConversation",
|
573
|
-
value: function createConversation(options) {
|
574
|
-
options = options || {};
|
575
|
-
return this.conversationsPromise.then(function (conversationsEntity) {
|
576
|
-
return conversationsEntity.addConversation(options);
|
577
|
-
});
|
578
|
-
}
|
579
|
-
/**
|
580
|
-
* Registers for push notifications.
|
581
|
-
* @param {Client#NotificationsChannelType} channelType - 'apn' and 'fcm' are supported
|
582
|
-
* @param {string} registrationId - Push notification id provided by the platform
|
583
|
-
* @returns {Promise<void>}
|
584
|
-
*/
|
585
|
-
|
586
|
-
}, {
|
587
|
-
key: "setPushRegistrationId",
|
588
|
-
value: function () {
|
589
|
-
var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6(channelType, registrationId) {
|
590
|
-
var _this6 = this;
|
591
|
-
|
592
|
-
return _regenerator2.default.wrap(function _callee6$(_context6) {
|
593
|
-
while (1) {
|
594
|
-
switch (_context6.prev = _context6.next) {
|
595
|
-
case 0:
|
596
|
-
_context6.next = 2;
|
597
|
-
return this.subscribeToPushNotifications(channelType).then(function () {
|
598
|
-
return _this6.services.notificationClient.setPushRegistrationId(registrationId, channelType);
|
599
|
-
});
|
600
|
-
|
601
|
-
case 2:
|
602
|
-
case "end":
|
603
|
-
return _context6.stop();
|
604
|
-
}
|
605
|
-
}
|
606
|
-
}, _callee6, this);
|
607
|
-
}));
|
608
|
-
|
609
|
-
function setPushRegistrationId(_x4, _x5) {
|
610
|
-
return _ref6.apply(this, arguments);
|
611
|
-
}
|
612
|
-
|
613
|
-
return setPushRegistrationId;
|
614
|
-
}()
|
615
|
-
/**
|
616
|
-
* Unregisters from push notifications.
|
617
|
-
* @param {Client#NotificationsChannelType} channelType - 'apn' and 'fcm' are supported
|
618
|
-
* @returns {Promise<void>}
|
619
|
-
*/
|
620
|
-
|
621
|
-
}, {
|
622
|
-
key: "unsetPushRegistrationId",
|
623
|
-
value: function () {
|
624
|
-
var _ref7 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7(channelType) {
|
625
|
-
return _regenerator2.default.wrap(function _callee7$(_context7) {
|
626
|
-
while (1) {
|
627
|
-
switch (_context7.prev = _context7.next) {
|
628
|
-
case 0:
|
629
|
-
if (!(Client.supportedPushChannels.indexOf(channelType) === -1)) {
|
630
|
-
_context7.next = 2;
|
631
|
-
break;
|
632
|
-
}
|
633
|
-
|
634
|
-
throw new Error('Invalid or unsupported channelType: ' + channelType);
|
635
|
-
|
636
|
-
case 2:
|
637
|
-
_context7.next = 4;
|
638
|
-
return this.unsubscribeFromPushNotifications(channelType);
|
639
|
-
|
640
|
-
case 4:
|
641
|
-
case "end":
|
642
|
-
return _context7.stop();
|
643
|
-
}
|
644
|
-
}
|
645
|
-
}, _callee7, this);
|
646
|
-
}));
|
647
|
-
|
648
|
-
function unsetPushRegistrationId(_x6) {
|
649
|
-
return _ref7.apply(this, arguments);
|
650
|
-
}
|
651
|
-
|
652
|
-
return unsetPushRegistrationId;
|
653
|
-
}()
|
654
|
-
}, {
|
655
|
-
key: "handlePushNotification",
|
656
|
-
|
657
|
-
/**
|
658
|
-
* Handle push notification payload parsing and emits event {@link Client#event:pushNotification} on this {@link Client} instance.
|
659
|
-
* @param {Object} notificationPayload - Push notification payload
|
660
|
-
* @returns {Promise<void>}
|
661
|
-
*/
|
662
|
-
value: function () {
|
663
|
-
var _ref8 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(notificationPayload) {
|
664
|
-
return _regenerator2.default.wrap(function _callee8$(_context8) {
|
665
|
-
while (1) {
|
666
|
-
switch (_context8.prev = _context8.next) {
|
667
|
-
case 0:
|
668
|
-
log.debug('handlePushNotification, notificationPayload=', notificationPayload);
|
669
|
-
this.emit('pushNotification', Client.parsePushNotification(notificationPayload));
|
670
|
-
|
671
|
-
case 2:
|
672
|
-
case "end":
|
673
|
-
return _context8.stop();
|
674
|
-
}
|
675
|
-
}
|
676
|
-
}, _callee8, this);
|
677
|
-
}));
|
678
|
-
|
679
|
-
function handlePushNotification(_x7) {
|
680
|
-
return _ref8.apply(this, arguments);
|
681
|
-
}
|
682
|
-
|
683
|
-
return handlePushNotification;
|
684
|
-
}()
|
685
|
-
/**
|
686
|
-
* Gets user for given identity, if it's in subscribed list - then return the user object from it,
|
687
|
-
* if not - then subscribes and adds user to the subscribed list.
|
688
|
-
* @param {String} identity - Identity of User
|
689
|
-
* @returns {Promise<User>} Fully initialized user
|
690
|
-
*/
|
691
|
-
|
692
|
-
}, {
|
693
|
-
key: "getUser",
|
694
|
-
value: function getUser(identity) {
|
695
|
-
return this.services.users.getUser(identity);
|
696
|
-
}
|
697
|
-
/**
|
698
|
-
* @returns {Promise<Array<User>>} List of subscribed User objects
|
699
|
-
*/
|
700
|
-
|
701
|
-
}, {
|
702
|
-
key: "getSubscribedUsers",
|
703
|
-
value: function () {
|
704
|
-
var _ref9 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9() {
|
705
|
-
return _regenerator2.default.wrap(function _callee9$(_context9) {
|
706
|
-
while (1) {
|
707
|
-
switch (_context9.prev = _context9.next) {
|
708
|
-
case 0:
|
709
|
-
return _context9.abrupt("return", this.services.users.getSubscribedUsers());
|
710
|
-
|
711
|
-
case 1:
|
712
|
-
case "end":
|
713
|
-
return _context9.stop();
|
714
|
-
}
|
715
|
-
}
|
716
|
-
}, _callee9, this);
|
717
|
-
}));
|
718
|
-
|
719
|
-
function getSubscribedUsers() {
|
720
|
-
return _ref9.apply(this, arguments);
|
721
|
-
}
|
722
|
-
|
723
|
-
return getSubscribedUsers;
|
724
|
-
}()
|
725
|
-
}, {
|
726
|
-
key: "user",
|
727
|
-
get: function get() {
|
728
|
-
return this.services.users.myself;
|
729
|
-
}
|
730
|
-
}, {
|
731
|
-
key: "reachabilityEnabled",
|
732
|
-
get: function get() {
|
733
|
-
return this.services.session.reachabilityEnabled;
|
734
|
-
}
|
735
|
-
}, {
|
736
|
-
key: "token",
|
737
|
-
get: function get() {
|
738
|
-
return this.fpaToken;
|
739
|
-
}
|
740
|
-
}], [{
|
741
|
-
key: "create",
|
742
|
-
value: function () {
|
743
|
-
var _ref10 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10(token, options) {
|
744
|
-
var client, startupEvent;
|
745
|
-
return _regenerator2.default.wrap(function _callee10$(_context10) {
|
746
|
-
while (1) {
|
747
|
-
switch (_context10.prev = _context10.next) {
|
748
|
-
case 0:
|
749
|
-
client = new Client(token, options);
|
750
|
-
startupEvent = 'conversations.client.startup';
|
751
|
-
|
752
|
-
client.services.twilsockClient.addPartialTelemetryEvent(new telemetrytracker_1.TelemetryEventDescription(startupEvent, 'Conversations client startup', new Date()), startupEvent, telemetrytracker_1.TelemetryPoint.Start);
|
753
|
-
_context10.next = 5;
|
754
|
-
return client.initialize();
|
755
|
-
|
756
|
-
case 5:
|
757
|
-
client.services.twilsockClient.addPartialTelemetryEvent(new telemetrytracker_1.TelemetryEventDescription('', '', new Date()), startupEvent, telemetrytracker_1.TelemetryPoint.End);
|
758
|
-
return _context10.abrupt("return", client);
|
759
|
-
|
760
|
-
case 7:
|
761
|
-
case "end":
|
762
|
-
return _context10.stop();
|
763
|
-
}
|
764
|
-
}
|
765
|
-
}, _callee10, this);
|
766
|
-
}));
|
767
|
-
|
768
|
-
function create(_x8, _x9) {
|
769
|
-
return _ref10.apply(this, arguments);
|
770
|
-
}
|
771
|
-
|
772
|
-
return create;
|
773
|
-
}()
|
774
|
-
}, {
|
775
|
-
key: "parsePushNotificationChatData",
|
776
|
-
value: function parsePushNotificationChatData(data) {
|
777
|
-
var result = {};
|
778
|
-
for (var key in Client.supportedPushDataFields) {
|
779
|
-
if (typeof data[key] !== 'undefined' && data[key] !== null) {
|
780
|
-
if (key === 'message_index') {
|
781
|
-
if (util_1.parseToNumber(data[key]) !== null) {
|
782
|
-
result[Client.supportedPushDataFields[key]] = Number(data[key]);
|
783
|
-
}
|
784
|
-
} else {
|
785
|
-
result[Client.supportedPushDataFields[key]] = data[key];
|
786
|
-
}
|
787
|
-
}
|
788
|
-
}
|
789
|
-
return result;
|
790
|
-
}
|
791
|
-
/**
|
792
|
-
* Static method for push notification payload parsing. Returns parsed push as {@link PushNotification} object
|
793
|
-
* @param {Object} notificationPayload - Push notification payload
|
794
|
-
* @returns {PushNotification|Error}
|
795
|
-
*/
|
796
|
-
|
797
|
-
}, {
|
798
|
-
key: "parsePushNotification",
|
799
|
-
value: function parsePushNotification(notificationPayload) {
|
800
|
-
log.debug('parsePushNotification, notificationPayload=', notificationPayload);
|
801
|
-
// APNS specifics
|
802
|
-
if (typeof notificationPayload.aps !== 'undefined') {
|
803
|
-
if (!notificationPayload.twi_message_type) {
|
804
|
-
throw new Error('Provided push notification payload does not contain Programmable Chat push notification type');
|
805
|
-
}
|
806
|
-
var data = Client.parsePushNotificationChatData(notificationPayload);
|
807
|
-
var apsPayload = notificationPayload.aps;
|
808
|
-
var body = null;
|
809
|
-
var title = null;
|
810
|
-
if (typeof apsPayload.alert === 'string') {
|
811
|
-
body = apsPayload.alert || null;
|
812
|
-
} else {
|
813
|
-
body = apsPayload.alert.body || null;
|
814
|
-
title = apsPayload.alert.title || null;
|
815
|
-
}
|
816
|
-
return new pushnotification_1.PushNotification({
|
817
|
-
title: title,
|
818
|
-
body: body,
|
819
|
-
sound: apsPayload.sound || null,
|
820
|
-
badge: apsPayload.badge || null,
|
821
|
-
action: apsPayload.category || null,
|
822
|
-
type: notificationPayload.twi_message_type,
|
823
|
-
data: data
|
824
|
-
});
|
825
|
-
}
|
826
|
-
// FCM specifics
|
827
|
-
if (typeof notificationPayload.data !== 'undefined') {
|
828
|
-
var dataPayload = notificationPayload.data;
|
829
|
-
if (!dataPayload.twi_message_type) {
|
830
|
-
throw new Error('Provided push notification payload does not contain Programmable Chat push notification type');
|
831
|
-
}
|
832
|
-
var _data = Client.parsePushNotificationChatData(notificationPayload.data);
|
833
|
-
return new pushnotification_1.PushNotification({
|
834
|
-
title: dataPayload.twi_title || null,
|
835
|
-
body: dataPayload.twi_body || null,
|
836
|
-
sound: dataPayload.twi_sound || null,
|
837
|
-
badge: null,
|
838
|
-
action: dataPayload.twi_action || null,
|
839
|
-
type: dataPayload.twi_message_type,
|
840
|
-
data: _data
|
841
|
-
});
|
842
|
-
}
|
843
|
-
throw new Error('Provided push notification payload is not Programmable Chat notification');
|
844
|
-
}
|
845
|
-
}]);
|
846
|
-
return Client;
|
847
|
-
}(events_1.EventEmitter);
|
848
|
-
|
849
|
-
Client.version = SDK_VERSION;
|
850
|
-
Client.supportedPushChannels = ['fcm', 'apn'];
|
851
|
-
Client.supportedPushDataFields = {
|
852
|
-
'conversation_sid': 'conversationSid',
|
853
|
-
'message_sid': 'messageSid',
|
854
|
-
'message_index': 'messageIndex'
|
855
|
-
};
|
856
|
-
__decorate([twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", _promise2.default)], Client.prototype, "updateToken", null);
|
857
|
-
__decorate([twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", _promise2.default)], Client.prototype, "getConversationBySid", null);
|
858
|
-
__decorate([twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", _promise2.default)], Client.prototype, "getConversationByUniqueName", null);
|
859
|
-
__decorate([twilio_sdk_type_validator_1.validateTypesAsync(['undefined', twilio_sdk_type_validator_1.objectSchema('conversation options', {
|
860
|
-
friendlyName: ['string', 'undefined'],
|
861
|
-
isPrivate: ['boolean', 'undefined'],
|
862
|
-
uniqueName: ['string', 'undefined']
|
863
|
-
})]), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", _promise2.default)], Client.prototype, "createConversation", null);
|
864
|
-
__decorate([twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.literal('fcm', 'apn'), 'string'), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String]), __metadata("design:returntype", _promise2.default)], Client.prototype, "setPushRegistrationId", null);
|
865
|
-
__decorate([twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.literal('fcm', 'apn')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", _promise2.default)], Client.prototype, "unsetPushRegistrationId", null);
|
866
|
-
__decorate([twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.pureObject), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", _promise2.default)], Client.prototype, "handlePushNotification", null);
|
867
|
-
__decorate([twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", _promise2.default)], Client.prototype, "getUser", null);
|
868
|
-
__decorate([twilio_sdk_type_validator_1.validateTypesAsync('string', ['undefined', twilio_sdk_type_validator_1.pureObject]), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", _promise2.default)], Client, "create", null);
|
869
|
-
__decorate([twilio_sdk_type_validator_1.validateTypes(twilio_sdk_type_validator_1.pureObject), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", pushnotification_1.PushNotification)], Client, "parsePushNotification", null);
|
870
|
-
exports.Client = Client;
|
871
|
-
exports.default = Client;
|
872
|
-
/**
|
873
|
-
* Fired when a Conversation becomes visible to the Client. The event is also triggered when the client creates a new Conversation.
|
874
|
-
* Fired for all conversations Client has joined.
|
875
|
-
* @event Client#conversationAdded
|
876
|
-
* @type {Conversation}
|
877
|
-
*/
|
878
|
-
/**
|
879
|
-
* Fired when the Client joins a Conversation.
|
880
|
-
* @event Client#conversationJoined
|
881
|
-
* @type {Conversation}
|
882
|
-
*/
|
883
|
-
/**
|
884
|
-
* Fired when the Client leaves a Conversation.
|
885
|
-
* @event Client#conversationLeft
|
886
|
-
* @type {Conversation}
|
887
|
-
*/
|
888
|
-
/**
|
889
|
-
* Fired when a Conversation is no longer visible to the Client.
|
890
|
-
* @event Client#conversationRemoved
|
891
|
-
* @type {Conversation}
|
892
|
-
*/
|
893
|
-
/**
|
894
|
-
* Fired when a Conversation's attributes or metadata have been updated.
|
895
|
-
* During Conversation's {@link Client.create| creation and initialization} this event might be fired multiple times
|
896
|
-
* for same joined or created Conversation as new data is arriving from different sources.
|
897
|
-
* @event Client#conversationUpdated
|
898
|
-
* @type {Object}
|
899
|
-
* @property {Conversation} conversation - Updated Conversation
|
900
|
-
* @property {Conversation#UpdateReason[]} updateReasons - Array of Conversation's updated event reasons
|
901
|
-
*/
|
902
|
-
/**
|
903
|
-
* Fired when Client's connection state has been changed.
|
904
|
-
* @event Client#connectionStateChanged
|
905
|
-
* @type {Client#ConnectionState}
|
906
|
-
*/
|
907
|
-
/**
|
908
|
-
* Fired when a Participant has joined the Conversation.
|
909
|
-
* @event Client#participantJoined
|
910
|
-
* @type {Participant}
|
911
|
-
*/
|
912
|
-
/**
|
913
|
-
* Fired when a Participant has left the Conversation.
|
914
|
-
* @event Client#participantLeft
|
915
|
-
* @type {Participant}
|
916
|
-
*/
|
917
|
-
/**
|
918
|
-
* Fired when a Participant's fields has been updated.
|
919
|
-
* @event Client#participantUpdated
|
920
|
-
* @type {Object}
|
921
|
-
* @property {Participant} participant - Updated Participant
|
922
|
-
* @property {Participant#UpdateReason[]} updateReasons - Array of Participant's updated event reasons
|
923
|
-
*/
|
924
|
-
/**
|
925
|
-
* Fired when a new Message has been added to the Conversation on the server.
|
926
|
-
* @event Client#messageAdded
|
927
|
-
* @type {Message}
|
928
|
-
*/
|
929
|
-
/**
|
930
|
-
* Fired when Message is removed from Conversation's message list.
|
931
|
-
* @event Client#messageRemoved
|
932
|
-
* @type {Message}
|
933
|
-
*/
|
934
|
-
/**
|
935
|
-
* Fired when an existing Message's fields are updated with new values.
|
936
|
-
* @event Client#messageUpdated
|
937
|
-
* @type {Object}
|
938
|
-
* @property {Message} message - Updated Message
|
939
|
-
* @property {Message#UpdateReason[]} updateReasons - Array of Message's updated event reasons
|
940
|
-
*/
|
941
|
-
/**
|
942
|
-
* Fired when token is about to expire and needs to be updated.
|
943
|
-
* @event Client#tokenAboutToExpire
|
944
|
-
* @type {void}
|
945
|
-
*/
|
946
|
-
/**
|
947
|
-
* Fired when token is expired.
|
948
|
-
* @event Client#tokenExpired
|
949
|
-
* @type {void}
|
950
|
-
*/
|
951
|
-
/**
|
952
|
-
* Fired when a Participant has stopped typing.
|
953
|
-
* @event Client#typingEnded
|
954
|
-
* @type {Participant}
|
955
|
-
*/
|
956
|
-
/**
|
957
|
-
* Fired when a Participant has started typing.
|
958
|
-
* @event Client#typingStarted
|
959
|
-
* @type {Participant}
|
960
|
-
*/
|
961
|
-
/**
|
962
|
-
* Fired when client received (and parsed) push notification via one of push channels (apn or fcm).
|
963
|
-
* @event Client#pushNotification
|
964
|
-
* @type {PushNotification}
|
965
|
-
*/
|
966
|
-
/**
|
967
|
-
* Fired when the Client is subscribed to a User.
|
968
|
-
* @event Client#userSubscribed
|
969
|
-
* @type {User}
|
970
|
-
*/
|
971
|
-
/**
|
972
|
-
* Fired when the Client is unsubscribed from a User.
|
973
|
-
* @event Client#userUnsubscribed
|
974
|
-
* @type {User}
|
975
|
-
*/
|
976
|
-
/**
|
977
|
-
* Fired when the User's properties or reachability status have been updated.
|
978
|
-
* @event Client#userUpdated
|
979
|
-
* @type {Object}
|
980
|
-
* @property {User} user - Updated User
|
981
|
-
* @property {User#UpdateReason[]} updateReasons - Array of User's updated event reasons
|
982
|
-
*/
|
983
|
-
/**
|
984
|
-
* Fired when connection is interrupted by unexpected reason
|
985
|
-
* @event Client#connectionError
|
986
|
-
* @type {Object}
|
987
|
-
* @property {Boolean} terminal - twilsock will stop connection attempts
|
988
|
-
* @property {String} message - root cause
|
989
|
-
* @property {Number} [httpStatusCode] - http status code if available
|
990
|
-
* @property {Number} [errorCode] - Twilio public error code if available
|
991
|
-
*/
|