@flashphoner/sfusdk 1.0.47 → 2.0.48
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/dist/examples/sfu.d.ts +13 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/sdk/connection.d.ts +25 -0
- package/dist/sdk/connection.js +101 -0
- package/dist/sdk/connection.js.map +1 -0
- package/dist/sdk/constants.d.ts +355 -0
- package/dist/sdk/constants.js +190 -0
- package/dist/sdk/constants.js.map +1 -0
- package/dist/sdk/logger.d.ts +10 -0
- package/dist/sdk/logger.js +22 -0
- package/dist/sdk/logger.js.map +1 -0
- package/dist/sdk/notifier.d.ts +7 -0
- package/dist/sdk/notifier.js +52 -0
- package/dist/sdk/notifier.js.map +1 -0
- package/dist/sdk/promises.d.ts +11 -0
- package/{src/sdk/promise.js → dist/sdk/promises.js} +14 -13
- package/dist/sdk/promises.js.map +1 -0
- package/dist/sdk/room-extended.d.ts +13 -0
- package/dist/sdk/room-extended.js +112 -0
- package/dist/sdk/room-extended.js.map +1 -0
- package/dist/sdk/room.d.ts +30 -0
- package/dist/sdk/room.js +384 -0
- package/dist/sdk/room.js.map +1 -0
- package/dist/sdk/sfu-extended.d.ts +126 -0
- package/dist/sdk/sfu-extended.js +511 -0
- package/dist/sdk/sfu-extended.js.map +1 -0
- package/dist/sdk/sfu.d.ts +22 -0
- package/dist/sdk/sfu.js +136 -0
- package/dist/sdk/sfu.js.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/sdk/connection.d.ts +25 -0
- package/dist/src/sdk/constants.d.ts +355 -0
- package/dist/src/sdk/logger.d.ts +10 -0
- package/dist/src/sdk/notifier.d.ts +7 -0
- package/dist/src/sdk/promises.d.ts +11 -0
- package/dist/src/sdk/room-extended.d.ts +13 -0
- package/dist/src/sdk/room.d.ts +30 -0
- package/dist/src/sdk/sfu-extended.d.ts +126 -0
- package/dist/src/sdk/sfu.d.ts +22 -0
- package/package.json +27 -27
- package/Gruntfile.js +0 -79
- package/README.md +0 -95
- package/dependencies/bootstrap/css/bootstrap-theme.css +0 -587
- package/dependencies/bootstrap/css/bootstrap-theme.css.map +0 -1
- package/dependencies/bootstrap/css/bootstrap-theme.min.css +0 -5
- package/dependencies/bootstrap/css/bootstrap.css +0 -6853
- package/dependencies/bootstrap/css/bootstrap.css.map +0 -1
- package/dependencies/bootstrap/css/bootstrap.min.css +0 -5
- package/dependencies/bootstrap/font-awesome/HELP-US-OUT.txt +0 -7
- package/dependencies/bootstrap/font-awesome/css/font-awesome.css +0 -2178
- package/dependencies/bootstrap/font-awesome/css/font-awesome.min.css +0 -4
- package/dependencies/bootstrap/font-awesome/fonts/FontAwesome.otf +0 -0
- package/dependencies/bootstrap/font-awesome/fonts/fontawesome-webfont.eot +0 -0
- package/dependencies/bootstrap/font-awesome/fonts/fontawesome-webfont.svg +0 -685
- package/dependencies/bootstrap/font-awesome/fonts/fontawesome-webfont.ttf +0 -0
- package/dependencies/bootstrap/font-awesome/fonts/fontawesome-webfont.woff +0 -0
- package/dependencies/bootstrap/font-awesome/fonts/fontawesome-webfont.woff2 +0 -0
- package/dependencies/bootstrap/font-awesome/less/animated.less +0 -34
- package/dependencies/bootstrap/font-awesome/less/bordered-pulled.less +0 -25
- package/dependencies/bootstrap/font-awesome/less/core.less +0 -12
- package/dependencies/bootstrap/font-awesome/less/fixed-width.less +0 -6
- package/dependencies/bootstrap/font-awesome/less/font-awesome.less +0 -18
- package/dependencies/bootstrap/font-awesome/less/icons.less +0 -724
- package/dependencies/bootstrap/font-awesome/less/larger.less +0 -13
- package/dependencies/bootstrap/font-awesome/less/list.less +0 -19
- package/dependencies/bootstrap/font-awesome/less/mixins.less +0 -60
- package/dependencies/bootstrap/font-awesome/less/path.less +0 -15
- package/dependencies/bootstrap/font-awesome/less/rotated-flipped.less +0 -20
- package/dependencies/bootstrap/font-awesome/less/screen-reader.less +0 -5
- package/dependencies/bootstrap/font-awesome/less/stacked.less +0 -20
- package/dependencies/bootstrap/font-awesome/less/variables.less +0 -735
- package/dependencies/bootstrap/font-awesome/scss/_animated.scss +0 -34
- package/dependencies/bootstrap/font-awesome/scss/_bordered-pulled.scss +0 -25
- package/dependencies/bootstrap/font-awesome/scss/_core.scss +0 -12
- package/dependencies/bootstrap/font-awesome/scss/_fixed-width.scss +0 -6
- package/dependencies/bootstrap/font-awesome/scss/_icons.scss +0 -724
- package/dependencies/bootstrap/font-awesome/scss/_larger.scss +0 -13
- package/dependencies/bootstrap/font-awesome/scss/_list.scss +0 -19
- package/dependencies/bootstrap/font-awesome/scss/_mixins.scss +0 -60
- package/dependencies/bootstrap/font-awesome/scss/_path.scss +0 -15
- package/dependencies/bootstrap/font-awesome/scss/_rotated-flipped.scss +0 -20
- package/dependencies/bootstrap/font-awesome/scss/_screen-reader.scss +0 -5
- package/dependencies/bootstrap/font-awesome/scss/_stacked.scss +0 -20
- package/dependencies/bootstrap/font-awesome/scss/_variables.scss +0 -735
- package/dependencies/bootstrap/font-awesome/scss/font-awesome.scss +0 -18
- package/dependencies/bootstrap/fonts/FontAwesome.otf +0 -0
- package/dependencies/bootstrap/fonts/fontawesome-webfont.eot +0 -0
- package/dependencies/bootstrap/fonts/fontawesome-webfont.svg +0 -655
- package/dependencies/bootstrap/fonts/fontawesome-webfont.ttf +0 -0
- package/dependencies/bootstrap/fonts/fontawesome-webfont.woff +0 -0
- package/dependencies/bootstrap/fonts/fontawesome-webfont.woff2 +0 -0
- package/dependencies/bootstrap/fonts/glyphicons-halflings-regular.eot +0 -0
- package/dependencies/bootstrap/fonts/glyphicons-halflings-regular.svg +0 -288
- package/dependencies/bootstrap/fonts/glyphicons-halflings-regular.ttf +0 -0
- package/dependencies/bootstrap/fonts/glyphicons-halflings-regular.woff +0 -0
- package/dependencies/bootstrap/fonts/glyphicons-halflings-regular.woff2 +0 -0
- package/dependencies/bootstrap/icons/font-awesome.min.css +0 -4
- package/dependencies/bootstrap/js/bootstrap.js +0 -2363
- package/dependencies/bootstrap/js/bootstrap.min.js +0 -7
- package/dependencies/bootstrap/js/npm.js +0 -13
- package/dependencies/bootstrap/js/switch.js +0 -85
- package/dependencies/jquery/jquery-1.12.0.js +0 -11027
- package/dependencies/jquery/jquery-ui.js +0 -16617
- package/dependencies/jquery/jquery.js +0 -8981
- package/dependencies/jquery/jquery.json.js +0 -199
- package/dependencies/jquery/jquery.websocket.js +0 -61
- package/dependencies/sigma/sigma.layout.forceAtlas2.min.js +0 -1
- package/dependencies/sigma/sigma.layout.noverlap.min.js +0 -1
- package/dependencies/sigma/sigma.min.js +0 -2
- package/dependencies/sigma/sigma.plugins.relativeSize.min.js +0 -1
- package/dependencies/sigma/sigma.renderers.edgeLabels.min.js +0 -1
- package/dependencies/sigma/sigma.renderers.parallelEdges.min.js +0 -1
- package/dependencies/sigma/sigma.require.js +0 -12076
- package/docTemplate/README.md +0 -5
- package/docTemplate/publish.js +0 -654
- package/docTemplate/static/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docTemplate/static/fonts/OpenSans-Bold-webfont.svg +0 -1830
- package/docTemplate/static/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docTemplate/static/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docTemplate/static/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
- package/docTemplate/static/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docTemplate/static/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docTemplate/static/fonts/OpenSans-Italic-webfont.svg +0 -1830
- package/docTemplate/static/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docTemplate/static/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docTemplate/static/fonts/OpenSans-Light-webfont.svg +0 -1831
- package/docTemplate/static/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docTemplate/static/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docTemplate/static/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
- package/docTemplate/static/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docTemplate/static/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docTemplate/static/fonts/OpenSans-Regular-webfont.svg +0 -1831
- package/docTemplate/static/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docTemplate/static/scripts/linenumber.js +0 -25
- package/docTemplate/static/scripts/prettify/Apache-License-2.0.txt +0 -202
- package/docTemplate/static/scripts/prettify/lang-css.js +0 -2
- package/docTemplate/static/scripts/prettify/prettify.js +0 -28
- package/docTemplate/static/styles/jsdoc-default.css +0 -354
- package/docTemplate/static/styles/prettify-jsdoc.css +0 -111
- package/docTemplate/static/styles/prettify-tomorrow.css +0 -132
- package/docTemplate/tmpl/augments.tmpl +0 -10
- package/docTemplate/tmpl/container.tmpl +0 -183
- package/docTemplate/tmpl/details.tmpl +0 -143
- package/docTemplate/tmpl/example.tmpl +0 -2
- package/docTemplate/tmpl/examples.tmpl +0 -13
- package/docTemplate/tmpl/exceptions.tmpl +0 -32
- package/docTemplate/tmpl/layout.tmpl +0 -38
- package/docTemplate/tmpl/mainpage.tmpl +0 -14
- package/docTemplate/tmpl/members.tmpl +0 -38
- package/docTemplate/tmpl/method.tmpl +0 -105
- package/docTemplate/tmpl/params.tmpl +0 -124
- package/docTemplate/tmpl/properties.tmpl +0 -108
- package/docTemplate/tmpl/returns.tmpl +0 -19
- package/docTemplate/tmpl/source.tmpl +0 -8
- package/docTemplate/tmpl/tutorial.tmpl +0 -19
- package/docTemplate/tmpl/type.tmpl +0 -7
- package/src/examples/client/chat.js +0 -67
- package/src/examples/client/config.json +0 -26
- package/src/examples/client/controls.js +0 -314
- package/src/examples/client/display.js +0 -502
- package/src/examples/client/main.css +0 -45
- package/src/examples/client/main.html +0 -220
- package/src/examples/client/main.js +0 -156
- package/src/examples/client/resources/details_close.png +0 -0
- package/src/examples/client/resources/details_open.png +0 -0
- package/src/examples/client/util.js +0 -67
- package/src/examples/commons/js/config.js +0 -81
- package/src/examples/commons/js/display.js +0 -484
- package/src/examples/commons/js/util.js +0 -202
- package/src/examples/commons/media/silence.mp3 +0 -0
- package/src/examples/controller/dependencies/sigma/sigma.renderers.edgeLabels.min.js +0 -1
- package/src/examples/controller/dependencies/sigma/sigma.renderers.parallelEdges.min.js +0 -1
- package/src/examples/controller/dependencies/sigma/sigma.require.js +0 -12076
- package/src/examples/controller/graph-view.js +0 -32
- package/src/examples/controller/main.css +0 -45
- package/src/examples/controller/main.html +0 -79
- package/src/examples/controller/main.js +0 -65
- package/src/examples/controller/parser.js +0 -202
- package/src/examples/controller/resources/details_close.png +0 -0
- package/src/examples/controller/resources/details_open.png +0 -0
- package/src/examples/controller/rest.js +0 -56
- package/src/examples/controller/table-view.js +0 -64
- package/src/examples/controller/test-data.js +0 -382
- package/src/examples/player/config.json +0 -8
- package/src/examples/player/player.css +0 -19
- package/src/examples/player/player.html +0 -54
- package/src/examples/player/player.js +0 -209
- package/src/examples/two-way-streaming/config.json +0 -34
- package/src/examples/two-way-streaming/two-way-streaming.css +0 -26
- package/src/examples/two-way-streaming/two-way-streaming.html +0 -72
- package/src/examples/two-way-streaming/two-way-streaming.js +0 -375
- package/src/sdk/constants.js +0 -514
- package/src/sdk/logger.js +0 -16
- package/src/sdk/room.js +0 -594
- package/src/sdk/sfu-extended.js +0 -843
- package/src/sdk/sfu.js +0 -208
- package/src/sdk/ws.js +0 -113
- package/src/tests/assets/1.jpeg +0 -0
- package/src/tests/lib/rtcaudiosourcesinewave.js +0 -109
- package/src/tests/lib/rtcvideosourcewrapper.js +0 -28
- package/src/tests/sdk/room.test.js +0 -229
- package/src/tests/sdk/sfu-extended.test.js +0 -265
- package/src/tests/sdk/sfu-extended.test.js_ +0 -265
- package/src/tests/util.js +0 -48
package/src/sdk/sfu-extended.js
DELETED
|
@@ -1,843 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @namespace FlashphonerSFUExtended
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const {v4: uuidv4} = require("uuid");
|
|
7
|
-
const ws = require("./ws");
|
|
8
|
-
const roomApi = require("./room");
|
|
9
|
-
const promises = require("./promise");
|
|
10
|
-
const constants = require("./constants");
|
|
11
|
-
const logger = require("./logger");
|
|
12
|
-
const SFU_STATE = constants.SFU_STATE;
|
|
13
|
-
const SFU_EVENT = constants.SFU_EVENT;
|
|
14
|
-
const SFU_INTERNAL = constants.SFU_INTERNAL_API;
|
|
15
|
-
const sfu = {};
|
|
16
|
-
let rooms = {};
|
|
17
|
-
let connection = ws.createConnection();
|
|
18
|
-
let server;
|
|
19
|
-
const callbacks = {};
|
|
20
|
-
|
|
21
|
-
let state = SFU_STATE.NEW;
|
|
22
|
-
let connectionConfig;
|
|
23
|
-
let user;
|
|
24
|
-
|
|
25
|
-
function setupConnection(connection) {
|
|
26
|
-
connection.onMessage = function(name, msg){
|
|
27
|
-
switch (name) {
|
|
28
|
-
case SFU_INTERNAL.DEFAULT_METHOD:
|
|
29
|
-
//filter messages
|
|
30
|
-
if (msg[0].type === SFU_INTERNAL.MESSAGE) {
|
|
31
|
-
notify(SFU_EVENT.MESSAGE, msg[0].message);
|
|
32
|
-
} else if (msg[0].type === SFU_INTERNAL.MESSAGE_STATE) {
|
|
33
|
-
if (!promises.resolve(msg[0].internalMessageId, msg[0].status)) {
|
|
34
|
-
notify(SFU_EVENT.MESSAGE_STATE, msg[0].status);
|
|
35
|
-
}
|
|
36
|
-
} else if (msg[0].type === SFU_INTERNAL.USER_LIST) {
|
|
37
|
-
promises.resolve(msg[0].internalMessageId, msg[0].list);
|
|
38
|
-
notify(SFU_EVENT.USER_LIST, msg[0].list);
|
|
39
|
-
} else if (msg[0].type === SFU_INTERNAL.USER_CALENDAR) {
|
|
40
|
-
promises.resolve(msg[0].internalMessageId, msg[0].calendar);
|
|
41
|
-
notify(SFU_EVENT.USER_CALENDAR, msg[0].calendar);
|
|
42
|
-
} else if (msg[0].type === SFU_INTERNAL.NEW_CHAT) {
|
|
43
|
-
if(!promises.resolve(msg[0].internalMessageId, msg[0].info)) {
|
|
44
|
-
notify(SFU_EVENT.NEW_CHAT, msg[0].info);
|
|
45
|
-
}
|
|
46
|
-
} else if (msg[0].type === SFU_INTERNAL.CONTACT_INVITE) {
|
|
47
|
-
if(!promises.resolve(msg[0].internalMessageId, msg[0].invite)) {
|
|
48
|
-
notify(SFU_EVENT.CONTACT_INVITE, msg[0].invite);
|
|
49
|
-
}
|
|
50
|
-
} else if (msg[0].type === SFU_INTERNAL.CONTACT_UPDATED) {
|
|
51
|
-
if(!promises.resolve(msg[0].internalMessageId, msg[0].contact)) {
|
|
52
|
-
notify(SFU_EVENT.CONTACT_UPDATE, msg[0].contact);
|
|
53
|
-
}
|
|
54
|
-
} else if (msg[0].type === SFU_INTERNAL.CONTACT_REMOVED) {
|
|
55
|
-
if(!promises.resolve(msg[0].internalMessageId, msg[0].contact)) {
|
|
56
|
-
notify(SFU_EVENT.CONTACT_REMOVED, msg[0].contact);
|
|
57
|
-
}
|
|
58
|
-
} else if (msg[0].type === SFU_INTERNAL.CHAT_DELETED) {
|
|
59
|
-
notify(SFU_EVENT.CHAT_DELETED, msg[0].info);
|
|
60
|
-
} else if (msg[0].type === SFU_INTERNAL.CHAT_UPDATED) {
|
|
61
|
-
promises.resolve(msg[0].internalMessageId, msg[0].info);
|
|
62
|
-
notify(SFU_EVENT.CHAT_UPDATED, msg[0].info);
|
|
63
|
-
} else if (msg[0].type === SFU_INTERNAL.USER_CHATS) {
|
|
64
|
-
promises.resolve(msg[0].internalMessageId, msg[0].chats);
|
|
65
|
-
notify(SFU_EVENT.USER_CHATS, msg[0].chats);
|
|
66
|
-
} else if (msg[0].type === SFU_INTERNAL.PUBLIC_CHANNELS) {
|
|
67
|
-
promises.resolve(msg[0].internalMessageId, msg[0].channels);
|
|
68
|
-
notify(SFU_EVENT.PUBLIC_CHANNELS, msg[0].channels);
|
|
69
|
-
} else if (msg[0].type === SFU_INTERNAL.CHAT_LOADED) {
|
|
70
|
-
promises.resolve(msg[0].internalMessageId, msg[0].chat);
|
|
71
|
-
notify(SFU_EVENT.CHAT_LOADED, msg[0].chat);
|
|
72
|
-
} else if (msg[0].type === constants.SFU_ROOM_EVENT.OPERATION_FAILED && promises.promised(msg[0].internalMessageId)) {
|
|
73
|
-
promises.reject(msg[0].internalMessageId, msg[0]);
|
|
74
|
-
} else if (msg[0].type === constants.SFU_EVENT.ACK && promises.promised(msg[0].internalMessageId)) {
|
|
75
|
-
promises.resolve(msg[0].internalMessageId);
|
|
76
|
-
} else if (msg[0].roomName && msg[0].roomName.length > 0) {
|
|
77
|
-
//room event
|
|
78
|
-
const room = rooms[msg[0].roomName];
|
|
79
|
-
if (room) {
|
|
80
|
-
room.processEvent(msg[0]);
|
|
81
|
-
}
|
|
82
|
-
} else {
|
|
83
|
-
notify(msg[0].type, msg[0]);
|
|
84
|
-
}
|
|
85
|
-
break;
|
|
86
|
-
case "failed":
|
|
87
|
-
notify(constants.SFU_EVENT.FAILED, msg[0]);
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
connection.onClose = function(e) {
|
|
93
|
-
state = SFU_STATE.DISCONNECTED;
|
|
94
|
-
disconnect();
|
|
95
|
-
notify(SFU_EVENT.DISCONNECTED, e);
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
connection.onError = function(e) {
|
|
99
|
-
state = SFU_STATE.FAILED;
|
|
100
|
-
notify(SFU_STATE.FAILED, e);
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Connect to server.
|
|
105
|
-
*
|
|
106
|
-
* @param {Object} options SFU options
|
|
107
|
-
* @param {String} options.url Server url
|
|
108
|
-
* @param {String} options.username Username
|
|
109
|
-
* @param {String} options.password Password
|
|
110
|
-
* @param {String=} options.nickname Participant's nickname
|
|
111
|
-
* @returns {Promise<void|Error>} Promise which resolves upon connect
|
|
112
|
-
* @throws {TypeError} Error if no options provided
|
|
113
|
-
* @memberof FlashphonerSFUExtended
|
|
114
|
-
*/
|
|
115
|
-
const connect = function(options) {
|
|
116
|
-
if (!options) {
|
|
117
|
-
throw new TypeError("No options provided");
|
|
118
|
-
}
|
|
119
|
-
logger.setPrefix(() => {
|
|
120
|
-
return options.username;
|
|
121
|
-
});
|
|
122
|
-
setupConnection(connection);
|
|
123
|
-
server = new URL(options.url).hostname;
|
|
124
|
-
connectionConfig = {
|
|
125
|
-
url: options.url,
|
|
126
|
-
appName: SFU_INTERNAL.Z_APP,
|
|
127
|
-
custom: {
|
|
128
|
-
username: options.username,
|
|
129
|
-
password: options.password,
|
|
130
|
-
nickname: options.nickname
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
return new Promise(function(resolve, reject) {
|
|
134
|
-
if (state !== SFU_STATE.NEW && state !== SFU_STATE.DISCONNECTED && state !== SFU_STATE.FAILED) {
|
|
135
|
-
reject(new Error("Can't connect with the state " + state));
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
connection.connect(connectionConfig).then(function (connectionConfig) {
|
|
139
|
-
user = Object.freeze({
|
|
140
|
-
username: connectionConfig[0].sipLogin,
|
|
141
|
-
nickname: connectionConfig[0].sipVisibleName,
|
|
142
|
-
pmi: connectionConfig[0].pmi
|
|
143
|
-
});
|
|
144
|
-
state = SFU_STATE.AUTHENTICATED;
|
|
145
|
-
notify(SFU_EVENT.CONNECTED);
|
|
146
|
-
resolve(user);
|
|
147
|
-
}, function (e) {
|
|
148
|
-
state = SFU_STATE.FAILED;
|
|
149
|
-
notify(SFU_EVENT.FAILED, e);
|
|
150
|
-
reject(e);
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* @typedef MessageAttachment
|
|
157
|
-
* @memberOf FlashphonerSFUExtended
|
|
158
|
-
* @property attachment {Object} attachment info
|
|
159
|
-
* @property attachment.type {String} "file|picture"
|
|
160
|
-
* @property attachment.name {String} name of the attachment
|
|
161
|
-
* @property attachment.size {Number} payload size
|
|
162
|
-
* @property attachment.payload {String} base64 string that represents content of the attachment
|
|
163
|
-
*/
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Send message
|
|
167
|
-
* @param {Object} msg Message
|
|
168
|
-
* @param {String} msg.to Recipient's id (deprecated, use chatId instead)
|
|
169
|
-
* @param {String} msg.chatId Indicates chat this message belongs to
|
|
170
|
-
* @param {String} msg.body Message body
|
|
171
|
-
* @param {Array<MessageAttachment>} msg.attachments
|
|
172
|
-
* @returns {Promise} Promise will resolve upon message delivery and reject if delivery was unsuccessful
|
|
173
|
-
* @throws {Error} error if api isn't connected
|
|
174
|
-
* @memberOf FlashphonerSFUExtended
|
|
175
|
-
*/
|
|
176
|
-
const sendMessage = function(msg) {
|
|
177
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
178
|
-
throw new Error("Can't send message while in " + state + " state");
|
|
179
|
-
}
|
|
180
|
-
return new Promise(function(resolve, reject) {
|
|
181
|
-
//validate
|
|
182
|
-
if (!msg) {
|
|
183
|
-
reject(new Error("Can't send null message"));
|
|
184
|
-
} else if ((!msg.body || msg.body === "") && (!msg.attachments || msg.attachments.length === 0)) {
|
|
185
|
-
reject(new Error("Can't send message without content"));
|
|
186
|
-
} else if (!msg.chatId || msg.chatId === "") {
|
|
187
|
-
reject(new Error("Can't send message without a chatId"));
|
|
188
|
-
} else {
|
|
189
|
-
const id = uuidv4();
|
|
190
|
-
promises.add(id, resolve, reject);
|
|
191
|
-
connection.send(constants.SFU_INTERNAL_API.SEND_MESSAGE, {
|
|
192
|
-
id: id,
|
|
193
|
-
internalMessageId: id,
|
|
194
|
-
to: msg.to,
|
|
195
|
-
body: msg.body,
|
|
196
|
-
chatId: msg.chatId,
|
|
197
|
-
attachments: msg.attachments
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
<<<<<<< HEAD
|
|
205
|
-
* Mark message
|
|
206
|
-
* @param {Object} msg Message
|
|
207
|
-
* @param {String} msg.id Message id
|
|
208
|
-
* @param {String} msg.chatId Indicates chat this message belongs to
|
|
209
|
-
* @returns {Promise} Promise resolves with a new state
|
|
210
|
-
* @throws {Error} error if api isn't connected
|
|
211
|
-
=======
|
|
212
|
-
* Fetch available user list from server
|
|
213
|
-
* @returns {Promise<Array<FlashphonerSFUExtended.UserListEntry>>}
|
|
214
|
-
>>>>>>> zapp-26
|
|
215
|
-
* @memberOf FlashphonerSFUExtended
|
|
216
|
-
*/
|
|
217
|
-
const markMessageRead = function(msg) {
|
|
218
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
219
|
-
throw new Error("Can't mark message while in " + state + " state");
|
|
220
|
-
}
|
|
221
|
-
return new Promise(function(resolve, reject) {
|
|
222
|
-
if (!msg) {
|
|
223
|
-
reject(new Error("Can't mark null message"));
|
|
224
|
-
} else if (!msg.chatId || msg.chatId === "") {
|
|
225
|
-
reject(new Error("Can't mark message without a chatId"));
|
|
226
|
-
} else if (!msg.id || msg.id === "") {
|
|
227
|
-
reject(new Error("Can't mark message without massage id"));
|
|
228
|
-
} else {
|
|
229
|
-
const id = uuidv4();
|
|
230
|
-
promises.add(id, resolve, reject);
|
|
231
|
-
connection.send(constants.SFU_INTERNAL_API.MARK_MESSAGE_READ, {
|
|
232
|
-
internalMessageId: id,
|
|
233
|
-
id: msg.id,
|
|
234
|
-
chatId: msg.chatId
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Mark message
|
|
242
|
-
* @param {Object} msg Message
|
|
243
|
-
* @param {String} msg.id Message id
|
|
244
|
-
* @param {String} msg.chatId Indicates chat this message belongs to
|
|
245
|
-
* @returns {Promise} Promise resolves with a new state
|
|
246
|
-
* @throws {Error} error if api isn't connected
|
|
247
|
-
* @memberOf FlashphonerSFUExtended
|
|
248
|
-
*/
|
|
249
|
-
const markMessageUnread = function(msg) {
|
|
250
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
251
|
-
throw new Error("Can't mark message while in " + state + " state");
|
|
252
|
-
}
|
|
253
|
-
return new Promise(function(resolve, reject) {
|
|
254
|
-
if (!msg) {
|
|
255
|
-
reject(new Error("Can't mark null message"));
|
|
256
|
-
} else if (!msg.chatId || msg.chatId === "") {
|
|
257
|
-
reject(new Error("Can't mark message without a chatId"));
|
|
258
|
-
} else if (!msg.id || msg.id === "") {
|
|
259
|
-
reject(new Error("Can't mark message without massage id"));
|
|
260
|
-
} else {
|
|
261
|
-
const id = uuidv4();
|
|
262
|
-
promises.add(id, resolve, reject);
|
|
263
|
-
connection.send(constants.SFU_INTERNAL_API.MARK_MESSAGE_UNREAD, {
|
|
264
|
-
internalMessageId: id,
|
|
265
|
-
id: msg.id,
|
|
266
|
-
chatId: msg.chatId
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Fetch available user list from server
|
|
274
|
-
* @returns {Promise<Array<FlashphonerSFUExtended.UserListEntry>>}
|
|
275
|
-
* @memberOf FlashphonerSFUExtended
|
|
276
|
-
|
|
277
|
-
*/
|
|
278
|
-
const getUserList = function() {
|
|
279
|
-
return new Promise(function (resolve, reject){
|
|
280
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
281
|
-
reject(new Error("Can't get user list while in " + state + " state"));
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
const id = uuidv4();
|
|
285
|
-
promises.add(id, resolve, reject);
|
|
286
|
-
connection.send(constants.SFU_INTERNAL_API.GET_USER_LIST, {internalMessageId: id});
|
|
287
|
-
});
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Fetch available calendar from server
|
|
292
|
-
* @returns {Promise<Array<FlashphonerSFUExtended.UserCalendar>>}
|
|
293
|
-
* @memberOf FlashphonerSFUExtended
|
|
294
|
-
|
|
295
|
-
*/
|
|
296
|
-
const getUserCalendar = function() {
|
|
297
|
-
return new Promise(function (resolve, reject){
|
|
298
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
299
|
-
reject(new Error("Can't get user calendar while in " + state + " state"));
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
const id = uuidv4();
|
|
303
|
-
promises.add(id, resolve, reject);
|
|
304
|
-
connection.send(constants.SFU_INTERNAL_API.GET_USER_CALENDAR, {internalMessageId: id});
|
|
305
|
-
});
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Add event to the calendar
|
|
310
|
-
* @param event {FlashphonerSFUExtended.UserCalendarEvent}
|
|
311
|
-
* @returns {Promise<void|error>}
|
|
312
|
-
* @memberOf FlashphonerSFUExtended
|
|
313
|
-
|
|
314
|
-
*/
|
|
315
|
-
const addCalendarEvent = function(event) {
|
|
316
|
-
return new Promise(function(resolve, reject){
|
|
317
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
318
|
-
reject(new Error("Can't add calendar event while in " + state + " state"));
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
const id = uuidv4();
|
|
322
|
-
promises.add(id, resolve, reject);
|
|
323
|
-
connection.send(constants.SFU_INTERNAL_API.ADD_CALENDAR_EVENT, {
|
|
324
|
-
internalMessageId: id,
|
|
325
|
-
event: event
|
|
326
|
-
});
|
|
327
|
-
});
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Remove event from the calendar
|
|
332
|
-
* @param event {FlashphonerSFUExtended.UserCalendarEvent}
|
|
333
|
-
* @returns {Promise<void|error>}
|
|
334
|
-
* @memberOf FlashphonerSFUExtended
|
|
335
|
-
|
|
336
|
-
*/
|
|
337
|
-
const removeCalendarEvent = function(event) {
|
|
338
|
-
return new Promise(function(resolve, reject){
|
|
339
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
340
|
-
reject(new Error("Can't remove calendar event while in " + state + " state"));
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
const id = uuidv4();
|
|
344
|
-
promises.add(id, resolve, reject);
|
|
345
|
-
connection.send(constants.SFU_INTERNAL_API.REMOVE_CALENDAR_EVENT, {
|
|
346
|
-
internalMessageId: id,
|
|
347
|
-
event: event
|
|
348
|
-
});
|
|
349
|
-
});
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Fetch available chats from server
|
|
354
|
-
* @returns {Promise<Array<FlashphonerSFUExtended.UserCalendar>>}
|
|
355
|
-
* @memberOf FlashphonerSFUExtended
|
|
356
|
-
*/
|
|
357
|
-
const getUserChats = function() {
|
|
358
|
-
return new Promise(function (resolve, reject){
|
|
359
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
360
|
-
reject(new Error("Can't get user chats while in " + state + " state"));
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
const id = uuidv4();
|
|
364
|
-
promises.add(id, resolve, reject);
|
|
365
|
-
connection.send(constants.SFU_INTERNAL_API.GET_USER_CHATS, {internalMessageId: id});
|
|
366
|
-
});
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
const getPublicChannels = function() {
|
|
370
|
-
return new Promise(function (resolve, reject){
|
|
371
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
372
|
-
reject(new Error("Can't get public channels while in " + state + " state"));
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
const id = uuidv4();
|
|
376
|
-
promises.add(id, resolve, reject);
|
|
377
|
-
connection.send(constants.SFU_INTERNAL_API.GET_PUBLIC_CHANNELS, {internalMessageId: id});
|
|
378
|
-
});
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Fetch chat data from server
|
|
383
|
-
* @returns {Promise<Array<FlashphonerSFUExtended.UserCalendar>>}
|
|
384
|
-
* @memberOf FlashphonerSFUExtended
|
|
385
|
-
*/
|
|
386
|
-
const loadChat = function(chat) {
|
|
387
|
-
return new Promise(function (resolve, reject){
|
|
388
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
389
|
-
reject(new Error("Can't load chats while in " + state + " state"));
|
|
390
|
-
return;
|
|
391
|
-
}
|
|
392
|
-
const id = uuidv4();
|
|
393
|
-
promises.add(id, resolve, reject);
|
|
394
|
-
connection.send(constants.SFU_INTERNAL_API.LOAD_CHAT, {id: chat.id, internalMessageId: id});
|
|
395
|
-
});
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* Create chat
|
|
400
|
-
* @returns {Promise<Array<FlashphonerSFUExtended.UserCalendar>>}
|
|
401
|
-
* @memberOf FlashphonerSFUExtended
|
|
402
|
-
*/
|
|
403
|
-
const createChat = function(chat) {
|
|
404
|
-
return new Promise(function (resolve, reject){
|
|
405
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
406
|
-
reject(new Error("Can't create chats while in " + state + " state"));
|
|
407
|
-
return;
|
|
408
|
-
}
|
|
409
|
-
const id = uuidv4();
|
|
410
|
-
promises.add(id, resolve, reject);
|
|
411
|
-
connection.send(constants.SFU_INTERNAL_API.CREATE_CHAT, {
|
|
412
|
-
id: chat.id,
|
|
413
|
-
name: chat.name,
|
|
414
|
-
members: chat.members,
|
|
415
|
-
favourite: chat.favourite,
|
|
416
|
-
internalMessageId: id,
|
|
417
|
-
channel: chat.channel,
|
|
418
|
-
channelType: chat.channelType,
|
|
419
|
-
channelSendPolicy: chat.channelSendPolicy,
|
|
420
|
-
sendPermissionList: chat.sendPermissionList
|
|
421
|
-
});
|
|
422
|
-
});
|
|
423
|
-
};
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Delete chat
|
|
427
|
-
* @returns {Promise<Array<FlashphonerSFUExtended.UserCalendar>>}
|
|
428
|
-
* @memberOf FlashphonerSFUExtended
|
|
429
|
-
*/
|
|
430
|
-
const deleteChat = function(chat) {
|
|
431
|
-
return new Promise(function (resolve, reject){
|
|
432
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
433
|
-
reject(new Error("Can't delete chats while in " + state + " state"));
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
const id = uuidv4();
|
|
437
|
-
promises.add(id, resolve, reject);
|
|
438
|
-
connection.send(constants.SFU_INTERNAL_API.DELETE_CHAT, {id: chat.id, internalMessageId: id});
|
|
439
|
-
});
|
|
440
|
-
};
|
|
441
|
-
|
|
442
|
-
/**
|
|
443
|
-
* Rename chat
|
|
444
|
-
* @returns {Promise<Array<FlashphonerSFUExtended.UserCalendar>>}
|
|
445
|
-
* @memberOf FlashphonerSFUExtended
|
|
446
|
-
*/
|
|
447
|
-
const renameChat = function(chat) {
|
|
448
|
-
return new Promise(function (resolve, reject){
|
|
449
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
450
|
-
reject(new Error("Can't rename chats while in " + state + " state"));
|
|
451
|
-
return;
|
|
452
|
-
}
|
|
453
|
-
const id = uuidv4();
|
|
454
|
-
promises.add(id, resolve, reject);
|
|
455
|
-
connection.send(constants.SFU_INTERNAL_API.RENAME_CHAT, {id: chat.id, name: chat.name, internalMessageId: id});
|
|
456
|
-
});
|
|
457
|
-
};
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* Add member to chat
|
|
461
|
-
* @returns {Promise<Array<FlashphonerSFUExtended.UserCalendar>>}
|
|
462
|
-
* @memberOf FlashphonerSFUExtended
|
|
463
|
-
*/
|
|
464
|
-
const addMemberToChat = function(chat) {
|
|
465
|
-
return new Promise(function (resolve, reject){
|
|
466
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
467
|
-
reject(new Error("Can't add member to chat while in " + state + " state"));
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
const id = uuidv4();
|
|
471
|
-
promises.add(id, resolve, reject);
|
|
472
|
-
connection.send(constants.SFU_INTERNAL_API.ADD_MEMBER_TO_CHAT, {id: chat.id, member: chat.member, internalMessageId: id});
|
|
473
|
-
});
|
|
474
|
-
};
|
|
475
|
-
|
|
476
|
-
/**
|
|
477
|
-
* Remove member from chat
|
|
478
|
-
* @returns {Promise<Array<FlashphonerSFUExtended.UserCalendar>>}
|
|
479
|
-
* @memberOf FlashphonerSFUExtended
|
|
480
|
-
*/
|
|
481
|
-
const removeMemberFromChat = function(chat) {
|
|
482
|
-
return new Promise(function (resolve, reject){
|
|
483
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
484
|
-
reject(new Error("Can't remove member to chat while in " + state + " state"));
|
|
485
|
-
return;
|
|
486
|
-
}
|
|
487
|
-
const id = uuidv4();
|
|
488
|
-
promises.add(id, resolve, reject);
|
|
489
|
-
connection.send(constants.SFU_INTERNAL_API.REMOVE_MEMBER_FROM_CHAT, {id: chat.id, member: chat.member, internalMessageId: id});
|
|
490
|
-
});
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
/**
|
|
494
|
-
*
|
|
495
|
-
* @param invite
|
|
496
|
-
* @returns {Promise<unknown>}
|
|
497
|
-
*/
|
|
498
|
-
const inviteContact = function(invite) {
|
|
499
|
-
return new Promise(function (resolve, reject){
|
|
500
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
501
|
-
reject(new Error("Can't invite contact while in " + state + " state"));
|
|
502
|
-
return;
|
|
503
|
-
}
|
|
504
|
-
const id = uuidv4();
|
|
505
|
-
promises.add(id, resolve, reject);
|
|
506
|
-
connection.send(constants.SFU_INTERNAL_API.INVITE_CONTACT, {from: user.username, to: invite.to, internalMessageId: id});
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
/**
|
|
511
|
-
*
|
|
512
|
-
* @param invite
|
|
513
|
-
* @returns {Promise<unknown>}
|
|
514
|
-
*/
|
|
515
|
-
const confirmContact = function(invite) {
|
|
516
|
-
return new Promise(function (resolve, reject){
|
|
517
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
518
|
-
reject(new Error("Can't confirm contact while in " + state + " state"));
|
|
519
|
-
return;
|
|
520
|
-
}
|
|
521
|
-
const id = uuidv4();
|
|
522
|
-
promises.add(id, resolve, reject);
|
|
523
|
-
connection.send(constants.SFU_INTERNAL_API.CONFIRM_CONTACT, {from: invite.from, to: invite.to, id: invite.id, internalMessageId: id});
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
*
|
|
529
|
-
* @param contact
|
|
530
|
-
* @returns {Promise<unknown>}
|
|
531
|
-
*/
|
|
532
|
-
const removeContact = function(contact) {
|
|
533
|
-
return new Promise(function (resolve, reject){
|
|
534
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
535
|
-
reject(new Error("Can't remove contact while in " + state + " state"));
|
|
536
|
-
return;
|
|
537
|
-
}
|
|
538
|
-
const id = uuidv4();
|
|
539
|
-
promises.add(id, resolve, reject);
|
|
540
|
-
connection.send(constants.SFU_INTERNAL_API.REMOVE_CONTACT, {id: contact.id, internalMessageId: id});
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
*
|
|
545
|
-
* @param channel
|
|
546
|
-
* @returns {Promise<unknown>}
|
|
547
|
-
*/
|
|
548
|
-
const updateChannelSendPolicy = function(channel) {
|
|
549
|
-
return new Promise(function (resolve, reject){
|
|
550
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
551
|
-
reject(new Error("Can't change channel send policy while in " + state + " state"));
|
|
552
|
-
return;
|
|
553
|
-
}
|
|
554
|
-
const id = uuidv4();
|
|
555
|
-
promises.add(id, resolve, reject);
|
|
556
|
-
connection.send(constants.SFU_INTERNAL_API.UPDATE_CHANNEL_SEND_POLICY, {
|
|
557
|
-
id: channel.id,
|
|
558
|
-
channelSendPolicy: channel.channelSendPolicy,
|
|
559
|
-
internalMessageId: id
|
|
560
|
-
});
|
|
561
|
-
});
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
const addChannelSendPermissionListMember = function(channel) {
|
|
565
|
-
return new Promise(function (resolve, reject){
|
|
566
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
567
|
-
reject(new Error("Can't change channel send permission list while in " + state + " state"));
|
|
568
|
-
return;
|
|
569
|
-
}
|
|
570
|
-
const id = uuidv4();
|
|
571
|
-
promises.add(id, resolve, reject);
|
|
572
|
-
connection.send(constants.SFU_INTERNAL_API.ADD_CHANNEL_SEND_PERMISSION_LIST_MEMBER, {
|
|
573
|
-
id: channel.id,
|
|
574
|
-
member: channel.member,
|
|
575
|
-
internalMessageId: id
|
|
576
|
-
});
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
const removeChannelSendPermissionListMember = function(channel) {
|
|
581
|
-
return new Promise(function (resolve, reject){
|
|
582
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
583
|
-
reject(new Error("Can't change channel send permission list while in " + state + " state"));
|
|
584
|
-
return;
|
|
585
|
-
}
|
|
586
|
-
const id = uuidv4();
|
|
587
|
-
promises.add(id, resolve, reject);
|
|
588
|
-
connection.send(constants.SFU_INTERNAL_API.REMOVE_CHANNEL_SEND_PERMISSION_LIST_MEMBER, {
|
|
589
|
-
id: channel.id,
|
|
590
|
-
member: channel.member,
|
|
591
|
-
internalMessageId: id
|
|
592
|
-
});
|
|
593
|
-
});
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
const addChatToFavourites = function(chat) {
|
|
597
|
-
return new Promise(function (resolve, reject){
|
|
598
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
599
|
-
reject(new Error("Can't add to favourites while in " + state + " state"));
|
|
600
|
-
return;
|
|
601
|
-
}
|
|
602
|
-
const id = uuidv4();
|
|
603
|
-
promises.add(id, resolve, reject);
|
|
604
|
-
connection.send(constants.SFU_INTERNAL_API.ADD_CHAT_TO_FAVOURITES, {
|
|
605
|
-
id: chat.id,
|
|
606
|
-
internalMessageId: id
|
|
607
|
-
});
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
const removeChatFromFavourites = function(chat) {
|
|
612
|
-
return new Promise(function (resolve, reject){
|
|
613
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
614
|
-
reject(new Error("Can't remove from favourites while in " + state + " state"));
|
|
615
|
-
return;
|
|
616
|
-
}
|
|
617
|
-
const id = uuidv4();
|
|
618
|
-
promises.add(id, resolve, reject);
|
|
619
|
-
connection.send(constants.SFU_INTERNAL_API.REMOVE_CHAT_FROM_FAVOURITES, {
|
|
620
|
-
id: chat.id,
|
|
621
|
-
internalMessageId: id
|
|
622
|
-
});
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
/**
|
|
627
|
-
* Create room
|
|
628
|
-
*
|
|
629
|
-
* @param {Object} options Room options
|
|
630
|
-
* @param {String} options.name Room name
|
|
631
|
-
* @param {String} options.pin Room's pin
|
|
632
|
-
* @param {Object} options.pc Peer connection
|
|
633
|
-
* @returns {FlashphonerSFU.Room} Room
|
|
634
|
-
* @throws {TypeError} Error if no options provided
|
|
635
|
-
* @throws {Error} error if api isn't connected
|
|
636
|
-
* @memberof FlashphonerSFUExtended
|
|
637
|
-
*/
|
|
638
|
-
const room = function(options) {
|
|
639
|
-
if (!options) {
|
|
640
|
-
throw new TypeError("No options provided");
|
|
641
|
-
}
|
|
642
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
643
|
-
throw new Error("Can't create room while in " + state + " state");
|
|
644
|
-
}
|
|
645
|
-
const opt = {
|
|
646
|
-
connection: connection,
|
|
647
|
-
name: options.name,
|
|
648
|
-
pin: options.pin,
|
|
649
|
-
pc: options.pc
|
|
650
|
-
};
|
|
651
|
-
const exports = roomApi.room(opt);
|
|
652
|
-
rooms[options.name] = exports;
|
|
653
|
-
const cleanup = function() {
|
|
654
|
-
rooms[options.name].pc().close();
|
|
655
|
-
rooms[options.name].pc().dispatchEvent(new Event("connectionstatechange"));
|
|
656
|
-
delete rooms[options.name];
|
|
657
|
-
};
|
|
658
|
-
exports.on(constants.SFU_ROOM_EVENT.LEFT, function(participant){
|
|
659
|
-
if (participant.name === user.nickname) {
|
|
660
|
-
cleanup();
|
|
661
|
-
}
|
|
662
|
-
}).on(constants.SFU_ROOM_EVENT.EVICTED, function(participant) {
|
|
663
|
-
if (participant.name === user.nickname) {
|
|
664
|
-
cleanup();
|
|
665
|
-
}
|
|
666
|
-
}).on(constants.SFU_ROOM_EVENT.FAILED, cleanup
|
|
667
|
-
).on(constants.SFU_ROOM_EVENT.OPERATION_FAILED, function(e) {
|
|
668
|
-
if (constants.SFU_OPERATIONS.ROOM_JOIN === e.operation) {
|
|
669
|
-
cleanup();
|
|
670
|
-
}
|
|
671
|
-
});
|
|
672
|
-
return exports;
|
|
673
|
-
};
|
|
674
|
-
|
|
675
|
-
/**
|
|
676
|
-
* Get previously created room.
|
|
677
|
-
* Note that this function will not return ended or failed room
|
|
678
|
-
*
|
|
679
|
-
* @param options {Object}
|
|
680
|
-
* @param options.name {String} room name
|
|
681
|
-
* @returns {FlashphonerSFU.Room} Room
|
|
682
|
-
* @throws {TypeError} Error if no options provided
|
|
683
|
-
* @throws {Error} error if api isn't connected
|
|
684
|
-
* @memberof FlashphonerSFUExtended
|
|
685
|
-
*/
|
|
686
|
-
const getRoom = function(options) {
|
|
687
|
-
if (!options) {
|
|
688
|
-
throw new TypeError("No options provided");
|
|
689
|
-
}
|
|
690
|
-
if (state !== SFU_STATE.AUTHENTICATED) {
|
|
691
|
-
throw new Error("Can't create room while in " + state + " state");
|
|
692
|
-
}
|
|
693
|
-
return rooms[options.name];
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
/**
|
|
697
|
-
* FlashphonerSFUExtended event callback.
|
|
698
|
-
*
|
|
699
|
-
* @callback FlashphonerSFUExtended~eventCallback
|
|
700
|
-
* @param {FlashphonerSFUExtended} sdk instance FlashphonerSFUExtended
|
|
701
|
-
*/
|
|
702
|
-
|
|
703
|
-
/**
|
|
704
|
-
* Add session event callback.
|
|
705
|
-
*
|
|
706
|
-
* @param {String} event One of {@link FlashphonerSFU.SFU_EVENT} events
|
|
707
|
-
* @param {FlashphonerSFUExtended~eventCallback} callback Callback function
|
|
708
|
-
* @returns {FlashphonerSFUExtended} SDK instance callback was attached to
|
|
709
|
-
* @throws {TypeError} Error if event is not specified
|
|
710
|
-
* @throws {Error} Error if callback is not a valid function
|
|
711
|
-
* @memberOf FlashphonerSFUExtended
|
|
712
|
-
*/
|
|
713
|
-
const on = function (event, callback) {
|
|
714
|
-
if (!event) {
|
|
715
|
-
throw new TypeError("Event can't be null");
|
|
716
|
-
}
|
|
717
|
-
if (!callback || typeof callback !== "function") {
|
|
718
|
-
throw new Error("Callback needs to be a valid function");
|
|
719
|
-
}
|
|
720
|
-
if (!callbacks[event]) {
|
|
721
|
-
callbacks[event] = [];
|
|
722
|
-
}
|
|
723
|
-
callbacks[event].push(callback);
|
|
724
|
-
return sfu;
|
|
725
|
-
};
|
|
726
|
-
|
|
727
|
-
/**
|
|
728
|
-
* Remove session event callback.
|
|
729
|
-
*
|
|
730
|
-
* @param {String} event One of {@link FlashphonerSFU.SFU_EVENT} events
|
|
731
|
-
* @param {FlashphonerSFUExtended~eventCallback} callback Callback function
|
|
732
|
-
* @returns {FlashphonerSFUExtended} SDK instance callback was removed from
|
|
733
|
-
* @throws {TypeError} Error if event is not specified
|
|
734
|
-
* @throws {Error} Error if callback is not a valid function
|
|
735
|
-
* @memberOf FlashphonerSFUExtended
|
|
736
|
-
*/
|
|
737
|
-
const off = function (event, callback) {
|
|
738
|
-
if (!event) {
|
|
739
|
-
throw new TypeError("Event can't be null");
|
|
740
|
-
}
|
|
741
|
-
if (!callback || typeof callback !== "function") {
|
|
742
|
-
throw new Error("Callback needs to be a valid function");
|
|
743
|
-
}
|
|
744
|
-
if (!callbacks[event]) {
|
|
745
|
-
callbacks[event] = [];
|
|
746
|
-
}
|
|
747
|
-
let index = callbacks[event].findIndex(element => element === callback);
|
|
748
|
-
if (index !== -1) {
|
|
749
|
-
callbacks[event] = callbacks[event].slice(index, 1);
|
|
750
|
-
}
|
|
751
|
-
return sfu;
|
|
752
|
-
};
|
|
753
|
-
|
|
754
|
-
const notify = function(event, msg) {
|
|
755
|
-
if (callbacks[event]) {
|
|
756
|
-
for (const callback of callbacks[event]) {
|
|
757
|
-
callback(msg);
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
};
|
|
761
|
-
|
|
762
|
-
/**
|
|
763
|
-
* Disconnect sfu from the server
|
|
764
|
-
* @memberOf FlashphonerSFUExtended
|
|
765
|
-
*/
|
|
766
|
-
const disconnect = function() {
|
|
767
|
-
for (const [key, value] of Object.entries(rooms)) {
|
|
768
|
-
value.leaveRoom();
|
|
769
|
-
}
|
|
770
|
-
user = undefined;
|
|
771
|
-
connection.close();
|
|
772
|
-
connection = ws.createConnection();
|
|
773
|
-
state = SFU_STATE.DISCONNECTED;
|
|
774
|
-
rooms = {};
|
|
775
|
-
};
|
|
776
|
-
|
|
777
|
-
sfu.on = on;
|
|
778
|
-
sfu.off = off;
|
|
779
|
-
sfu.connect = connect;
|
|
780
|
-
sfu.sendMessage = sendMessage;
|
|
781
|
-
sfu.markMessageRead = markMessageRead;
|
|
782
|
-
sfu.markMessageUnread = markMessageUnread;
|
|
783
|
-
sfu.getUserList = getUserList;
|
|
784
|
-
sfu.getUserCalendar = getUserCalendar;
|
|
785
|
-
sfu.addCalendarEvent = addCalendarEvent;
|
|
786
|
-
sfu.removeCalendarEvent = removeCalendarEvent;
|
|
787
|
-
sfu.getUserChats = getUserChats;
|
|
788
|
-
sfu.getPublicChannels = getPublicChannels;
|
|
789
|
-
sfu.loadChat = loadChat;
|
|
790
|
-
sfu.createChat = createChat;
|
|
791
|
-
sfu.deleteChat = deleteChat;
|
|
792
|
-
sfu.renameChat = renameChat;
|
|
793
|
-
sfu.addMemberToChat = addMemberToChat;
|
|
794
|
-
sfu.removeMemberFromChat = removeMemberFromChat;
|
|
795
|
-
sfu.inviteContact = inviteContact;
|
|
796
|
-
sfu.confirmContact = confirmContact;
|
|
797
|
-
sfu.removeContact = removeContact;
|
|
798
|
-
sfu.updateChannelSendPolicy = updateChannelSendPolicy;
|
|
799
|
-
sfu.addChannelSendPermissionListMember = addChannelSendPermissionListMember;
|
|
800
|
-
sfu.removeChannelSendPermissionListMember = removeChannelSendPermissionListMember;
|
|
801
|
-
sfu.addChatToFavourites = addChatToFavourites;
|
|
802
|
-
sfu.removeChatFromFavourites = removeChatFromFavourites;
|
|
803
|
-
sfu.room = room;
|
|
804
|
-
sfu.getRoom = getRoom;
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
/**
|
|
808
|
-
* @typedef {Object} SFUUser
|
|
809
|
-
* @property username {String} username
|
|
810
|
-
* @property nickname {String} nickname
|
|
811
|
-
* @memberOf FlashphonerSFUExtended
|
|
812
|
-
*/
|
|
813
|
-
|
|
814
|
-
/**
|
|
815
|
-
* Get current user
|
|
816
|
-
* @returns {FlashphonerSFUExtended.SFUUser} Returns current logged in user
|
|
817
|
-
* @memberOf FlashphonerSFUExtended
|
|
818
|
-
*/
|
|
819
|
-
sfu.user = function(){
|
|
820
|
-
return user;
|
|
821
|
-
};
|
|
822
|
-
/**
|
|
823
|
-
* Get hostname of the server in use
|
|
824
|
-
* @returns {String} Current server's hostname
|
|
825
|
-
* @memberOf FlashphonerSFUExtended
|
|
826
|
-
*/
|
|
827
|
-
sfu.server = function() {
|
|
828
|
-
return server;
|
|
829
|
-
};
|
|
830
|
-
sfu.disconnect = disconnect;
|
|
831
|
-
|
|
832
|
-
/**
|
|
833
|
-
* Get sfu state
|
|
834
|
-
* @returns {FlashphonerSFU.SFU_STATE} Current sfu state
|
|
835
|
-
*/
|
|
836
|
-
sfu.state = function() {
|
|
837
|
-
return state;
|
|
838
|
-
};
|
|
839
|
-
|
|
840
|
-
sfu.constants = constants;
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
module.exports = sfu;
|