@flashphoner/sfusdk 1.0.43 → 1.0.47
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/docTemplate/README.md
CHANGED
package/package.json
CHANGED
package/src/sdk/constants.js
CHANGED
|
@@ -295,6 +295,7 @@ const constants = Object.freeze({
|
|
|
295
295
|
* @memberof FlashphonerSFU.SFU_ROOM_EVENT
|
|
296
296
|
*/
|
|
297
297
|
WAITING_LIST: "SFU_WAITING_LIST",
|
|
298
|
+
WAITING_ROOM_UPDATE: "SFU_WAITING_ROOM_UPDATE",
|
|
298
299
|
/**
|
|
299
300
|
* Fires when mute/unmute state of one of the Room's participating tracks changes
|
|
300
301
|
* Event object {@link FlashphonerSFU.Room.TracksInfo}
|
package/src/sdk/room.js
CHANGED
|
@@ -59,7 +59,7 @@ const room = function(options) {
|
|
|
59
59
|
notify(message.type, message.message);
|
|
60
60
|
}
|
|
61
61
|
} else if (message.type === constants.SFU_EVENT.ACK && promises.promised(message.internalMessageId)) {
|
|
62
|
-
|
|
62
|
+
promises.resolve(message.internalMessageId);
|
|
63
63
|
} else {
|
|
64
64
|
notify(message.type, message.message);
|
|
65
65
|
}
|
|
@@ -117,6 +117,8 @@ const room = function(options) {
|
|
|
117
117
|
if (!promises.resolve(e.internalMessageId, e)) {
|
|
118
118
|
notify(e.type, e);
|
|
119
119
|
}
|
|
120
|
+
} else if (e.type === constants.SFU_ROOM_EVENT.WAITING_ROOM_UPDATE && promises.promised(e.internalMessageId)) {
|
|
121
|
+
promises.resolve(e.internalMessageId, e.enabled);
|
|
120
122
|
} else if (e.type === constants.SFU_EVENT.ACK && promises.promised(e.internalMessageId)) {
|
|
121
123
|
promises.resolve(e.internalMessageId);
|
|
122
124
|
} else {
|
package/src/sdk/sfu-extended.js
CHANGED
|
@@ -71,7 +71,7 @@ function setupConnection(connection) {
|
|
|
71
71
|
notify(SFU_EVENT.CHAT_LOADED, msg[0].chat);
|
|
72
72
|
} else if (msg[0].type === constants.SFU_ROOM_EVENT.OPERATION_FAILED && promises.promised(msg[0].internalMessageId)) {
|
|
73
73
|
promises.reject(msg[0].internalMessageId, msg[0]);
|
|
74
|
-
} else if (msg[0].type === constants.SFU_EVENT.ACK && promises.promised(msg[0].internalMessageId
|
|
74
|
+
} else if (msg[0].type === constants.SFU_EVENT.ACK && promises.promised(msg[0].internalMessageId)) {
|
|
75
75
|
promises.resolve(msg[0].internalMessageId);
|
|
76
76
|
} else if (msg[0].roomName && msg[0].roomName.length > 0) {
|
|
77
77
|
//room event
|
|
@@ -138,7 +138,8 @@ const connect = function(options) {
|
|
|
138
138
|
connection.connect(connectionConfig).then(function (connectionConfig) {
|
|
139
139
|
user = Object.freeze({
|
|
140
140
|
username: connectionConfig[0].sipLogin,
|
|
141
|
-
nickname: connectionConfig[0].sipVisibleName
|
|
141
|
+
nickname: connectionConfig[0].sipVisibleName,
|
|
142
|
+
pmi: connectionConfig[0].pmi
|
|
142
143
|
});
|
|
143
144
|
state = SFU_STATE.AUTHENTICATED;
|
|
144
145
|
notify(SFU_EVENT.CONNECTED);
|
|
@@ -224,14 +224,14 @@ describe("chat", () => {
|
|
|
224
224
|
body: MESSAGE_BODY
|
|
225
225
|
});
|
|
226
226
|
});
|
|
227
|
-
test("should receive ACK message", (
|
|
228
|
-
sfu.
|
|
229
|
-
done();
|
|
230
|
-
})
|
|
231
|
-
sfu.sendMessage({
|
|
227
|
+
test("should receive ACK message", async () => {
|
|
228
|
+
const msg = await sfu.sendMessage({
|
|
232
229
|
chatId: CHAT_ID,
|
|
233
230
|
body: MESSAGE_BODY
|
|
234
231
|
});
|
|
232
|
+
expect(msg).toBeTruthy();
|
|
233
|
+
expect(msg.id).toBeTruthy();
|
|
234
|
+
expect(msg.date).toBeTruthy();
|
|
235
235
|
});
|
|
236
236
|
test("should create new chat without id", () => {
|
|
237
237
|
return sfu.createChat({
|
|
@@ -0,0 +1,265 @@
|
|
|
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
|
+
});
|