1 | /*
|
2 | Copyright 2015, 2016 OpenMarket Ltd
|
3 | Copyright 2017 Vector Creations Ltd
|
4 |
|
5 | Licensed under the Apache License, Version 2.0 (the "License");
|
6 | you may not use this file except in compliance with the License.
|
7 | You may obtain a copy of the License at
|
8 |
|
9 | http://www.apache.org/licenses/LICENSE-2.0
|
10 |
|
11 | Unless required by applicable law or agreed to in writing, software
|
12 | distributed under the License is distributed on an "AS IS" BASIS,
|
13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 | See the License for the specific language governing permissions and
|
15 | limitations under the License.
|
16 | */
|
17 | ;
|
18 |
|
19 | /** The {@link module:ContentHelpers} object */
|
20 |
|
21 | module.exports.ContentHelpers = require("./content-helpers");
|
22 | /** The {@link module:models/event.MatrixEvent|MatrixEvent} class. */
|
23 | module.exports.MatrixEvent = require("./models/event").MatrixEvent;
|
24 | /** The {@link module:models/event.EventStatus|EventStatus} enum. */
|
25 | module.exports.EventStatus = require("./models/event").EventStatus;
|
26 | /** The {@link module:store/memory.MatrixInMemoryStore|MatrixInMemoryStore} class. */
|
27 | module.exports.MatrixInMemoryStore = require("./store/memory").MatrixInMemoryStore;
|
28 | /** The {@link module:store/indexeddb.IndexedDBStore|IndexedDBStore} class. */
|
29 | module.exports.IndexedDBStore = require("./store/indexeddb").IndexedDBStore;
|
30 | /** The {@link module:store/indexeddb.IndexedDBStoreBackend|IndexedDBStoreBackend} class. */
|
31 | module.exports.IndexedDBStoreBackend = require("./store/indexeddb").IndexedDBStoreBackend;
|
32 | /** The {@link module:sync-accumulator.SyncAccumulator|SyncAccumulator} class. */
|
33 | module.exports.SyncAccumulator = require("./sync-accumulator");
|
34 | /** The {@link module:http-api.MatrixHttpApi|MatrixHttpApi} class. */
|
35 | module.exports.MatrixHttpApi = require("./http-api").MatrixHttpApi;
|
36 | /** The {@link module:http-api.MatrixError|MatrixError} class. */
|
37 | module.exports.MatrixError = require("./http-api").MatrixError;
|
38 | /** The {@link module:errors.InvalidStoreError|InvalidStoreError} class. */
|
39 | module.exports.InvalidStoreError = require("./errors").InvalidStoreError;
|
40 | /** The {@link module:client.MatrixClient|MatrixClient} class. */
|
41 | module.exports.MatrixClient = require("./client").MatrixClient;
|
42 | /** The {@link module:models/room|Room} class. */
|
43 | module.exports.Room = require("./models/room");
|
44 | /** The {@link module:models/group|Group} class. */
|
45 | module.exports.Group = require("./models/group");
|
46 | /** The {@link module:models/event-timeline~EventTimeline} class. */
|
47 | module.exports.EventTimeline = require("./models/event-timeline");
|
48 | /** The {@link module:models/event-timeline-set~EventTimelineSet} class. */
|
49 | module.exports.EventTimelineSet = require("./models/event-timeline-set");
|
50 | /** The {@link module:models/room-member|RoomMember} class. */
|
51 | module.exports.RoomMember = require("./models/room-member");
|
52 | /** The {@link module:models/room-state~RoomState|RoomState} class. */
|
53 | module.exports.RoomState = require("./models/room-state");
|
54 | /** The {@link module:models/user~User|User} class. */
|
55 | module.exports.User = require("./models/user");
|
56 | /** The {@link module:scheduler~MatrixScheduler|MatrixScheduler} class. */
|
57 | module.exports.MatrixScheduler = require("./scheduler");
|
58 | /** The {@link module:store/session/webstorage~WebStorageSessionStore|
|
59 | * WebStorageSessionStore} class. <strong>Work in progress; unstable.</strong> */
|
60 | module.exports.WebStorageSessionStore = require("./store/session/webstorage");
|
61 | /** True if crypto libraries are being used on this client. */
|
62 | module.exports.CRYPTO_ENABLED = require("./client").CRYPTO_ENABLED;
|
63 | /** {@link module:content-repo|ContentRepo} utility functions. */
|
64 | module.exports.ContentRepo = require("./content-repo");
|
65 | /** The {@link module:filter~Filter|Filter} class. */
|
66 | module.exports.Filter = require("./filter");
|
67 | /** The {@link module:timeline-window~TimelineWindow} class. */
|
68 | module.exports.TimelineWindow = require("./timeline-window").TimelineWindow;
|
69 | /** The {@link module:interactive-auth} class. */
|
70 | module.exports.InteractiveAuth = require("./interactive-auth");
|
71 | /** The {@link module:auto-discovery|AutoDiscovery} class. */
|
72 | module.exports.AutoDiscovery = require("./autodiscovery").AutoDiscovery;
|
73 |
|
74 | module.exports.MemoryCryptoStore = require("./crypto/store/memory-crypto-store").default;
|
75 | module.exports.IndexedDBCryptoStore = require("./crypto/store/indexeddb-crypto-store").default;
|
76 |
|
77 | /**
|
78 | * Create a new Matrix Call.
|
79 | * @function
|
80 | * @param {module:client.MatrixClient} client The MatrixClient instance to use.
|
81 | * @param {string} roomId The room the call is in.
|
82 | * @return {module:webrtc/call~MatrixCall} The Matrix call or null if the browser
|
83 | * does not support WebRTC.
|
84 | */
|
85 | module.exports.createNewMatrixCall = require("./webrtc/call").createNewMatrixCall;
|
86 |
|
87 | /**
|
88 | * Set an audio output device to use for MatrixCalls
|
89 | * @function
|
90 | * @param {string=} deviceId the identifier for the device
|
91 | * undefined treated as unset
|
92 | */
|
93 | module.exports.setMatrixCallAudioOutput = require('./webrtc/call').setAudioOutput;
|
94 | /**
|
95 | * Set an audio input device to use for MatrixCalls
|
96 | * @function
|
97 | * @param {string=} deviceId the identifier for the device
|
98 | * undefined treated as unset
|
99 | */
|
100 | module.exports.setMatrixCallAudioInput = require('./webrtc/call').setAudioInput;
|
101 | /**
|
102 | * Set a video input device to use for MatrixCalls
|
103 | * @function
|
104 | * @param {string=} deviceId the identifier for the device
|
105 | * undefined treated as unset
|
106 | */
|
107 | module.exports.setMatrixCallVideoInput = require('./webrtc/call').setVideoInput;
|
108 |
|
109 | // expose the underlying request object so different environments can use
|
110 | // different request libs (e.g. request or browser-request)
|
111 | var request = void 0;
|
112 | /**
|
113 | * The function used to perform HTTP requests. Only use this if you want to
|
114 | * use a different HTTP library, e.g. Angular's <code>$http</code>. This should
|
115 | * be set prior to calling {@link createClient}.
|
116 | * @param {requestFunction} r The request function to use.
|
117 | */
|
118 | module.exports.request = function (r) {
|
119 | request = r;
|
120 | };
|
121 |
|
122 | /**
|
123 | * Return the currently-set request function.
|
124 | * @return {requestFunction} The current request function.
|
125 | */
|
126 | module.exports.getRequest = function () {
|
127 | return request;
|
128 | };
|
129 |
|
130 | /**
|
131 | * Apply wrapping code around the request function. The wrapper function is
|
132 | * installed as the new request handler, and when invoked it is passed the
|
133 | * previous value, along with the options and callback arguments.
|
134 | * @param {requestWrapperFunction} wrapper The wrapping function.
|
135 | */
|
136 | module.exports.wrapRequest = function (wrapper) {
|
137 | var origRequest = request;
|
138 | request = function request(options, callback) {
|
139 | return wrapper(origRequest, options, callback);
|
140 | };
|
141 | };
|
142 |
|
143 | var cryptoStoreFactory = function cryptoStoreFactory() {
|
144 | return new module.exports.MemoryCryptoStore();
|
145 | };
|
146 |
|
147 | /**
|
148 | * Configure a different factory to be used for creating crypto stores
|
149 | *
|
150 | * @param {Function} fac a function which will return a new
|
151 | * {@link module:crypto.store.base~CryptoStore}.
|
152 | */
|
153 | module.exports.setCryptoStoreFactory = function (fac) {
|
154 | cryptoStoreFactory = fac;
|
155 | };
|
156 |
|
157 | /**
|
158 | * Construct a Matrix Client. Similar to {@link module:client~MatrixClient}
|
159 | * except that the 'request', 'store' and 'scheduler' dependencies are satisfied.
|
160 | * @param {(Object|string)} opts The configuration options for this client. If
|
161 | * this is a string, it is assumed to be the base URL. These configuration
|
162 | * options will be passed directly to {@link module:client~MatrixClient}.
|
163 | * @param {Object} opts.store If not set, defaults to
|
164 | * {@link module:store/memory.MatrixInMemoryStore}.
|
165 | * @param {Object} opts.scheduler If not set, defaults to
|
166 | * {@link module:scheduler~MatrixScheduler}.
|
167 | * @param {requestFunction} opts.request If not set, defaults to the function
|
168 | * supplied to {@link request} which defaults to the request module from NPM.
|
169 | *
|
170 | * @param {module:crypto.store.base~CryptoStore=} opts.cryptoStore
|
171 | * crypto store implementation. Calls the factory supplied to
|
172 | * {@link setCryptoStoreFactory} if unspecified; or if no factory has been
|
173 | * specified, uses a default implementation (indexeddb in the browser,
|
174 | * in-memory otherwise).
|
175 | *
|
176 | * @return {MatrixClient} A new matrix client.
|
177 | * @see {@link module:client~MatrixClient} for the full list of options for
|
178 | * <code>opts</code>.
|
179 | */
|
180 | module.exports.createClient = function (opts) {
|
181 | if (typeof opts === "string") {
|
182 | opts = {
|
183 | "baseUrl": opts
|
184 | };
|
185 | }
|
186 | opts.request = opts.request || request;
|
187 | opts.store = opts.store || new module.exports.MatrixInMemoryStore({
|
188 | localStorage: global.localStorage
|
189 | });
|
190 | opts.scheduler = opts.scheduler || new module.exports.MatrixScheduler();
|
191 | opts.cryptoStore = opts.cryptoStore || cryptoStoreFactory();
|
192 | return new module.exports.MatrixClient(opts);
|
193 | };
|
194 |
|
195 | /**
|
196 | * The request function interface for performing HTTP requests. This matches the
|
197 | * API for the {@link https://github.com/request/request#requestoptions-callback|
|
198 | * request NPM module}. The SDK will attempt to call this function in order to
|
199 | * perform an HTTP request.
|
200 | * @callback requestFunction
|
201 | * @param {Object} opts The options for this HTTP request.
|
202 | * @param {string} opts.uri The complete URI.
|
203 | * @param {string} opts.method The HTTP method.
|
204 | * @param {Object} opts.qs The query parameters to append to the URI.
|
205 | * @param {Object} opts.body The JSON-serializable object.
|
206 | * @param {boolean} opts.json True if this is a JSON request.
|
207 | * @param {Object} opts._matrix_opts The underlying options set for
|
208 | * {@link MatrixHttpApi}.
|
209 | * @param {requestCallback} callback The request callback.
|
210 | */
|
211 |
|
212 | /**
|
213 | * A wrapper for the request function interface.
|
214 | * @callback requestWrapperFunction
|
215 | * @param {requestFunction} origRequest The underlying request function being
|
216 | * wrapped
|
217 | * @param {Object} opts The options for this HTTP request, given in the same
|
218 | * form as {@link requestFunction}.
|
219 | * @param {requestCallback} callback The request callback.
|
220 | */
|
221 |
|
222 | /**
|
223 | * The request callback interface for performing HTTP requests. This matches the
|
224 | * API for the {@link https://github.com/request/request#requestoptions-callback|
|
225 | * request NPM module}. The SDK will implement a callback which meets this
|
226 | * interface in order to handle the HTTP response.
|
227 | * @callback requestCallback
|
228 | * @param {Error} err The error if one occurred, else falsey.
|
229 | * @param {Object} response The HTTP response which consists of
|
230 | * <code>{statusCode: {Number}, headers: {Object}}</code>
|
231 | * @param {Object} body The parsed HTTP response body.
|
232 | */
|
233 | //# sourceMappingURL=matrix.js.map |
\ | No newline at end of file |