@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
@@ -1,265 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const sfu = require("../../sdk/sfu-extended");
4
- const constants = require("../../sdk/constants");
5
-
6
- const SERVER = "ws://127.0.0.1:8080";
7
- const USER = "bob@flashphoner.com";
8
- const PASSWD = "123456";
9
- const CHAT_ID = "test-chat-id";
10
- const CHANNEL_ID = "test-channel-id";
11
- const CHANNEL_NAME = "test-channel";
12
- const CHAT_NAME = "test-chat";
13
- const CHAT_NAME2 = "test-chat2";
14
- const USER2 = "alice@flashphoner.com";
15
- const MESSAGE_BODY = "This is a test message";
16
- const MEMBERS = [
17
- "bob@flashphoner.com",
18
- "alice@flashphoner.com",
19
- "kiri@flashphoner.com"
20
- ];
21
- const FILE = "../assets/1.jpeg";
22
-
23
- jest.isolateModules(() => {
24
- sfu2 = require("../../sdk/sfu-extended");
25
- });
26
-
27
- beforeAll( async () => {
28
- await sfu.connect({
29
- url: SERVER,
30
- username: USER,
31
- password: PASSWD
32
- });
33
- const chats = await sfu.getUserChats();
34
- if (chats) {
35
- Object.entries(chats).map(async ([key, value]) => {
36
- await sfu.deleteChat({id: value.id});
37
- });
38
- }
39
- await sfu2.connect({
40
- url: SERVER,
41
- username: USER2,
42
- password: PASSWD
43
- });
44
- });
45
-
46
- afterAll(async () => {
47
- await sfu.disconnect();
48
- await sfu2.disconnect();
49
- });
50
-
51
-
52
- describe("connection", () => {
53
- test("should connect to server", () => {
54
- expect(sfu.state()).toBe(constants.SFU_STATE.AUTHENTICATED);
55
- });
56
- });
57
-
58
- describe("contacts", () => {
59
- test("should load user list", () => {
60
- return sfu.getUserList();
61
- });
62
- });
63
-
64
- describe("calendar", () => {
65
- test("should load calendar", () => {
66
- return sfu.getUserCalendar().then((calendar) => {
67
- expect(calendar).toHaveProperty("events");
68
- })
69
- })
70
- });
71
-
72
- describe("chat", () => {
73
- test("should create new chat", () => {
74
- return sfu.createChat({
75
- id: CHAT_ID,
76
- name: CHAT_NAME
77
- });
78
- });
79
- describe("channels", () => {
80
- test("should create new channel", () => {
81
- return sfu.createChat({
82
- id: CHANNEL_ID,
83
- name: CHANNEL_NAME,
84
- members: [USER2],
85
- channel: true,
86
- channelType: "PUBLIC",
87
- channelSendPolicy: "ADMIN_AND_LIST",
88
- sendPermissionList: [USER2]
89
- });
90
- });
91
- test("should load public channels", async () => {
92
- const channels = await sfu.getPublicChannels();
93
- expect(channels).toBeTruthy();
94
- expect(channels).toHaveProperty(CHANNEL_ID);
95
- });
96
- test("channel should appear in loaded chats", async () => {
97
- const chats = await sfu.getUserChats();
98
- expect(chats).toBeTruthy();
99
- expect(chats).toHaveProperty(CHANNEL_ID);
100
- });
101
- test("should load channel", async () => {
102
- const chat = await sfu.loadChat({id: CHANNEL_ID});
103
- expect(chat.id).toBe(CHANNEL_ID);
104
- expect(chat.name).toBe(CHANNEL_NAME);
105
- expect(chat.members).toContain(USER);
106
- expect(chat.channel).toBe(true);
107
- });
108
- });
109
- test("should load chats", () => {
110
- return sfu.getUserChats().then((chats) => {
111
- expect(chats).toBeTruthy();
112
- });
113
- });
114
- test("should add new member", () => {
115
- return sfu.addMemberToChat({
116
- id: CHAT_ID,
117
- member: USER2
118
- });
119
- });
120
- test("should send a message", () => {
121
- return sfu.sendMessage({
122
- chatId: CHAT_ID,
123
- body: MESSAGE_BODY
124
- });
125
- });
126
- test("should send message with attachment", () => {
127
- const file = fs.readFileSync(path.resolve(__dirname, FILE));
128
- let byteArray = new Uint8Array(file);
129
- let base64Content = Buffer.from(byteArray).toString('base64');
130
- return sfu.sendMessage({
131
- chatId: CHAT_ID,
132
- body: MESSAGE_BODY,
133
- attachments: [
134
- {
135
- type: "file",
136
- name: FILE,
137
- payload: base64Content,
138
- size: byteArray.length
139
- }
140
- ]
141
- });
142
- });
143
- test("should mark message as read", async () => {
144
- const msg = await sfu.sendMessage({
145
- chatId: CHAT_ID,
146
- body: MESSAGE_BODY
147
- });
148
- const freshState = await sfu.markMessageRead(msg);
149
- expect(freshState.lastReadMessageId).toBeTruthy();
150
- expect(freshState).toBeTruthy();
151
- });
152
- test("should mark message as unread", async () => {
153
- const msg1 = await sfu.sendMessage({
154
- chatId: CHAT_ID,
155
- body: MESSAGE_BODY
156
- });
157
- const msg2 = await sfu.sendMessage({
158
- chatId: CHAT_ID,
159
- body: MESSAGE_BODY
160
- });
161
- const freshState = await sfu.markMessageUnread(msg2);
162
- expect(freshState).toBeTruthy();
163
- expect(freshState.lastReadMessageId).toBeTruthy();
164
- expect(freshState.lastReadMessageId).toEqual(msg1.id);
165
- });
166
- test("should load chat", () => {
167
- return sfu.loadChat({
168
- id: CHAT_ID
169
- }).then((chat) => {
170
- expect(chat.id).toBe(CHAT_ID);
171
- expect(chat.name).toBe(CHAT_NAME);
172
- expect(chat.members).toContain(USER);
173
- expect(Array.isArray(chat.messages)).toBe(true);
174
- expect(chat.messages.length).toBeGreaterThan(0);
175
- });
176
- });
177
- test("should remove member", () => {
178
- return sfu.removeMemberFromChat({
179
- id: CHAT_ID,
180
- member: USER2
181
- });
182
- });
183
- test("should rename chat", () => {
184
- return sfu.renameChat({
185
- id: CHAT_ID,
186
- name: CHAT_NAME2
187
- });
188
- });
189
- test("should invite contact", async () => {
190
- const contact = await sfu.inviteContact({
191
- to: USER2
192
- });
193
- expect(contact).toBeTruthy();
194
- expect(contact.invite).toBeTruthy();
195
- expect(contact.invite.id).toBeTruthy();
196
- });
197
- test("should confirm invite", async () => {
198
- const contacts = await sfu2.getUserList();
199
- let unconfirmedContact;
200
- contacts.every((contact) => {
201
- if (contact.invite && contact.invite.from !== USER2) {
202
- unconfirmedContact = contact;
203
- return false;
204
- }
205
- return true;
206
- });
207
- expect(unconfirmedContact).toBeTruthy();
208
- const contact = await sfu2.confirmContact(unconfirmedContact.invite);
209
- expect(contact).toBeTruthy();
210
- expect(contact.confirmed).toEqual(true);
211
- });
212
- test("should remove contact", async () => {
213
- const contact = await sfu.removeContact({
214
- id: USER2
215
- });
216
- expect(contact).toBeTruthy();
217
- });
218
- test.skip("should receive message", (done) => {
219
- sfu.on(constants.SFU_EVENT.MESSAGE, (msg) => {
220
- done();
221
- })
222
- sfu.sendMessage({
223
- chatId: CHAT_ID,
224
- body: MESSAGE_BODY
225
- });
226
- });
227
- test("should receive ACK message", async () => {
228
- const msg = await sfu.sendMessage({
229
- chatId: CHAT_ID,
230
- body: MESSAGE_BODY
231
- });
232
- expect(msg).toBeTruthy();
233
- expect(msg.id).toBeTruthy();
234
- expect(msg.date).toBeTruthy();
235
- });
236
- test("should create new chat without id", () => {
237
- return sfu.createChat({
238
- name: CHAT_NAME
239
- });
240
- });
241
- test("should create new chat with member list", () => {
242
- return sfu.createChat({
243
- name: CHAT_NAME,
244
- members: MEMBERS
245
- });
246
- });
247
- test("should create new chat without name based on members", async () => {
248
- const chat = await sfu.createChat({
249
- members: MEMBERS
250
- });
251
- expect(chat.name).toBeTruthy();
252
- });
253
- test("should delete chat", () => {
254
- return sfu.deleteChat({
255
- id: CHAT_ID
256
- });
257
- });
258
- test("should change name after member was added", async () => {
259
- const chat = await sfu.createChat({});
260
- expect(chat.name).toBeTruthy();
261
- const name1 = chat.name;
262
- const sameChat = await sfu.addMemberToChat({id: chat.id, member: USER2});
263
- expect(sameChat.name !== name1).toBeTruthy();
264
- });
265
- });
@@ -1,265 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const sfu = require("../../sdk/sfu-extended");
4
- const constants = require("../../sdk/constants");
5
-
6
- const SERVER = "ws://127.0.0.1:8080";
7
- const USER = "bob@flashphoner.com";
8
- const PASSWD = "123456";
9
- const CHAT_ID = "test-chat-id";
10
- const CHANNEL_ID = "test-channel-id";
11
- const CHANNEL_NAME = "test-channel";
12
- const CHAT_NAME = "test-chat";
13
- const CHAT_NAME2 = "test-chat2";
14
- const USER2 = "alice@flashphoner.com";
15
- const MESSAGE_BODY = "This is a test message";
16
- const MEMBERS = [
17
- "bob@flashphoner.com",
18
- "alice@flashphoner.com",
19
- "kiri@flashphoner.com"
20
- ];
21
- const FILE = "../assets/1.jpeg";
22
-
23
- jest.isolateModules(() => {
24
- sfu2 = require("../../sdk/sfu-extended");
25
- });
26
-
27
- beforeAll( async () => {
28
- await sfu.connect({
29
- url: SERVER,
30
- username: USER,
31
- password: PASSWD
32
- });
33
- const chats = await sfu.getUserChats();
34
- if (chats) {
35
- Object.entries(chats).map(async ([key, value]) => {
36
- await sfu.deleteChat({id: value.id});
37
- });
38
- }
39
- await sfu2.connect({
40
- url: SERVER,
41
- username: USER2,
42
- password: PASSWD
43
- });
44
- });
45
-
46
- afterAll(async () => {
47
- await sfu.disconnect();
48
- await sfu2.disconnect();
49
- });
50
-
51
-
52
- describe("connection", () => {
53
- test("should connect to server", () => {
54
- expect(sfu.state()).toBe(constants.SFU_STATE.AUTHENTICATED);
55
- });
56
- });
57
-
58
- describe("contacts", () => {
59
- test("should load user list", () => {
60
- return sfu.getUserList();
61
- });
62
- });
63
-
64
- describe("calendar", () => {
65
- test("should load calendar", () => {
66
- return sfu.getUserCalendar().then((calendar) => {
67
- expect(calendar).toHaveProperty("events");
68
- })
69
- })
70
- });
71
-
72
- describe("chat", () => {
73
- test("should create new chat", () => {
74
- return sfu.createChat({
75
- id: CHAT_ID,
76
- name: CHAT_NAME
77
- });
78
- });
79
- describe("channels", () => {
80
- test("should create new channel", () => {
81
- return sfu.createChat({
82
- id: CHANNEL_ID,
83
- name: CHANNEL_NAME,
84
- members: [USER2],
85
- channel: true,
86
- channelType: "PUBLIC",
87
- channelSendPolicy: "ADMIN_AND_LIST",
88
- sendPermissionList: [USER2]
89
- });
90
- });
91
- test("should load public channels", async () => {
92
- const channels = await sfu.getPublicChannels();
93
- expect(channels).toBeTruthy();
94
- expect(channels).toHaveProperty(CHANNEL_ID);
95
- });
96
- test("channel should appear in loaded chats", async () => {
97
- const chats = await sfu.getUserChats();
98
- expect(chats).toBeTruthy();
99
- expect(chats).toHaveProperty(CHANNEL_ID);
100
- });
101
- test("should load channel", async () => {
102
- const chat = await sfu.loadChat({id: CHANNEL_ID});
103
- expect(chat.id).toBe(CHANNEL_ID);
104
- expect(chat.name).toBe(CHANNEL_NAME);
105
- expect(chat.members).toContain(USER);
106
- expect(chat.channel).toBe(true);
107
- });
108
- });
109
- test("should load chats", () => {
110
- return sfu.getUserChats().then((chats) => {
111
- expect(chats).toBeTruthy();
112
- });
113
- });
114
- test("should add new member", () => {
115
- return sfu.addMemberToChat({
116
- id: CHAT_ID,
117
- member: USER2
118
- });
119
- });
120
- test("should send a message", () => {
121
- return sfu.sendMessage({
122
- chatId: CHAT_ID,
123
- body: MESSAGE_BODY
124
- });
125
- });
126
- test("should send message with attachment", () => {
127
- const file = fs.readFileSync(path.resolve(__dirname, FILE));
128
- let byteArray = new Uint8Array(file);
129
- let base64Content = Buffer.from(byteArray).toString('base64');
130
- return sfu.sendMessage({
131
- chatId: CHAT_ID,
132
- body: MESSAGE_BODY,
133
- attachments: [
134
- {
135
- type: "file",
136
- name: FILE,
137
- payload: base64Content,
138
- size: byteArray.length
139
- }
140
- ]
141
- });
142
- });
143
- test("should mark message as read", async () => {
144
- const msg = await sfu.sendMessage({
145
- chatId: CHAT_ID,
146
- body: MESSAGE_BODY
147
- });
148
- const freshState = await sfu.markMessageRead(msg);
149
- expect(freshState.lastReadMessageId).toBeTruthy();
150
- expect(freshState).toBeTruthy();
151
- });
152
- test("should mark message as unread", async () => {
153
- const msg1 = await sfu.sendMessage({
154
- chatId: CHAT_ID,
155
- body: MESSAGE_BODY
156
- });
157
- const msg2 = await sfu.sendMessage({
158
- chatId: CHAT_ID,
159
- body: MESSAGE_BODY
160
- });
161
- const freshState = await sfu.markMessageUnread(msg2);
162
- expect(freshState).toBeTruthy();
163
- expect(freshState.lastReadMessageId).toBeTruthy();
164
- expect(freshState.lastReadMessageId).toEqual(msg1.id);
165
- });
166
- test("should load chat", () => {
167
- return sfu.loadChat({
168
- id: CHAT_ID
169
- }).then((chat) => {
170
- expect(chat.id).toBe(CHAT_ID);
171
- expect(chat.name).toBe(CHAT_NAME);
172
- expect(chat.members).toContain(USER);
173
- expect(Array.isArray(chat.messages)).toBe(true);
174
- expect(chat.messages.length).toBeGreaterThan(0);
175
- });
176
- });
177
- test("should remove member", () => {
178
- return sfu.removeMemberFromChat({
179
- id: CHAT_ID,
180
- member: USER2
181
- });
182
- });
183
- test("should rename chat", () => {
184
- return sfu.renameChat({
185
- id: CHAT_ID,
186
- name: CHAT_NAME2
187
- });
188
- });
189
- test("should invite contact", async () => {
190
- const contact = await sfu.inviteContact({
191
- to: USER2
192
- });
193
- expect(contact).toBeTruthy();
194
- expect(contact.invite).toBeTruthy();
195
- expect(contact.invite.id).toBeTruthy();
196
- });
197
- test("should confirm invite", async () => {
198
- const contacts = await sfu2.getUserList();
199
- let unconfirmedContact;
200
- contacts.every((contact) => {
201
- if (contact.invite && contact.invite.from !== USER2) {
202
- unconfirmedContact = contact;
203
- return false;
204
- }
205
- return true;
206
- });
207
- expect(unconfirmedContact).toBeTruthy();
208
- const contact = await sfu2.confirmContact(unconfirmedContact.invite);
209
- expect(contact).toBeTruthy();
210
- expect(contact.confirmed).toEqual(true);
211
- });
212
- test("should remove contact", async () => {
213
- const contact = await sfu.removeContact({
214
- id: USER2
215
- });
216
- expect(contact).toBeTruthy();
217
- });
218
- test.skip("should receive message", (done) => {
219
- sfu.on(constants.SFU_EVENT.MESSAGE, (msg) => {
220
- done();
221
- })
222
- sfu.sendMessage({
223
- chatId: CHAT_ID,
224
- body: MESSAGE_BODY
225
- });
226
- });
227
- test("should receive ACK message", async () => {
228
- const msg = await sfu.sendMessage({
229
- chatId: CHAT_ID,
230
- body: MESSAGE_BODY
231
- });
232
- expect(msg).toBeTruthy();
233
- expect(msg.id).toBeTruthy();
234
- expect(msg.date).toBeTruthy();
235
- });
236
- test("should create new chat without id", () => {
237
- return sfu.createChat({
238
- name: CHAT_NAME
239
- });
240
- });
241
- test("should create new chat with member list", () => {
242
- return sfu.createChat({
243
- name: CHAT_NAME,
244
- members: MEMBERS
245
- });
246
- });
247
- test("should create new chat without name based on members", async () => {
248
- const chat = await sfu.createChat({
249
- members: MEMBERS
250
- });
251
- expect(chat.name).toBeTruthy();
252
- });
253
- test("should delete chat", () => {
254
- return sfu.deleteChat({
255
- id: CHAT_ID
256
- });
257
- });
258
- test("should change name after member was added", async () => {
259
- const chat = await sfu.createChat({});
260
- expect(chat.name).toBeTruthy();
261
- const name1 = chat.name;
262
- const sameChat = await sfu.addMemberToChat({id: chat.id, member: USER2});
263
- expect(sameChat.name !== name1).toBeTruthy();
264
- });
265
- });
package/src/tests/util.js DELETED
@@ -1,48 +0,0 @@
1
- const waitForTrack = (pc, track) => {
2
- return new Promise((resolve, reject) => {
3
- pc.ontrack = ({transceiver}) => {
4
- if (transceiver.mid === track.mid) {
5
- resolve(transceiver.receiver.track);
6
- }
7
- }
8
- });
9
- };
10
-
11
- const waitForTracks = (pc, tracks) => {
12
- return new Promise((resolve, reject) => {
13
- let waitingFor = tracks.length;
14
- const trackArrived = () => {
15
- waitingFor--;
16
- if (waitingFor === 0) {
17
- resolve();
18
- }
19
- };
20
- for (const track of tracks) {
21
- waitForTrack(pc, track).then(trackArrived);
22
- }
23
- });
24
- };
25
-
26
- const waitForPeerConnectionStableState = (pc) => {
27
- return waitForPeerConnectionState(pc, "stable");
28
- }
29
-
30
- const waitForPeerConnectionState = (pc, state) => {
31
- return new Promise((resolve, reject) => {
32
- if (pc.signalingState === state) {
33
- resolve();
34
- }
35
- pc.onsignalingstatechange = (e) => {
36
- if (pc.signalingState === state) {
37
- resolve();
38
- }
39
- }
40
- });
41
- };
42
-
43
- module.exports = {
44
- waitForTrack: waitForTrack,
45
- waitForTracks: waitForTracks,
46
- waitForPeerConnectionState: waitForPeerConnectionState,
47
- waitForPeerConnectionStableState: waitForPeerConnectionStableState
48
- }