UNPKG

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