videomail-client 8.3.1 → 8.3.3
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/package.json +1 -1
- package/prototype/js/videomail-client.js +8 -9
- package/prototype/js/videomail-client.min.js +1 -1
- package/prototype/js/videomail-client.min.js.map +1 -1
- package/src/js/client.js +0 -210
- package/src/js/constants.js +0 -11
- package/src/js/events.js +0 -46
- package/src/js/index.js +0 -15
- package/src/js/options.js +0 -180
- package/src/js/resource.js +0 -206
- package/src/js/util/audioRecorder.js +0 -152
- package/src/js/util/browser.js +0 -319
- package/src/js/util/collectLogger.js +0 -72
- package/src/js/util/eventEmitter.js +0 -72
- package/src/js/util/humanize.js +0 -16
- package/src/js/util/mediaEvents.js +0 -148
- package/src/js/util/pretty.js +0 -70
- package/src/js/util/standardize.js +0 -71
- package/src/js/util/videomailError.js +0 -431
- package/src/js/wrappers/buttons.js +0 -670
- package/src/js/wrappers/container.js +0 -797
- package/src/js/wrappers/dimension.js +0 -149
- package/src/js/wrappers/form.js +0 -319
- package/src/js/wrappers/optionsWrapper.js +0 -81
- package/src/js/wrappers/visuals/inside/recorder/countdown.js +0 -83
- package/src/js/wrappers/visuals/inside/recorder/facingMode.js +0 -53
- package/src/js/wrappers/visuals/inside/recorder/pausedNote.js +0 -59
- package/src/js/wrappers/visuals/inside/recorder/recordNote.js +0 -42
- package/src/js/wrappers/visuals/inside/recorder/recordTimer.js +0 -149
- package/src/js/wrappers/visuals/inside/recorderInsides.js +0 -144
- package/src/js/wrappers/visuals/notifier.js +0 -341
- package/src/js/wrappers/visuals/recorder.js +0 -1492
- package/src/js/wrappers/visuals/replay.js +0 -355
- package/src/js/wrappers/visuals/userMedia.js +0 -541
- package/src/js/wrappers/visuals.js +0 -410
- package/src/styles/css/main.min.css.js +0 -1
- package/src/styles/styl/keyframes/blink.styl +0 -16
- package/src/styles/styl/main.styl +0 -126
package/src/js/client.js
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import deepmerge from "deepmerge";
|
|
2
|
-
import readystate from "readystate";
|
|
3
|
-
import inherits from "inherits";
|
|
4
|
-
|
|
5
|
-
import defaultOptions from "./options";
|
|
6
|
-
import Constants from "./constants";
|
|
7
|
-
import Events from "./events";
|
|
8
|
-
import CollectLogger from "./util/collectLogger";
|
|
9
|
-
import EventEmitter from "./util/eventEmitter";
|
|
10
|
-
import Container from "./wrappers/container";
|
|
11
|
-
import Replay from "./wrappers/visuals/replay";
|
|
12
|
-
import OptionsWrapper from "./wrappers/optionsWrapper";
|
|
13
|
-
import Browser from "./util/browser";
|
|
14
|
-
import Resource from "./resource";
|
|
15
|
-
|
|
16
|
-
let collectLogger;
|
|
17
|
-
let browser;
|
|
18
|
-
|
|
19
|
-
function adjustOptions(options = {}) {
|
|
20
|
-
const localOptions = deepmerge(defaultOptions, options, {
|
|
21
|
-
arrayMerge(destination, source) {
|
|
22
|
-
return source;
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
collectLogger ||= new CollectLogger(localOptions);
|
|
27
|
-
|
|
28
|
-
localOptions.logger = collectLogger;
|
|
29
|
-
localOptions.debug = localOptions.logger.debug;
|
|
30
|
-
|
|
31
|
-
OptionsWrapper.addFunctions(localOptions);
|
|
32
|
-
|
|
33
|
-
return localOptions;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function getBrowser(localOptions) {
|
|
37
|
-
if (!browser) {
|
|
38
|
-
browser = new Browser(localOptions);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return browser;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const VideomailClient = function (options) {
|
|
45
|
-
const localOptions = adjustOptions(options);
|
|
46
|
-
const container = new Container(localOptions);
|
|
47
|
-
const { debug } = localOptions;
|
|
48
|
-
|
|
49
|
-
let replay;
|
|
50
|
-
|
|
51
|
-
EventEmitter.call(this, localOptions, "VideomailClient");
|
|
52
|
-
|
|
53
|
-
// expose all possible events
|
|
54
|
-
this.events = Events;
|
|
55
|
-
|
|
56
|
-
function build() {
|
|
57
|
-
let building = false;
|
|
58
|
-
|
|
59
|
-
readystate.interactive(function (previousState) {
|
|
60
|
-
debug(
|
|
61
|
-
"Client: interactive(),",
|
|
62
|
-
"previousState =",
|
|
63
|
-
`${previousState},`,
|
|
64
|
-
"!building =",
|
|
65
|
-
`${!building},`,
|
|
66
|
-
"!isBuilt() =",
|
|
67
|
-
!container.isBuilt(),
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
/*
|
|
71
|
-
* it can happen that it gets called twice, i.E. when an error is thrown
|
|
72
|
-
* in the middle of the build() fn
|
|
73
|
-
*/
|
|
74
|
-
if (!building && !container.isBuilt()) {
|
|
75
|
-
building = true;
|
|
76
|
-
container.build();
|
|
77
|
-
building = false;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
this.show = function () {
|
|
83
|
-
if (container.isBuilt()) {
|
|
84
|
-
container.show();
|
|
85
|
-
} else {
|
|
86
|
-
this.once(Events.BUILT, container.show);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
/*
|
|
91
|
-
* automatically adds a <video> element inside the given parentElement and loads
|
|
92
|
-
* it with the videomail
|
|
93
|
-
*/
|
|
94
|
-
this.replay = function (videomail, parentElement) {
|
|
95
|
-
function buildReplay() {
|
|
96
|
-
if (typeof parentElement === "string") {
|
|
97
|
-
parentElement = document.getElementById(parentElement);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (!parentElement) {
|
|
101
|
-
if (!container.isBuilt()) {
|
|
102
|
-
// this will try build all over again
|
|
103
|
-
container.build();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (!container.hasElement()) {
|
|
107
|
-
// if container.setElement() failed too, then complain
|
|
108
|
-
readystate.removeAllListeners();
|
|
109
|
-
throw new Error(
|
|
110
|
-
"Unable to replay video without a container nor parent element.",
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
} else if (container.isOutsideElementOf(parentElement)) {
|
|
114
|
-
replay = new Replay(parentElement, localOptions);
|
|
115
|
-
replay.build();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (!replay) {
|
|
119
|
-
replay = container.getReplay();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (!parentElement) {
|
|
123
|
-
parentElement = replay.getParentElement();
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (videomail) {
|
|
127
|
-
videomail = container.addPlayerDimensions(videomail, parentElement);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (container.isOutsideElementOf(parentElement)) {
|
|
131
|
-
// replay element must be outside of the container
|
|
132
|
-
container.hideForm({ deep: true });
|
|
133
|
-
} else {
|
|
134
|
-
container.loadForm(videomail);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// slight delay needed to avoid HTTP 416 errors (request range unavailable)
|
|
138
|
-
setTimeout(function () {
|
|
139
|
-
replay.setVideomail(videomail);
|
|
140
|
-
container.showReplayOnly();
|
|
141
|
-
}, 10e2); // not sure, but probably can be reduced a bit
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
readystate.interactive(buildReplay);
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
this.startOver = function (params) {
|
|
148
|
-
if (replay) {
|
|
149
|
-
replay.hide();
|
|
150
|
-
replay.reset();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
container.startOver(params);
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
this.unload = function (e) {
|
|
157
|
-
readystate.removeAllListeners();
|
|
158
|
-
container.unload(e);
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
this.hide = function () {
|
|
162
|
-
container.hide();
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
this.get = function (alias, cb) {
|
|
166
|
-
new Resource(localOptions).get(alias, function (err, videomail) {
|
|
167
|
-
if (err) {
|
|
168
|
-
cb(err);
|
|
169
|
-
} else {
|
|
170
|
-
cb(null, container.addPlayerDimensions(videomail));
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
this.canRecord = function () {
|
|
176
|
-
return getBrowser(localOptions).canRecord();
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
// return true when a video has been recorded but is not sent yet
|
|
180
|
-
this.isDirty = function () {
|
|
181
|
-
return container.isDirty();
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
this.isRecording = function () {
|
|
185
|
-
return container.isRecording();
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
this.submit = function () {
|
|
189
|
-
container.submit();
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
this.getLogLines = function () {
|
|
193
|
-
if (localOptions.logger && localOptions.logger.getLines) {
|
|
194
|
-
return localOptions.logger.getLines();
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
build();
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
inherits(VideomailClient, EventEmitter);
|
|
202
|
-
|
|
203
|
-
Object.keys(Constants.public).forEach(function (name) {
|
|
204
|
-
VideomailClient[name] = Constants.public[name];
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
// just another convenient thing
|
|
208
|
-
VideomailClient.events = Events;
|
|
209
|
-
|
|
210
|
-
export default VideomailClient;
|
package/src/js/constants.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// constants (changing these only break down functionality, so be careful)
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
SITE_NAME_LABEL: "x-videomail-site-name",
|
|
5
|
-
VERSION_LABEL: "videomailClientVersion",
|
|
6
|
-
|
|
7
|
-
public: {
|
|
8
|
-
ENC_TYPE_APP_JSON: "application/json",
|
|
9
|
-
ENC_TYPE_FORM: "application/x-www-form-urlencoded",
|
|
10
|
-
},
|
|
11
|
-
};
|
package/src/js/events.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import keymirror from "keymirror";
|
|
2
|
-
|
|
3
|
-
export default keymirror({
|
|
4
|
-
BUILT: null, // all dom elements are ready, are in the DOM
|
|
5
|
-
FORM_READY: null, // form is ready, available in the DOM
|
|
6
|
-
LOADING_USER_MEDIA: null, // asking for webcam access
|
|
7
|
-
USER_MEDIA_READY: null, // user media (= webcam) is ready, loaded
|
|
8
|
-
CONNECTING: null, // socket is connecting to server
|
|
9
|
-
CONNECTED: null, // socket is connected to server
|
|
10
|
-
DISCONNECTED: null, // socket to server is disconnected
|
|
11
|
-
COUNTDOWN: null, // countdown for recording has started
|
|
12
|
-
RECORDING: null, // webcam is recording
|
|
13
|
-
STOPPING: null, // recording is being stopped (= preview)
|
|
14
|
-
STOPPED: null, // recording has stopped
|
|
15
|
-
PROGRESS: null, // start sending
|
|
16
|
-
BEGIN_AUDIO_ENCODING: null, // encoding video
|
|
17
|
-
BEGIN_VIDEO_ENCODING: null, // encoding video
|
|
18
|
-
RESETTING: null, // resetting everything to go back to initial state
|
|
19
|
-
PAUSED: null, // recording is being paused
|
|
20
|
-
RESUMING: null, // recording is resumed
|
|
21
|
-
PREVIEW: null, // video preview is set
|
|
22
|
-
PREVIEW_SHOWN: null, // video preview is shown
|
|
23
|
-
REPLAY_SHOWN: null, // submitted video is shown
|
|
24
|
-
INVALID: null, // form is invalid
|
|
25
|
-
VALIDATING: null, // form is being validated
|
|
26
|
-
VALID: null, // form is valid
|
|
27
|
-
SUBMITTING: null, // form is being submitted
|
|
28
|
-
SUBMITTED: null, // form has been successfully submitted
|
|
29
|
-
ERROR: null, // an error occured
|
|
30
|
-
BLOCKING: null, // something serious, most likely an error, is shown and blocks
|
|
31
|
-
SENDING_FIRST_FRAME: null, // emitted before the first frame is being computed
|
|
32
|
-
FIRST_FRAME_SENT: null, // emitted once when fist frame has been sent to server
|
|
33
|
-
HIDE: null, // emitted when hidden
|
|
34
|
-
NOTIFYING: null, // notifies user about something (not blocking)
|
|
35
|
-
ENABLING_AUDIO: null, // about to enable audio
|
|
36
|
-
DISABLING_AUDIO: null, // about to disable audio
|
|
37
|
-
LOADED_META_DATA: null, // raised when webcam knows its dimensions
|
|
38
|
-
EVENT_EMITTED: null, // for debugging only, is emitted when an event is emitted lol,
|
|
39
|
-
GOING_BACK: null, // switch from replaying back to recording
|
|
40
|
-
STARTING_OVER: null, // starting all over again back to its inital state
|
|
41
|
-
ASKING_WEBCAM_PERMISSION: null, // when about to ask for webcam permissions
|
|
42
|
-
VISIBLE: null, // document just became visible
|
|
43
|
-
INVISIBLE: null, // document just became INvisible
|
|
44
|
-
SWITCH_FACING_MODE: null, // to switch camera on mobiles between fron and back
|
|
45
|
-
SERVER_READY: null, // Gets emitted when the ready command is sent through sockets from the server for recording
|
|
46
|
-
});
|
package/src/js/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import standardize from "./util/standardize";
|
|
2
|
-
import Client from "./client";
|
|
3
|
-
|
|
4
|
-
if (!navigator) {
|
|
5
|
-
throw new Error("Navigator is missing!");
|
|
6
|
-
} else {
|
|
7
|
-
// Ensures Videomail functionality is not broken on exotic browsers with shims.
|
|
8
|
-
standardize(window, navigator);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// Provide both ways
|
|
12
|
-
|
|
13
|
-
// export { Client };
|
|
14
|
-
|
|
15
|
-
export default Client;
|
package/src/js/options.js
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { version } from "../../package.json";
|
|
2
|
-
|
|
3
|
-
const PRODUCTION = process.env.NODE_ENV === "production";
|
|
4
|
-
|
|
5
|
-
/* eslint-disable no-multi-spaces */
|
|
6
|
-
/* eslint indent: ["error", 2, { "ignoreComments": true }] */
|
|
7
|
-
|
|
8
|
-
export default {
|
|
9
|
-
logger: null, // define logging instance. leave null for default, console.
|
|
10
|
-
logStackSize: 30, // limits the stack size of log outputs to collect
|
|
11
|
-
verbose: !PRODUCTION, // set true to log more info
|
|
12
|
-
baseUrl: "https://videomail.io", // leave as it, permanent url to post videos
|
|
13
|
-
socketUrl: "wss://videomail.io", // leave as it, permanent url to send frames
|
|
14
|
-
siteName: "videomail-client-demo", // Required for API, use https://videomail.io/whitelist
|
|
15
|
-
cache: true, // reduces GET queries when loading videos
|
|
16
|
-
insertCss: true, // inserts predefined CSS, see examples
|
|
17
|
-
enablePause: true, // enable pause/resume button
|
|
18
|
-
enableAutoPause: true, // automatically pauses when window becomes inactive
|
|
19
|
-
enableSpace: true, // hitting space can pause recording
|
|
20
|
-
submitWithVideomail: false, // when enabled, all videomail metadata is submitted
|
|
21
|
-
// under the `videomail` key inside the form data body.
|
|
22
|
-
disableSubmit: false, // set this to true if you do not want to submit videos,
|
|
23
|
-
// but just want to record and replay these temporarily
|
|
24
|
-
enableAutoValidation: true, // automatically validates all form inputs if any exist and
|
|
25
|
-
/*
|
|
26
|
-
* does not /enable disable submit button after recording
|
|
27
|
-
* when something else seems invalid.
|
|
28
|
-
*/
|
|
29
|
-
enableAutoSubmission: true, // automatically submits the form where the videomail-client
|
|
30
|
-
/*
|
|
31
|
-
* appears upon press of submit button. disable it when
|
|
32
|
-
* you want a framework to deal with the form submission itself.
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
enctype: "application/json", // enctype for the form submission. currently implemented are:
|
|
36
|
-
// 'application/json' and 'application/x-www-form-urlencoded'
|
|
37
|
-
|
|
38
|
-
// default CSS selectors you can alter, see examples
|
|
39
|
-
selectors: {
|
|
40
|
-
containerId: "videomail",
|
|
41
|
-
replayClass: "replay",
|
|
42
|
-
userMediaClass: "userMedia",
|
|
43
|
-
visualsClass: "visuals",
|
|
44
|
-
buttonClass: null, // can also be used as a default class for all buttons
|
|
45
|
-
buttonsClass: "buttons",
|
|
46
|
-
|
|
47
|
-
recordButtonClass: "record",
|
|
48
|
-
pauseButtonClass: "pause",
|
|
49
|
-
resumeButtonClass: "resume",
|
|
50
|
-
previewButtonClass: "preview",
|
|
51
|
-
recordAgainButtonClass: "recordAgain",
|
|
52
|
-
submitButtonClass: "submit",
|
|
53
|
-
|
|
54
|
-
subjectInputName: "subject", // the form input name for subject
|
|
55
|
-
fromInputName: "from", // the form input name for the from email
|
|
56
|
-
toInputName: "to", // the form input name for the to email
|
|
57
|
-
ccInputName: "cc", // the form input name for the cc email
|
|
58
|
-
bccInputName: "bcc", // the form input name for the bcc email
|
|
59
|
-
bodyInputName: "body", // the form input name for the message (body)
|
|
60
|
-
sendCopyInputName: "sendCopy", // the form checkbox name for sending myself a copy
|
|
61
|
-
|
|
62
|
-
keyInputName: "videomail_key",
|
|
63
|
-
parentKeyInputName: "videomail_parent_key",
|
|
64
|
-
aliasInputName: "videomail_alias",
|
|
65
|
-
|
|
66
|
-
formId: null, // automatically detects form if any
|
|
67
|
-
submitButtonId: null, // semi-automatically detects submit button in the form
|
|
68
|
-
// but if that does not work, try using the
|
|
69
|
-
submitButtonSelector: null, // submitButtonSelector
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
audio: {
|
|
73
|
-
enabled: false, // set to true for experimental audio recording
|
|
74
|
-
switch: false, // enables a switcher for audio recording (on/off)
|
|
75
|
-
volume: 0.2, // must be between 0 .. 1 but 0.20 is recommended to avoid
|
|
76
|
-
// distorting at the higher volume peaks
|
|
77
|
-
bufferSize: "auto", // decides how often the audio is being sampled,
|
|
78
|
-
/*
|
|
79
|
-
* can be 'auto' or an integer being a power of two like 512 or 2048
|
|
80
|
-
* the higher the less traffic, but harder to adjust with rubberband
|
|
81
|
-
* to match with the video length on server side during encoding
|
|
82
|
-
*/
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
video: {
|
|
86
|
-
fps: 15, // depends on your connection
|
|
87
|
-
limitSeconds: 30, // recording automatically stops after that limit
|
|
88
|
-
countdown: 3, // set it to 0 or false to disable it
|
|
89
|
-
|
|
90
|
-
/*
|
|
91
|
-
* it is recommended to set one dimension only and leave the other one to auto
|
|
92
|
-
* because each webcam has a different aspect ratio
|
|
93
|
-
*/
|
|
94
|
-
|
|
95
|
-
width: "auto", // or use an integer for exact pixels
|
|
96
|
-
height: "auto", // or use an integer for exact pixels
|
|
97
|
-
facingMode: "user", // can be 'user', 'environment', 'left' or 'right'. useful for mobiles.
|
|
98
|
-
facingModeButton: false,
|
|
99
|
-
|
|
100
|
-
stretch: false, // Set to true if you want the video to take the full width of the parent container
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
image: {
|
|
104
|
-
quality: 0.42,
|
|
105
|
-
types: ["webp", "jpeg"], // recommended settings to make most of all browsers
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
// alter these text for internationalisation
|
|
109
|
-
text: {
|
|
110
|
-
pausedHeader: "Paused",
|
|
111
|
-
pausedHint: null,
|
|
112
|
-
sending: "Teleporting",
|
|
113
|
-
encoding: "Encoding",
|
|
114
|
-
limitReached: "Limit reached",
|
|
115
|
-
audioOff: "Audio off",
|
|
116
|
-
audioOn: "Audio on",
|
|
117
|
-
buttons: {
|
|
118
|
-
record: "Record video",
|
|
119
|
-
recordAgain: "Record again",
|
|
120
|
-
resume: "Resume",
|
|
121
|
-
pause: "Pause",
|
|
122
|
-
preview: "Preview",
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
|
|
126
|
-
notifier: {
|
|
127
|
-
entertain: false, // when true, user is entertained while waiting, see examples
|
|
128
|
-
entertainClass: "bg",
|
|
129
|
-
entertainLimit: 6,
|
|
130
|
-
entertainInterval: 9000,
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
timeouts: {
|
|
134
|
-
userMedia: 20e3, // in milliseconds, increase if you want user give more time to enable webcam
|
|
135
|
-
connection: 1e4, // in seconds, increase if api is slow
|
|
136
|
-
pingInterval: 35e3, // in milliseconds, keeps web stream (connection) alive when pausing
|
|
137
|
-
},
|
|
138
|
-
|
|
139
|
-
loadUserMediaOnRecord: false, // when true, user media is loaded only when record button is pressed
|
|
140
|
-
|
|
141
|
-
callbacks: {
|
|
142
|
-
/*
|
|
143
|
-
* a custom callback to tweak form data before posting to server
|
|
144
|
-
* this is for advanced use only and shouldn't be used if possible
|
|
145
|
-
*/
|
|
146
|
-
adjustFormDataBeforePosting: null,
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
defaults: {
|
|
150
|
-
from: null, // define default FROM email address
|
|
151
|
-
to: null, // define default TO email address
|
|
152
|
-
cc: null, // define default CC email address
|
|
153
|
-
bcc: null, // define default BCC email address
|
|
154
|
-
subject: null, // define default subject line
|
|
155
|
-
body: null, // define default body content
|
|
156
|
-
},
|
|
157
|
-
|
|
158
|
-
/*
|
|
159
|
-
* a special flag to indicate that everything to be initialised
|
|
160
|
-
* serves only for playing existing videomails with the replay function
|
|
161
|
-
*/
|
|
162
|
-
playerOnly: false,
|
|
163
|
-
|
|
164
|
-
// show errors inside the container?
|
|
165
|
-
displayErrors: true,
|
|
166
|
-
|
|
167
|
-
// true = all form inputs get disabled and disappear when browser can't record
|
|
168
|
-
adjustFormOnBrowserError: false,
|
|
169
|
-
|
|
170
|
-
/*
|
|
171
|
-
* when true, any errors will be sent to the videomail server for analysis
|
|
172
|
-
* ps: can be a function too returning a boolean
|
|
173
|
-
*/
|
|
174
|
-
reportErrors: false,
|
|
175
|
-
|
|
176
|
-
// just for testing purposes to simulate browser agent handling
|
|
177
|
-
fakeUaString: null,
|
|
178
|
-
|
|
179
|
-
version,
|
|
180
|
-
};
|
package/src/js/resource.js
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import superagent from "superagent";
|
|
2
|
-
|
|
3
|
-
import Constants from "./constants";
|
|
4
|
-
|
|
5
|
-
const CACHE_KEY = "alias";
|
|
6
|
-
const timezoneId = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
7
|
-
|
|
8
|
-
export default function (options) {
|
|
9
|
-
const cache = {};
|
|
10
|
-
|
|
11
|
-
function applyDefaultValue(videomail, name) {
|
|
12
|
-
if (options.defaults[name] && !videomail[name]) {
|
|
13
|
-
videomail[name] = options.defaults[name];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return videomail;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function applyDefaultValues(videomail) {
|
|
20
|
-
if (options.defaults) {
|
|
21
|
-
videomail = applyDefaultValue(videomail, "from");
|
|
22
|
-
videomail = applyDefaultValue(videomail, "to");
|
|
23
|
-
videomail = applyDefaultValue(videomail, "cc");
|
|
24
|
-
videomail = applyDefaultValue(videomail, "bcc");
|
|
25
|
-
videomail = applyDefaultValue(videomail, "subject");
|
|
26
|
-
videomail = applyDefaultValue(videomail, "body");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return videomail;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function packError(err, res) {
|
|
33
|
-
if (res && res.body && res.body.error) {
|
|
34
|
-
// use the server generated text instead of the superagent's default text
|
|
35
|
-
err = res.body.error;
|
|
36
|
-
|
|
37
|
-
if (!err.message && res.text) {
|
|
38
|
-
err.message = res.text;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return err;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function fetch(alias, cb) {
|
|
46
|
-
superagent
|
|
47
|
-
.get(`/videomail/${alias}/snapshot`)
|
|
48
|
-
.set("Accept", "application/json")
|
|
49
|
-
.set("Timezone-Id", timezoneId)
|
|
50
|
-
.set(Constants.SITE_NAME_LABEL, options.siteName)
|
|
51
|
-
.timeout(options.timeouts.connection)
|
|
52
|
-
.end(function (err, res) {
|
|
53
|
-
err = packError(err, res);
|
|
54
|
-
|
|
55
|
-
if (err) {
|
|
56
|
-
cb(err);
|
|
57
|
-
} else {
|
|
58
|
-
const videomail = res.body ? res.body : null;
|
|
59
|
-
|
|
60
|
-
if (options.cache) {
|
|
61
|
-
cache[CACHE_KEY] = videomail;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
cb(null, videomail);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function write(method, videomail, identifier, cb) {
|
|
70
|
-
if (!cb) {
|
|
71
|
-
cb = identifier;
|
|
72
|
-
identifier = null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const queryParams = {};
|
|
76
|
-
|
|
77
|
-
let url = `${options.baseUrl}/videomail/`;
|
|
78
|
-
|
|
79
|
-
if (identifier) {
|
|
80
|
-
url += identifier;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const request = superagent(method, url);
|
|
84
|
-
|
|
85
|
-
queryParams[Constants.SITE_NAME_LABEL] = options.siteName;
|
|
86
|
-
|
|
87
|
-
request
|
|
88
|
-
.query(queryParams)
|
|
89
|
-
.set("Timezone-Id", timezoneId)
|
|
90
|
-
.send(videomail)
|
|
91
|
-
.timeout(options.timeout)
|
|
92
|
-
.end(function (err, res) {
|
|
93
|
-
err = packError(err, res);
|
|
94
|
-
|
|
95
|
-
if (err) {
|
|
96
|
-
cb(err);
|
|
97
|
-
} else {
|
|
98
|
-
const returnedVideomail =
|
|
99
|
-
res.body && res.body.videomail ? res.body.videomail : null;
|
|
100
|
-
|
|
101
|
-
if (options.cache && videomail[CACHE_KEY]) {
|
|
102
|
-
cache[videomail[CACHE_KEY]] = returnedVideomail;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
cb(null, returnedVideomail, res.body);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
this.get = function (alias, cb) {
|
|
111
|
-
if (options.cache && cache[alias]) {
|
|
112
|
-
// keep all callbacks async
|
|
113
|
-
setTimeout(() => {
|
|
114
|
-
cb(null, cache[alias]);
|
|
115
|
-
}, 0);
|
|
116
|
-
} else {
|
|
117
|
-
fetch(alias, cb);
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
this.reportError = function (err, cb) {
|
|
122
|
-
const queryParams = {};
|
|
123
|
-
const url = `${options.baseUrl}/client-error/`;
|
|
124
|
-
const request = superagent("post", url);
|
|
125
|
-
|
|
126
|
-
queryParams[Constants.SITE_NAME_LABEL] = options.siteName;
|
|
127
|
-
|
|
128
|
-
request
|
|
129
|
-
.query(queryParams)
|
|
130
|
-
.send(err)
|
|
131
|
-
.timeout(options.timeout)
|
|
132
|
-
.end(function (err, res) {
|
|
133
|
-
err = packError(err, res);
|
|
134
|
-
if (err) {
|
|
135
|
-
cb && cb(err);
|
|
136
|
-
} else {
|
|
137
|
-
cb && cb();
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
this.post = function (videomail, cb) {
|
|
143
|
-
videomail = applyDefaultValues(videomail);
|
|
144
|
-
|
|
145
|
-
/*
|
|
146
|
-
* always good to know the version of the client
|
|
147
|
-
* the videomail was submitted with
|
|
148
|
-
*/
|
|
149
|
-
videomail[Constants.VERSION_LABEL] = options.version;
|
|
150
|
-
|
|
151
|
-
if (options.callbacks.adjustFormDataBeforePosting) {
|
|
152
|
-
options.callbacks.adjustFormDataBeforePosting(
|
|
153
|
-
videomail,
|
|
154
|
-
function (err, adjustedVideomail) {
|
|
155
|
-
if (err) {
|
|
156
|
-
cb(err);
|
|
157
|
-
} else {
|
|
158
|
-
write("post", adjustedVideomail, cb);
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
);
|
|
162
|
-
} else {
|
|
163
|
-
write("post", videomail, cb);
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
this.put = function (videomail, cb) {
|
|
168
|
-
write("put", videomail, videomail.key, cb);
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
this.form = function (formData, url, cb) {
|
|
172
|
-
let formType;
|
|
173
|
-
|
|
174
|
-
switch (options.enctype) {
|
|
175
|
-
case Constants.public.ENC_TYPE_APP_JSON:
|
|
176
|
-
formType = "json";
|
|
177
|
-
break;
|
|
178
|
-
case Constants.public.ENC_TYPE_FORM:
|
|
179
|
-
formType = "form";
|
|
180
|
-
break;
|
|
181
|
-
default:
|
|
182
|
-
// keep all callbacks async
|
|
183
|
-
setTimeout(() => {
|
|
184
|
-
cb(new Error(`Invalid enctype given: ${options.enctype}`));
|
|
185
|
-
}, 0);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (formType) {
|
|
189
|
-
superagent
|
|
190
|
-
.post(url)
|
|
191
|
-
.type(formType)
|
|
192
|
-
.set("Timezone-Id", timezoneId)
|
|
193
|
-
.send(formData)
|
|
194
|
-
.timeout(options.timeout)
|
|
195
|
-
.end(function (err, res) {
|
|
196
|
-
err = packError(err, res);
|
|
197
|
-
|
|
198
|
-
if (err) {
|
|
199
|
-
cb(err);
|
|
200
|
-
} else {
|
|
201
|
-
cb(null, res);
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
}
|