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 |
|
72 | module.exports.MemoryCryptoStore = require("./crypto/store/memory-crypto-store").default;
|
73 | module.exports.IndexedDBCryptoStore = require("./crypto/store/indexeddb-crypto-store").default;
|
74 |
|
75 | /**
|
76 | * Create a new Matrix Call.
|
77 | * @function
|
78 | * @param {module:client.MatrixClient} client The MatrixClient instance to use.
|
79 | * @param {string} roomId The room the call is in.
|
80 | * @return {module:webrtc/call~MatrixCall} The Matrix call or null if the browser
|
81 | * does not support WebRTC.
|
82 | */
|
83 | module.exports.createNewMatrixCall = require("./webrtc/call").createNewMatrixCall;
|
84 |
|
85 | /**
|
86 | * Set an audio output device to use for MatrixCalls
|
87 | * @function
|
88 | * @param {string=} deviceId the identifier for the device
|
89 | * undefined treated as unset
|
90 | */
|
91 | module.exports.setMatrixCallAudioOutput = require('./webrtc/call').setAudioOutput;
|
92 | /**
|
93 | * Set an audio input device to use for MatrixCalls
|
94 | * @function
|
95 | * @param {string=} deviceId the identifier for the device
|
96 | * undefined treated as unset
|
97 | */
|
98 | module.exports.setMatrixCallAudioInput = require('./webrtc/call').setAudioInput;
|
99 | /**
|
100 | * Set a video input device to use for MatrixCalls
|
101 | * @function
|
102 | * @param {string=} deviceId the identifier for the device
|
103 | * undefined treated as unset
|
104 | */
|
105 | module.exports.setMatrixCallVideoInput = require('./webrtc/call').setVideoInput;
|
106 |
|
107 | // expose the underlying request object so different environments can use
|
108 | // different request libs (e.g. request or browser-request)
|
109 | var request = void 0;
|
110 | /**
|
111 | * The function used to perform HTTP requests. Only use this if you want to
|
112 | * use a different HTTP library, e.g. Angular's <code>$http</code>. This should
|
113 | * be set prior to calling {@link createClient}.
|
114 | * @param {requestFunction} r The request function to use.
|
115 | */
|
116 | module.exports.request = function (r) {
|
117 | request = r;
|
118 | };
|
119 |
|
120 | /**
|
121 | * Return the currently-set request function.
|
122 | * @return {requestFunction} The current request function.
|
123 | */
|
124 | module.exports.getRequest = function () {
|
125 | return request;
|
126 | };
|
127 |
|
128 | /**
|
129 | * Apply wrapping code around the request function. The wrapper function is
|
130 | * installed as the new request handler, and when invoked it is passed the
|
131 | * previous value, along with the options and callback arguments.
|
132 | * @param {requestWrapperFunction} wrapper The wrapping function.
|
133 | */
|
134 | module.exports.wrapRequest = function (wrapper) {
|
135 | var origRequest = request;
|
136 | request = function request(options, callback) {
|
137 | return wrapper(origRequest, options, callback);
|
138 | };
|
139 | };
|
140 |
|
141 | var cryptoStoreFactory = function cryptoStoreFactory() {
|
142 | return new module.exports.MemoryCryptoStore();
|
143 | };
|
144 |
|
145 | /**
|
146 | * Configure a different factory to be used for creating crypto stores
|
147 | *
|
148 | * @param {Function} fac a function which will return a new
|
149 | * {@link module:crypto.store.base~CryptoStore}.
|
150 | */
|
151 | module.exports.setCryptoStoreFactory = function (fac) {
|
152 | cryptoStoreFactory = fac;
|
153 | };
|
154 |
|
155 | /**
|
156 | * Construct a Matrix Client. Similar to {@link module:client~MatrixClient}
|
157 | * except that the 'request', 'store' and 'scheduler' dependencies are satisfied.
|
158 | * @param {(Object|string)} opts The configuration options for this client. If
|
159 | * this is a string, it is assumed to be the base URL. These configuration
|
160 | * options will be passed directly to {@link module:client~MatrixClient}.
|
161 | * @param {Object} opts.store If not set, defaults to
|
162 | * {@link module:store/memory.MatrixInMemoryStore}.
|
163 | * @param {Object} opts.scheduler If not set, defaults to
|
164 | * {@link module:scheduler~MatrixScheduler}.
|
165 | * @param {requestFunction} opts.request If not set, defaults to the function
|
166 | * supplied to {@link request} which defaults to the request module from NPM.
|
167 | *
|
168 | * @param {module:crypto.store.base~CryptoStore=} opts.cryptoStore
|
169 | * crypto store implementation. Calls the factory supplied to
|
170 | * {@link setCryptoStoreFactory} if unspecified; or if no factory has been
|
171 | * specified, uses a default implementation (indexeddb in the browser,
|
172 | * in-memory otherwise).
|
173 | *
|
174 | * @return {MatrixClient} A new matrix client.
|
175 | * @see {@link module:client~MatrixClient} for the full list of options for
|
176 | * <code>opts</code>.
|
177 | */
|
178 | module.exports.createClient = function (opts) {
|
179 | if (typeof opts === "string") {
|
180 | opts = {
|
181 | "baseUrl": opts
|
182 | };
|
183 | }
|
184 | opts.request = opts.request || request;
|
185 | opts.store = opts.store || new module.exports.MatrixInMemoryStore({
|
186 | localStorage: global.localStorage
|
187 | });
|
188 | opts.scheduler = opts.scheduler || new module.exports.MatrixScheduler();
|
189 | opts.cryptoStore = opts.cryptoStore || cryptoStoreFactory();
|
190 | return new module.exports.MatrixClient(opts);
|
191 | };
|
192 |
|
193 | /**
|
194 | * The request function interface for performing HTTP requests. This matches the
|
195 | * API for the {@link https://github.com/request/request#requestoptions-callback|
|
196 | * request NPM module}. The SDK will attempt to call this function in order to
|
197 | * perform an HTTP request.
|
198 | * @callback requestFunction
|
199 | * @param {Object} opts The options for this HTTP request.
|
200 | * @param {string} opts.uri The complete URI.
|
201 | * @param {string} opts.method The HTTP method.
|
202 | * @param {Object} opts.qs The query parameters to append to the URI.
|
203 | * @param {Object} opts.body The JSON-serializable object.
|
204 | * @param {boolean} opts.json True if this is a JSON request.
|
205 | * @param {Object} opts._matrix_opts The underlying options set for
|
206 | * {@link MatrixHttpApi}.
|
207 | * @param {requestCallback} callback The request callback.
|
208 | */
|
209 |
|
210 | /**
|
211 | * A wrapper for the request function interface.
|
212 | * @callback requestWrapperFunction
|
213 | * @param {requestFunction} origRequest The underlying request function being
|
214 | * wrapped
|
215 | * @param {Object} opts The options for this HTTP request, given in the same
|
216 | * form as {@link requestFunction}.
|
217 | * @param {requestCallback} callback The request callback.
|
218 | */
|
219 |
|
220 | /**
|
221 | * The request callback interface for performing HTTP requests. This matches the
|
222 | * API for the {@link https://github.com/request/request#requestoptions-callback|
|
223 | * request NPM module}. The SDK will implement a callback which meets this
|
224 | * interface in order to handle the HTTP response.
|
225 | * @callback requestCallback
|
226 | * @param {Error} err The error if one occurred, else falsey.
|
227 | * @param {Object} response The HTTP response which consists of
|
228 | * <code>{statusCode: {Number}, headers: {Object}}</code>
|
229 | * @param {Object} body The parsed HTTP response body.
|
230 | */
|
231 | //# sourceMappingURL=matrix.js.map |
\ | No newline at end of file |