@flashphoner/sfusdk 1.0.47 → 2.0.51
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/client.version +1 -0
- 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 +364 -0
- package/dist/sdk/constants.js +192 -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 +14 -0
- package/dist/sdk/room-extended.js +125 -0
- package/dist/sdk/room-extended.js.map +1 -0
- package/dist/sdk/room.d.ts +30 -0
- package/dist/sdk/room.js +370 -0
- package/dist/sdk/room.js.map +1 -0
- package/dist/sdk/sfu-extended.d.ts +132 -0
- package/dist/sdk/sfu-extended.js +525 -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 +364 -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 +14 -0
- package/dist/src/sdk/room.d.ts +30 -0
- package/dist/src/sdk/sfu-extended.d.ts +132 -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.js
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @namespace FlashphonerSFU
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const ws = require("./ws");
|
|
6
|
-
const roomApi = require("./room");
|
|
7
|
-
const constants = require("./constants");
|
|
8
|
-
const SFU_STATE = constants.SFU_STATE;
|
|
9
|
-
const SFU_EVENT = constants.SFU_EVENT;
|
|
10
|
-
const SFU_INTERNAL = constants.SFU_INTERNAL_API;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Connect to server and create local representation of the room.
|
|
14
|
-
* @param {Object} options Room options
|
|
15
|
-
* @param {String} options.url Server url
|
|
16
|
-
* @param {String} options.roomName Room name
|
|
17
|
-
* @param {String} options.pin Room's pin
|
|
18
|
-
* @param {String} options.nickname Participant's nick
|
|
19
|
-
* @param {Object} options.pc Peer connection
|
|
20
|
-
* @returns {FlashphonerSFU.SFUSession} session
|
|
21
|
-
* @throws {TypeError} Error if no options provided
|
|
22
|
-
* @memberof FlashphonerSFU
|
|
23
|
-
*/
|
|
24
|
-
function createSession(options) {
|
|
25
|
-
if (!options) {
|
|
26
|
-
throw new TypeError("No options provided");
|
|
27
|
-
}
|
|
28
|
-
let sfu = {};
|
|
29
|
-
let room;
|
|
30
|
-
const callbacks = {};
|
|
31
|
-
const connection = ws.createConnection();
|
|
32
|
-
let state = SFU_STATE.NEW;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
connection.onMessage = function(name, msg){
|
|
36
|
-
switch (name) {
|
|
37
|
-
case SFU_INTERNAL.DEFAULT_METHOD:
|
|
38
|
-
if (msg[0].roomName && msg[0].roomName.length > 0) {
|
|
39
|
-
//room event
|
|
40
|
-
if (room) {
|
|
41
|
-
room.processEvent(msg[0]);
|
|
42
|
-
}
|
|
43
|
-
} else {
|
|
44
|
-
notify(msg[0].type, msg[0]);
|
|
45
|
-
}
|
|
46
|
-
break;
|
|
47
|
-
case "failed":
|
|
48
|
-
notify(constants.SFU_EVENT.FAILED, msg[0]);
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
connection.onClose = function(e) {
|
|
54
|
-
state = SFU_STATE.DISCONNECTED;
|
|
55
|
-
notify(SFU_EVENT.DISCONNECTED, e);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
connection.onError = function(e) {
|
|
59
|
-
state = SFU_STATE.FAILED;
|
|
60
|
-
notify(SFU_STATE.FAILED, e);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
let connectionConfig = {
|
|
64
|
-
url: options.url,
|
|
65
|
-
appName: SFU_INTERNAL.P_APP,
|
|
66
|
-
custom: {
|
|
67
|
-
nickname: options.nickname,
|
|
68
|
-
roomName: options.roomName
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
connection.connect(connectionConfig).then(function (connectionConfig) {
|
|
73
|
-
state = SFU_STATE.CONNECTED;
|
|
74
|
-
//create room
|
|
75
|
-
const opt = {
|
|
76
|
-
connection: connection,
|
|
77
|
-
name: options.roomName,
|
|
78
|
-
pin: options.pin,
|
|
79
|
-
pc: options.pc
|
|
80
|
-
};
|
|
81
|
-
room = roomApi.room(opt);
|
|
82
|
-
notify(SFU_EVENT.CONNECTED, room);
|
|
83
|
-
}, function (e) {
|
|
84
|
-
state = SFU_STATE.FAILED;
|
|
85
|
-
notify(SFU_EVENT.FAILED, e);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Disconnect from the server
|
|
90
|
-
* @memberOf FlashphonerSFU.SFUSession
|
|
91
|
-
*/
|
|
92
|
-
const disconnect = function() {
|
|
93
|
-
connection.close();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Session event callback.
|
|
98
|
-
*
|
|
99
|
-
* @callback FlashphonerSFU.SFUSession~eventCallback
|
|
100
|
-
* @param {FlashphonerSFU.SFUSession} session SFUSession that corresponds to the event
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Add session event callback.
|
|
105
|
-
*
|
|
106
|
-
* @param {String} event One of {@link FlashphonerSFU.SFU_EVENT} events
|
|
107
|
-
* @param {FlashphonerSFU.SFUSession~eventCallback} callback Callback function
|
|
108
|
-
* @returns {FlashphonerSFU.SFUSession} Session callback was attached to
|
|
109
|
-
* @throws {TypeError} Error if event is not specified
|
|
110
|
-
* @throws {Error} Error if callback is not a valid function
|
|
111
|
-
* @memberOf FlashphonerSFU.SFUSession
|
|
112
|
-
* @inner
|
|
113
|
-
*/
|
|
114
|
-
const on = function (event, callback) {
|
|
115
|
-
if (!event) {
|
|
116
|
-
throw new TypeError("Event can't be null");
|
|
117
|
-
}
|
|
118
|
-
if (!callback || typeof callback !== "function") {
|
|
119
|
-
throw new Error("Callback needs to be a valid function");
|
|
120
|
-
}
|
|
121
|
-
if (!callbacks[event]) {
|
|
122
|
-
callbacks[event] = [];
|
|
123
|
-
}
|
|
124
|
-
callbacks[event].push(callback);
|
|
125
|
-
return sfu;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Remove session event callback.
|
|
130
|
-
*
|
|
131
|
-
* @param {String} event One of {@link FlashphonerSFU.SFU_EVENT} events
|
|
132
|
-
* @param {FlashphonerSFU.SFUSession~eventCallback} callback Callback function
|
|
133
|
-
* @returns {FlashphonerSFU.SFUSession} Session callback was removed from
|
|
134
|
-
* @throws {TypeError} Error if event is not specified
|
|
135
|
-
* @throws {Error} Error if callback is not a valid function
|
|
136
|
-
* @memberOf FlashphonerSFU.SFUSession
|
|
137
|
-
* @inner
|
|
138
|
-
*/
|
|
139
|
-
const off = function (event, callback) {
|
|
140
|
-
if (!event) {
|
|
141
|
-
throw new TypeError("Event can't be null");
|
|
142
|
-
}
|
|
143
|
-
if (!callback || typeof callback !== "function") {
|
|
144
|
-
throw new Error("Callback needs to be a valid function");
|
|
145
|
-
}
|
|
146
|
-
if (!callbacks[event]) {
|
|
147
|
-
callbacks[event] = [];
|
|
148
|
-
}
|
|
149
|
-
let index = callbacks[event].findIndex(element => element === callback);
|
|
150
|
-
if (index !== -1) {
|
|
151
|
-
callbacks[event] = callbacks[event].slice(index, 1);
|
|
152
|
-
}
|
|
153
|
-
return sfu;
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
const notify = function(event, msg) {
|
|
157
|
-
if (callbacks[event]) {
|
|
158
|
-
for (const callback of callbacks[event]) {
|
|
159
|
-
callback(msg);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Represents connection to server. Once connected will emmit {@link FlashphonerSFU.SFU_EVENT.CONNECTED} with local instance of previously
|
|
166
|
-
* specified room.
|
|
167
|
-
*
|
|
168
|
-
* @see FlashphonerSFU.createSession
|
|
169
|
-
* @namespace SFUSession
|
|
170
|
-
* @memberOf FlashphonerSFU
|
|
171
|
-
*/
|
|
172
|
-
sfu = {
|
|
173
|
-
/**
|
|
174
|
-
* Returns room object if available
|
|
175
|
-
* @returns {FlashphonerSFU.Room}
|
|
176
|
-
* @memberOf FlashphonerSFU.SFUSession
|
|
177
|
-
*/
|
|
178
|
-
room: function() {
|
|
179
|
-
return room;
|
|
180
|
-
},
|
|
181
|
-
/**
|
|
182
|
-
* Returns {@link FlashphonerSFU.SFU_STATE} state of connection
|
|
183
|
-
* @returns {FlashphonerSFU.SFU_STATE}
|
|
184
|
-
* @memberOf FlashphonerSFU.SFUSession
|
|
185
|
-
*/
|
|
186
|
-
state: function() {
|
|
187
|
-
return state;
|
|
188
|
-
},
|
|
189
|
-
/**
|
|
190
|
-
* Preconfigured nickname
|
|
191
|
-
* @returns {String}
|
|
192
|
-
* @memberOf FlashphonerSFU.SFUSession
|
|
193
|
-
*/
|
|
194
|
-
nickname: function() {
|
|
195
|
-
return options.nickname;
|
|
196
|
-
},
|
|
197
|
-
disconnect: disconnect,
|
|
198
|
-
on: on,
|
|
199
|
-
off: off
|
|
200
|
-
}
|
|
201
|
-
return sfu;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
module.exports = {
|
|
206
|
-
createRoom: createSession,
|
|
207
|
-
constants: constants
|
|
208
|
-
}
|
package/src/sdk/ws.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const logger = require("./logger");
|
|
4
|
-
|
|
5
|
-
function createConnection() {
|
|
6
|
-
let wsConnection;
|
|
7
|
-
let exports = {};
|
|
8
|
-
exports.onError = function(e){};
|
|
9
|
-
exports.onClose = function(e){};
|
|
10
|
-
exports.onMessage = function(name, body){};
|
|
11
|
-
/**
|
|
12
|
-
* @param {Object} options Connection options
|
|
13
|
-
* @param {String=} options.url Server url
|
|
14
|
-
* @param {String=} options.appName Application name
|
|
15
|
-
* @param {Number=} options.timeout Connection timeout
|
|
16
|
-
* @param {Object=} options.custom Custom object
|
|
17
|
-
* @returns Promise
|
|
18
|
-
* @throws {TypeError} Error if no options provided
|
|
19
|
-
* @memberof FSFU
|
|
20
|
-
* @inner
|
|
21
|
-
*/
|
|
22
|
-
exports.connect = function(options) {
|
|
23
|
-
return new Promise(function(resolve, reject) {
|
|
24
|
-
let connected = false;
|
|
25
|
-
wsConnection = new WebSocket(options.url);
|
|
26
|
-
wsConnection.binaryType = 'arraybuffer';
|
|
27
|
-
let connectionTimeout;
|
|
28
|
-
if (options.timeout !== undefined && options.timeout > 0) {
|
|
29
|
-
connectionTimeout = setTimeout(function () {
|
|
30
|
-
if (wsConnection.readyState === 0) {
|
|
31
|
-
console.log("WS connection timeout");
|
|
32
|
-
wsConnection.close();
|
|
33
|
-
}
|
|
34
|
-
}, options.timeout);
|
|
35
|
-
}
|
|
36
|
-
wsConnection.onerror = function (e) {
|
|
37
|
-
if (connected) {
|
|
38
|
-
exports.onError(e);
|
|
39
|
-
} else {
|
|
40
|
-
reject(e);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
wsConnection.onclose = function (e) {
|
|
44
|
-
if (connected) {
|
|
45
|
-
exports.onClose(e);
|
|
46
|
-
} else {
|
|
47
|
-
reject(e);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
wsConnection.onopen = function () {
|
|
51
|
-
clearTimeout(connectionTimeout);
|
|
52
|
-
let cConfig = {
|
|
53
|
-
appKey: options.appName,
|
|
54
|
-
mediaProviders: ["WebRTC"],
|
|
55
|
-
keepAlive: true,
|
|
56
|
-
authToken: null,
|
|
57
|
-
clientVersion: "0.5.28",
|
|
58
|
-
clientOSVersion: window.navigator.appVersion,
|
|
59
|
-
clientBrowserVersion: window.navigator.userAgent,
|
|
60
|
-
custom: options.custom
|
|
61
|
-
};
|
|
62
|
-
//connect to REST App
|
|
63
|
-
send("connection", cConfig);
|
|
64
|
-
};
|
|
65
|
-
wsConnection.onmessage = function (event) {
|
|
66
|
-
let name;
|
|
67
|
-
let msg;
|
|
68
|
-
if (event.data instanceof Blob) {
|
|
69
|
-
name = "binaryData";
|
|
70
|
-
} else {
|
|
71
|
-
let obj = JSON.parse(event.data);
|
|
72
|
-
name = obj.message;
|
|
73
|
-
msg = obj.data;
|
|
74
|
-
}
|
|
75
|
-
switch (name) {
|
|
76
|
-
case "ping":
|
|
77
|
-
send("pong", null);
|
|
78
|
-
break;
|
|
79
|
-
case "getUserData":
|
|
80
|
-
connected = true;
|
|
81
|
-
resolve(msg);
|
|
82
|
-
break;
|
|
83
|
-
default:
|
|
84
|
-
exports.onMessage(name, msg);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const send = function(message, data) {
|
|
91
|
-
logger.log("==>", message, data);
|
|
92
|
-
if (wsConnection) {
|
|
93
|
-
wsConnection.send(JSON.stringify({
|
|
94
|
-
message: message,
|
|
95
|
-
data: [data]
|
|
96
|
-
}));
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
exports.send = send;
|
|
101
|
-
|
|
102
|
-
const close = function() {
|
|
103
|
-
if (wsConnection) {
|
|
104
|
-
wsConnection.close();
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
exports.close = close;
|
|
108
|
-
return exports;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
module.exports = {
|
|
112
|
-
createConnection: createConnection
|
|
113
|
-
};
|
package/src/tests/assets/1.jpeg
DELETED
|
Binary file
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File from node-webrtc-examples project
|
|
3
|
-
* https://github.com/node-webrtc/node-webrtc-examples/blob/master/lib/server/webrtc/rtcaudiosourcesinewave.js
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
const { RTCAudioSource } = require('wrtc').nonstandard;
|
|
9
|
-
|
|
10
|
-
const twoPi = 2 * Math.PI;
|
|
11
|
-
|
|
12
|
-
class RTCAudioSourceSineWave {
|
|
13
|
-
constructor(options = {}) {
|
|
14
|
-
options = {
|
|
15
|
-
frequency: 440,
|
|
16
|
-
channelCount: 1,
|
|
17
|
-
panning: null,
|
|
18
|
-
sampleRate: 48000,
|
|
19
|
-
schedule: setTimeout,
|
|
20
|
-
unschedule: clearTimeout,
|
|
21
|
-
...options
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const {
|
|
25
|
-
channelCount,
|
|
26
|
-
sampleRate
|
|
27
|
-
} = options;
|
|
28
|
-
|
|
29
|
-
if (channelCount !== 1 && channelCount !== 2) {
|
|
30
|
-
throw new Error('channelCount must be 1 or 2');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const bitsPerSample = 16;
|
|
34
|
-
const maxValue = Math.pow(2, bitsPerSample) / 2 - 1;
|
|
35
|
-
const numberOfFrames = sampleRate / 100;
|
|
36
|
-
const secondsPerSample = 1 / sampleRate;
|
|
37
|
-
const source = new RTCAudioSource();
|
|
38
|
-
const samples = new Int16Array(channelCount * numberOfFrames);
|
|
39
|
-
|
|
40
|
-
const data = {
|
|
41
|
-
samples,
|
|
42
|
-
sampleRate,
|
|
43
|
-
bitsPerSample,
|
|
44
|
-
channelCount,
|
|
45
|
-
numberOfFrames
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const a = [1, 1];
|
|
49
|
-
|
|
50
|
-
let {
|
|
51
|
-
frequency,
|
|
52
|
-
panning
|
|
53
|
-
} = options;
|
|
54
|
-
|
|
55
|
-
let time = 0;
|
|
56
|
-
|
|
57
|
-
function next() {
|
|
58
|
-
for (let i = 0; i < numberOfFrames; i++, time += secondsPerSample) {
|
|
59
|
-
for (let j = 0; j < channelCount; j++) {
|
|
60
|
-
samples[i * channelCount + j] = a[j] * Math.sin(twoPi * frequency * time) * maxValue;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
source.onData(data);
|
|
64
|
-
// eslint-disable-next-line
|
|
65
|
-
scheduled = options.schedule(next);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
let scheduled = options.schedule(next);
|
|
69
|
-
|
|
70
|
-
this.close = () => {
|
|
71
|
-
options.unschedule(scheduled);
|
|
72
|
-
scheduled = null;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
this.createTrack = () => {
|
|
76
|
-
return source.createTrack();
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
this.setFrequency = newFrequency => {
|
|
80
|
-
frequency = newFrequency;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
this.setPanning = newPanning => {
|
|
84
|
-
if (channelCount === 1) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
panning = newPanning;
|
|
88
|
-
a[0] = 1 - (panning / 100);
|
|
89
|
-
a[1] = 1 - ((100 - panning) / 100);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
this.setPanning(panning);
|
|
93
|
-
|
|
94
|
-
Object.defineProperties(this, {
|
|
95
|
-
frequency: {
|
|
96
|
-
get() {
|
|
97
|
-
return frequency;
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
panning: {
|
|
101
|
-
get() {
|
|
102
|
-
return panning;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
module.exports = RTCAudioSourceSineWave;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* https://github.com/node-webrtc/node-webrtc/blob/develop/docs/nonstandard-apis.md#programmatic-video
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
'use strict';
|
|
6
|
-
|
|
7
|
-
const { RTCVideoSource } = require('wrtc').nonstandard;
|
|
8
|
-
|
|
9
|
-
class RTCVideoSourceWrapper {
|
|
10
|
-
constructor() {
|
|
11
|
-
const source = new RTCVideoSource();
|
|
12
|
-
const width = 320;
|
|
13
|
-
const height = 240;
|
|
14
|
-
const data = new Uint8ClampedArray(width * height * 1.5);
|
|
15
|
-
const frame = { width, height, data };
|
|
16
|
-
|
|
17
|
-
const interval = setInterval(() => {
|
|
18
|
-
// Update the frame in some way before sending.
|
|
19
|
-
source.onFrame(frame);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
this.createTrack = () => {
|
|
23
|
-
return source.createTrack();
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
module.exports = RTCVideoSourceWrapper;
|
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
const wrtc = require("wrtc");
|
|
2
|
-
const RTCAudioSourceSineWave = require("../lib/rtcaudiosourcesinewave");
|
|
3
|
-
const RTCVideoSourceWrapper = require("../lib/rtcvideosourcewrapper");
|
|
4
|
-
const sfu = require("../../sdk/sfu-extended");
|
|
5
|
-
const constants = require("../../sdk/constants");
|
|
6
|
-
const {waitForTracks, waitForPeerConnectionStableState, waitForPeerConnectionState} = require("../util");
|
|
7
|
-
|
|
8
|
-
// Jest default timeout
|
|
9
|
-
const JEST_TIMEOUT = 20000;
|
|
10
|
-
|
|
11
|
-
const SERVER = "ws://127.0.0.1:8080";
|
|
12
|
-
const USER_BOB = "bob@flashphoner.com";
|
|
13
|
-
const BOB_NICKNAME = "bob";
|
|
14
|
-
const USER_ALICE = "alice@flashphoner.com";
|
|
15
|
-
const ALICE_NICKNAME = "alice";
|
|
16
|
-
const PASSWD = "123456";
|
|
17
|
-
|
|
18
|
-
const ROOM_NAME = "TEST_ROOM";
|
|
19
|
-
const PIN = "1234";
|
|
20
|
-
const USE_WAITING_ROOM = true;
|
|
21
|
-
|
|
22
|
-
let sfu2;
|
|
23
|
-
|
|
24
|
-
jest.setTimeout(JEST_TIMEOUT);
|
|
25
|
-
jest.isolateModules(() => {
|
|
26
|
-
sfu2 = require("../../sdk/sfu-extended");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
function stopAfterTimeout(done) {
|
|
30
|
-
console.log("Test ended");
|
|
31
|
-
setTimeout(done, 5000);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
beforeAll(async () => {
|
|
35
|
-
await sfu.connect({
|
|
36
|
-
url: SERVER,
|
|
37
|
-
username: USER_BOB,
|
|
38
|
-
password: PASSWD
|
|
39
|
-
});
|
|
40
|
-
await sfu2.connect({
|
|
41
|
-
url: SERVER,
|
|
42
|
-
username: USER_ALICE,
|
|
43
|
-
password: PASSWD
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
afterAll(async () => {
|
|
48
|
-
await sfu2.disconnect();
|
|
49
|
-
await sfu.disconnect();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe("room", () => {
|
|
53
|
-
it("should create new room", async () => {
|
|
54
|
-
const room = sfu.room({
|
|
55
|
-
name: ROOM_NAME,
|
|
56
|
-
pin: PIN,
|
|
57
|
-
pc: new wrtc.RTCPeerConnection()
|
|
58
|
-
});
|
|
59
|
-
const ret = await room.createRoom();
|
|
60
|
-
expect(ret).toBeTruthy();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("should join the room", async () => {
|
|
64
|
-
const room = sfu.getRoom({name: ROOM_NAME});
|
|
65
|
-
const ret = await room.join();
|
|
66
|
-
expect(ret).toBeTruthy();
|
|
67
|
-
await waitForPeerConnectionStableState(room.pc());
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("should configure waiting room", async () => {
|
|
71
|
-
const room = sfu.getRoom({name: ROOM_NAME});
|
|
72
|
-
await room.configureWaitingRoom(USE_WAITING_ROOM);
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
describe("second participant", () => {
|
|
76
|
-
it("should be successfully authorized and joined to the room", async (done) => {
|
|
77
|
-
console.log("should be successfully authorized and joined to the room");
|
|
78
|
-
const room = sfu.getRoom({name: ROOM_NAME});
|
|
79
|
-
const waitingListHandler = async (event) => {
|
|
80
|
-
if (event.users && event.users.length !== 0) {
|
|
81
|
-
const users = event.users;
|
|
82
|
-
for (const waitingUser of users) {
|
|
83
|
-
const info = await room.subscribeToWaitingParticipant(waitingUser.nickname);
|
|
84
|
-
expect(info).toBeTruthy();
|
|
85
|
-
expect(Array.isArray(info.info)).toBeTruthy();
|
|
86
|
-
expect(info.info.length).toEqual(1);
|
|
87
|
-
await waitForTracks(room.pc(), info.info);
|
|
88
|
-
await room.unsubscribeFromWaitingParticipant(waitingUser.nickname);
|
|
89
|
-
await room.authorizeWaitingList(waitingUser.id, true);
|
|
90
|
-
await waitForPeerConnectionStableState(room.pc());
|
|
91
|
-
}
|
|
92
|
-
room.off(sfu.constants.SFU_ROOM_EVENT.WAITING_LIST, waitingListHandler);
|
|
93
|
-
done();
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
room.on(sfu.constants.SFU_ROOM_EVENT.WAITING_LIST, waitingListHandler);
|
|
97
|
-
const room2 = sfu2.room({
|
|
98
|
-
name: ROOM_NAME,
|
|
99
|
-
pin: PIN,
|
|
100
|
-
pc: new wrtc.RTCPeerConnection()
|
|
101
|
-
});
|
|
102
|
-
// Audio track
|
|
103
|
-
const aSource = new RTCAudioSourceSineWave();
|
|
104
|
-
const aTrack = aSource.createTrack();
|
|
105
|
-
const aSender = room2.pc().addTrack(aTrack);
|
|
106
|
-
|
|
107
|
-
const ret = await room2.join({});
|
|
108
|
-
expect(ret).toBeTruthy();
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("should set new role for the second participant", async () => {
|
|
112
|
-
const room = sfu.getRoom({name: ROOM_NAME});
|
|
113
|
-
await room.assignRole(ALICE_NICKNAME, sfu.constants.SFU_PARTICIPANT_ROLE.ADMIN);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("should be able to send message", async () => {
|
|
117
|
-
const room = sfu.getRoom({name: ROOM_NAME});
|
|
118
|
-
await room.sendMessage("should be able to send message");
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it("should be able to send message more then 16384 characters long", async () => {
|
|
122
|
-
const messageLength = 20000;
|
|
123
|
-
const letter = "a";
|
|
124
|
-
let msg = "";
|
|
125
|
-
for (let i = 0; i < messageLength; i++) {
|
|
126
|
-
msg += letter;
|
|
127
|
-
}
|
|
128
|
-
const room = sfu.getRoom({name: ROOM_NAME});
|
|
129
|
-
await room.sendMessage(msg);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("should receive message", async (done) => {
|
|
133
|
-
const msg = "should receive message";
|
|
134
|
-
const room = sfu.getRoom({name: ROOM_NAME});
|
|
135
|
-
const room2 = sfu2.getRoom({name: ROOM_NAME});
|
|
136
|
-
const messageHandler = (message) => {
|
|
137
|
-
expect(message).toBeTruthy();
|
|
138
|
-
expect(message.message).toEqual(msg);
|
|
139
|
-
room2.off(sfu.constants.SFU_ROOM_EVENT.MESSAGE, messageHandler);
|
|
140
|
-
done();
|
|
141
|
-
}
|
|
142
|
-
room2.on(sfu.constants.SFU_ROOM_EVENT.MESSAGE, messageHandler);
|
|
143
|
-
room.sendMessage(msg);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("should receive message more then 16384 characters long", async (done) => {
|
|
147
|
-
const messageLength = 20000;
|
|
148
|
-
const letter = "a";
|
|
149
|
-
let msg = "";
|
|
150
|
-
for (let i = 0; i < messageLength; i++) {
|
|
151
|
-
msg += letter;
|
|
152
|
-
}
|
|
153
|
-
const room = sfu.getRoom({name: ROOM_NAME});
|
|
154
|
-
const room2 = sfu2.getRoom({name: ROOM_NAME});
|
|
155
|
-
const messageHandler = (message) => {
|
|
156
|
-
expect(message).toBeTruthy();
|
|
157
|
-
expect(message.message).toEqual(msg);
|
|
158
|
-
room.off(sfu.constants.SFU_ROOM_EVENT.MESSAGE, messageHandler);
|
|
159
|
-
done();
|
|
160
|
-
}
|
|
161
|
-
room.on(sfu.constants.SFU_ROOM_EVENT.MESSAGE, messageHandler);
|
|
162
|
-
room2.sendMessage(msg);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it("should leave the room", async () => {
|
|
166
|
-
const room2 = sfu2.getRoom({name: ROOM_NAME});
|
|
167
|
-
await room2.leaveRoom();
|
|
168
|
-
await waitForPeerConnectionState(room2.pc(), "closed");
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it("the owner should be able to move it to the waiting room", async (done) => {
|
|
172
|
-
const room = sfu.getRoom({name: ROOM_NAME});
|
|
173
|
-
room.on(sfu.constants.SFU_ROOM_EVENT.JOINED, async (participant) => {
|
|
174
|
-
await room.moveToWaitingRoom(participant.name);
|
|
175
|
-
done();
|
|
176
|
-
});
|
|
177
|
-
await room.configureWaitingRoom(false);
|
|
178
|
-
const room2 = sfu2.room({
|
|
179
|
-
name: ROOM_NAME,
|
|
180
|
-
pin: PIN,
|
|
181
|
-
pc: new wrtc.RTCPeerConnection()
|
|
182
|
-
});
|
|
183
|
-
await room2.join({});
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it("should update room state", async () => {
|
|
188
|
-
const room = sfu.getRoom({name: ROOM_NAME});
|
|
189
|
-
// Audio track
|
|
190
|
-
const aSource = new RTCAudioSourceSineWave();
|
|
191
|
-
const aTrack = aSource.createTrack();
|
|
192
|
-
const aSender = room.pc().addTrack(aTrack);
|
|
193
|
-
// Video track
|
|
194
|
-
const vSource = new RTCVideoSourceWrapper();
|
|
195
|
-
const vTrack = vSource.createTrack();
|
|
196
|
-
const vSender = room.pc().addTrack(vTrack);
|
|
197
|
-
|
|
198
|
-
await room.updateState({});
|
|
199
|
-
await waitForPeerConnectionStableState(room.pc());
|
|
200
|
-
aTrack.stop();
|
|
201
|
-
aSource.close();
|
|
202
|
-
vTrack.stop();
|
|
203
|
-
room.pc().removeTrack(aSender);
|
|
204
|
-
room.pc().removeTrack(vSender);
|
|
205
|
-
await room.updateState();
|
|
206
|
-
await waitForPeerConnectionStableState(room.pc());
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it("should leave room", async () => {
|
|
210
|
-
const room = sfu.getRoom({name: ROOM_NAME});
|
|
211
|
-
const ret = await room.leaveRoom();
|
|
212
|
-
expect(ret).toBeTruthy();
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it("should destroy room", async (done) => {
|
|
216
|
-
const room = sfu.room({
|
|
217
|
-
name: ROOM_NAME,
|
|
218
|
-
pin: PIN,
|
|
219
|
-
pc: new wrtc.RTCPeerConnection()
|
|
220
|
-
});
|
|
221
|
-
room.on(constants.SFU_ROOM_EVENT.EVICTED, () => {
|
|
222
|
-
expect(sfu.getRoom({name: ROOM_NAME})).toBeFalsy();
|
|
223
|
-
done();
|
|
224
|
-
});
|
|
225
|
-
await room.createRoom();
|
|
226
|
-
await room.join();
|
|
227
|
-
await room.destroyRoom();
|
|
228
|
-
});
|
|
229
|
-
});
|