@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.
Files changed (207) hide show
  1. package/dist/client.version +1 -0
  2. package/dist/examples/sfu.d.ts +13 -0
  3. package/dist/index.d.ts +6 -0
  4. package/dist/index.js +15 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/sdk/connection.d.ts +25 -0
  7. package/dist/sdk/connection.js +101 -0
  8. package/dist/sdk/connection.js.map +1 -0
  9. package/dist/sdk/constants.d.ts +364 -0
  10. package/dist/sdk/constants.js +192 -0
  11. package/dist/sdk/constants.js.map +1 -0
  12. package/dist/sdk/logger.d.ts +10 -0
  13. package/dist/sdk/logger.js +22 -0
  14. package/dist/sdk/logger.js.map +1 -0
  15. package/dist/sdk/notifier.d.ts +7 -0
  16. package/dist/sdk/notifier.js +52 -0
  17. package/dist/sdk/notifier.js.map +1 -0
  18. package/dist/sdk/promises.d.ts +11 -0
  19. package/{src/sdk/promise.js → dist/sdk/promises.js} +14 -13
  20. package/dist/sdk/promises.js.map +1 -0
  21. package/dist/sdk/room-extended.d.ts +14 -0
  22. package/dist/sdk/room-extended.js +125 -0
  23. package/dist/sdk/room-extended.js.map +1 -0
  24. package/dist/sdk/room.d.ts +30 -0
  25. package/dist/sdk/room.js +370 -0
  26. package/dist/sdk/room.js.map +1 -0
  27. package/dist/sdk/sfu-extended.d.ts +132 -0
  28. package/dist/sdk/sfu-extended.js +525 -0
  29. package/dist/sdk/sfu-extended.js.map +1 -0
  30. package/dist/sdk/sfu.d.ts +22 -0
  31. package/dist/sdk/sfu.js +136 -0
  32. package/dist/sdk/sfu.js.map +1 -0
  33. package/dist/src/index.d.ts +6 -0
  34. package/dist/src/sdk/connection.d.ts +25 -0
  35. package/dist/src/sdk/constants.d.ts +364 -0
  36. package/dist/src/sdk/logger.d.ts +10 -0
  37. package/dist/src/sdk/notifier.d.ts +7 -0
  38. package/dist/src/sdk/promises.d.ts +11 -0
  39. package/dist/src/sdk/room-extended.d.ts +14 -0
  40. package/dist/src/sdk/room.d.ts +30 -0
  41. package/dist/src/sdk/sfu-extended.d.ts +132 -0
  42. package/dist/src/sdk/sfu.d.ts +22 -0
  43. package/package.json +27 -27
  44. package/Gruntfile.js +0 -79
  45. package/README.md +0 -95
  46. package/dependencies/bootstrap/css/bootstrap-theme.css +0 -587
  47. package/dependencies/bootstrap/css/bootstrap-theme.css.map +0 -1
  48. package/dependencies/bootstrap/css/bootstrap-theme.min.css +0 -5
  49. package/dependencies/bootstrap/css/bootstrap.css +0 -6853
  50. package/dependencies/bootstrap/css/bootstrap.css.map +0 -1
  51. package/dependencies/bootstrap/css/bootstrap.min.css +0 -5
  52. package/dependencies/bootstrap/font-awesome/HELP-US-OUT.txt +0 -7
  53. package/dependencies/bootstrap/font-awesome/css/font-awesome.css +0 -2178
  54. package/dependencies/bootstrap/font-awesome/css/font-awesome.min.css +0 -4
  55. package/dependencies/bootstrap/font-awesome/fonts/FontAwesome.otf +0 -0
  56. package/dependencies/bootstrap/font-awesome/fonts/fontawesome-webfont.eot +0 -0
  57. package/dependencies/bootstrap/font-awesome/fonts/fontawesome-webfont.svg +0 -685
  58. package/dependencies/bootstrap/font-awesome/fonts/fontawesome-webfont.ttf +0 -0
  59. package/dependencies/bootstrap/font-awesome/fonts/fontawesome-webfont.woff +0 -0
  60. package/dependencies/bootstrap/font-awesome/fonts/fontawesome-webfont.woff2 +0 -0
  61. package/dependencies/bootstrap/font-awesome/less/animated.less +0 -34
  62. package/dependencies/bootstrap/font-awesome/less/bordered-pulled.less +0 -25
  63. package/dependencies/bootstrap/font-awesome/less/core.less +0 -12
  64. package/dependencies/bootstrap/font-awesome/less/fixed-width.less +0 -6
  65. package/dependencies/bootstrap/font-awesome/less/font-awesome.less +0 -18
  66. package/dependencies/bootstrap/font-awesome/less/icons.less +0 -724
  67. package/dependencies/bootstrap/font-awesome/less/larger.less +0 -13
  68. package/dependencies/bootstrap/font-awesome/less/list.less +0 -19
  69. package/dependencies/bootstrap/font-awesome/less/mixins.less +0 -60
  70. package/dependencies/bootstrap/font-awesome/less/path.less +0 -15
  71. package/dependencies/bootstrap/font-awesome/less/rotated-flipped.less +0 -20
  72. package/dependencies/bootstrap/font-awesome/less/screen-reader.less +0 -5
  73. package/dependencies/bootstrap/font-awesome/less/stacked.less +0 -20
  74. package/dependencies/bootstrap/font-awesome/less/variables.less +0 -735
  75. package/dependencies/bootstrap/font-awesome/scss/_animated.scss +0 -34
  76. package/dependencies/bootstrap/font-awesome/scss/_bordered-pulled.scss +0 -25
  77. package/dependencies/bootstrap/font-awesome/scss/_core.scss +0 -12
  78. package/dependencies/bootstrap/font-awesome/scss/_fixed-width.scss +0 -6
  79. package/dependencies/bootstrap/font-awesome/scss/_icons.scss +0 -724
  80. package/dependencies/bootstrap/font-awesome/scss/_larger.scss +0 -13
  81. package/dependencies/bootstrap/font-awesome/scss/_list.scss +0 -19
  82. package/dependencies/bootstrap/font-awesome/scss/_mixins.scss +0 -60
  83. package/dependencies/bootstrap/font-awesome/scss/_path.scss +0 -15
  84. package/dependencies/bootstrap/font-awesome/scss/_rotated-flipped.scss +0 -20
  85. package/dependencies/bootstrap/font-awesome/scss/_screen-reader.scss +0 -5
  86. package/dependencies/bootstrap/font-awesome/scss/_stacked.scss +0 -20
  87. package/dependencies/bootstrap/font-awesome/scss/_variables.scss +0 -735
  88. package/dependencies/bootstrap/font-awesome/scss/font-awesome.scss +0 -18
  89. package/dependencies/bootstrap/fonts/FontAwesome.otf +0 -0
  90. package/dependencies/bootstrap/fonts/fontawesome-webfont.eot +0 -0
  91. package/dependencies/bootstrap/fonts/fontawesome-webfont.svg +0 -655
  92. package/dependencies/bootstrap/fonts/fontawesome-webfont.ttf +0 -0
  93. package/dependencies/bootstrap/fonts/fontawesome-webfont.woff +0 -0
  94. package/dependencies/bootstrap/fonts/fontawesome-webfont.woff2 +0 -0
  95. package/dependencies/bootstrap/fonts/glyphicons-halflings-regular.eot +0 -0
  96. package/dependencies/bootstrap/fonts/glyphicons-halflings-regular.svg +0 -288
  97. package/dependencies/bootstrap/fonts/glyphicons-halflings-regular.ttf +0 -0
  98. package/dependencies/bootstrap/fonts/glyphicons-halflings-regular.woff +0 -0
  99. package/dependencies/bootstrap/fonts/glyphicons-halflings-regular.woff2 +0 -0
  100. package/dependencies/bootstrap/icons/font-awesome.min.css +0 -4
  101. package/dependencies/bootstrap/js/bootstrap.js +0 -2363
  102. package/dependencies/bootstrap/js/bootstrap.min.js +0 -7
  103. package/dependencies/bootstrap/js/npm.js +0 -13
  104. package/dependencies/bootstrap/js/switch.js +0 -85
  105. package/dependencies/jquery/jquery-1.12.0.js +0 -11027
  106. package/dependencies/jquery/jquery-ui.js +0 -16617
  107. package/dependencies/jquery/jquery.js +0 -8981
  108. package/dependencies/jquery/jquery.json.js +0 -199
  109. package/dependencies/jquery/jquery.websocket.js +0 -61
  110. package/dependencies/sigma/sigma.layout.forceAtlas2.min.js +0 -1
  111. package/dependencies/sigma/sigma.layout.noverlap.min.js +0 -1
  112. package/dependencies/sigma/sigma.min.js +0 -2
  113. package/dependencies/sigma/sigma.plugins.relativeSize.min.js +0 -1
  114. package/dependencies/sigma/sigma.renderers.edgeLabels.min.js +0 -1
  115. package/dependencies/sigma/sigma.renderers.parallelEdges.min.js +0 -1
  116. package/dependencies/sigma/sigma.require.js +0 -12076
  117. package/docTemplate/README.md +0 -5
  118. package/docTemplate/publish.js +0 -654
  119. package/docTemplate/static/fonts/OpenSans-Bold-webfont.eot +0 -0
  120. package/docTemplate/static/fonts/OpenSans-Bold-webfont.svg +0 -1830
  121. package/docTemplate/static/fonts/OpenSans-Bold-webfont.woff +0 -0
  122. package/docTemplate/static/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  123. package/docTemplate/static/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  124. package/docTemplate/static/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  125. package/docTemplate/static/fonts/OpenSans-Italic-webfont.eot +0 -0
  126. package/docTemplate/static/fonts/OpenSans-Italic-webfont.svg +0 -1830
  127. package/docTemplate/static/fonts/OpenSans-Italic-webfont.woff +0 -0
  128. package/docTemplate/static/fonts/OpenSans-Light-webfont.eot +0 -0
  129. package/docTemplate/static/fonts/OpenSans-Light-webfont.svg +0 -1831
  130. package/docTemplate/static/fonts/OpenSans-Light-webfont.woff +0 -0
  131. package/docTemplate/static/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  132. package/docTemplate/static/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  133. package/docTemplate/static/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  134. package/docTemplate/static/fonts/OpenSans-Regular-webfont.eot +0 -0
  135. package/docTemplate/static/fonts/OpenSans-Regular-webfont.svg +0 -1831
  136. package/docTemplate/static/fonts/OpenSans-Regular-webfont.woff +0 -0
  137. package/docTemplate/static/scripts/linenumber.js +0 -25
  138. package/docTemplate/static/scripts/prettify/Apache-License-2.0.txt +0 -202
  139. package/docTemplate/static/scripts/prettify/lang-css.js +0 -2
  140. package/docTemplate/static/scripts/prettify/prettify.js +0 -28
  141. package/docTemplate/static/styles/jsdoc-default.css +0 -354
  142. package/docTemplate/static/styles/prettify-jsdoc.css +0 -111
  143. package/docTemplate/static/styles/prettify-tomorrow.css +0 -132
  144. package/docTemplate/tmpl/augments.tmpl +0 -10
  145. package/docTemplate/tmpl/container.tmpl +0 -183
  146. package/docTemplate/tmpl/details.tmpl +0 -143
  147. package/docTemplate/tmpl/example.tmpl +0 -2
  148. package/docTemplate/tmpl/examples.tmpl +0 -13
  149. package/docTemplate/tmpl/exceptions.tmpl +0 -32
  150. package/docTemplate/tmpl/layout.tmpl +0 -38
  151. package/docTemplate/tmpl/mainpage.tmpl +0 -14
  152. package/docTemplate/tmpl/members.tmpl +0 -38
  153. package/docTemplate/tmpl/method.tmpl +0 -105
  154. package/docTemplate/tmpl/params.tmpl +0 -124
  155. package/docTemplate/tmpl/properties.tmpl +0 -108
  156. package/docTemplate/tmpl/returns.tmpl +0 -19
  157. package/docTemplate/tmpl/source.tmpl +0 -8
  158. package/docTemplate/tmpl/tutorial.tmpl +0 -19
  159. package/docTemplate/tmpl/type.tmpl +0 -7
  160. package/src/examples/client/chat.js +0 -67
  161. package/src/examples/client/config.json +0 -26
  162. package/src/examples/client/controls.js +0 -314
  163. package/src/examples/client/display.js +0 -502
  164. package/src/examples/client/main.css +0 -45
  165. package/src/examples/client/main.html +0 -220
  166. package/src/examples/client/main.js +0 -156
  167. package/src/examples/client/resources/details_close.png +0 -0
  168. package/src/examples/client/resources/details_open.png +0 -0
  169. package/src/examples/client/util.js +0 -67
  170. package/src/examples/commons/js/config.js +0 -81
  171. package/src/examples/commons/js/display.js +0 -484
  172. package/src/examples/commons/js/util.js +0 -202
  173. package/src/examples/commons/media/silence.mp3 +0 -0
  174. package/src/examples/controller/dependencies/sigma/sigma.renderers.edgeLabels.min.js +0 -1
  175. package/src/examples/controller/dependencies/sigma/sigma.renderers.parallelEdges.min.js +0 -1
  176. package/src/examples/controller/dependencies/sigma/sigma.require.js +0 -12076
  177. package/src/examples/controller/graph-view.js +0 -32
  178. package/src/examples/controller/main.css +0 -45
  179. package/src/examples/controller/main.html +0 -79
  180. package/src/examples/controller/main.js +0 -65
  181. package/src/examples/controller/parser.js +0 -202
  182. package/src/examples/controller/resources/details_close.png +0 -0
  183. package/src/examples/controller/resources/details_open.png +0 -0
  184. package/src/examples/controller/rest.js +0 -56
  185. package/src/examples/controller/table-view.js +0 -64
  186. package/src/examples/controller/test-data.js +0 -382
  187. package/src/examples/player/config.json +0 -8
  188. package/src/examples/player/player.css +0 -19
  189. package/src/examples/player/player.html +0 -54
  190. package/src/examples/player/player.js +0 -209
  191. package/src/examples/two-way-streaming/config.json +0 -34
  192. package/src/examples/two-way-streaming/two-way-streaming.css +0 -26
  193. package/src/examples/two-way-streaming/two-way-streaming.html +0 -72
  194. package/src/examples/two-way-streaming/two-way-streaming.js +0 -375
  195. package/src/sdk/constants.js +0 -514
  196. package/src/sdk/logger.js +0 -16
  197. package/src/sdk/room.js +0 -594
  198. package/src/sdk/sfu-extended.js +0 -843
  199. package/src/sdk/sfu.js +0 -208
  200. package/src/sdk/ws.js +0 -113
  201. package/src/tests/assets/1.jpeg +0 -0
  202. package/src/tests/lib/rtcaudiosourcesinewave.js +0 -109
  203. package/src/tests/lib/rtcvideosourcewrapper.js +0 -28
  204. package/src/tests/sdk/room.test.js +0 -229
  205. package/src/tests/sdk/sfu-extended.test.js +0 -265
  206. package/src/tests/sdk/sfu-extended.test.js_ +0 -265
  207. 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
- };
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
- });