@live-change/peer-connection-service 0.9.197 → 0.9.199
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/config.js +24 -0
- package/message.js +9 -17
- package/package.json +2 -2
- package/peer.js +2 -6
- package/peerState.js +2 -6
- package/turn.js +1 -6
package/config.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import definition from './definition.js'
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
readerRoles = ['reader', 'speaker', 'vip', 'moderator', 'owner', 'member'],
|
|
5
|
+
writerRoles = ['speaker', 'vip', 'moderator', 'owner'],
|
|
6
|
+
messageWaitForEvents = false,
|
|
7
|
+
messageSkipEmit = false,
|
|
8
|
+
groupMessages = false
|
|
9
|
+
} = definition.config
|
|
10
|
+
|
|
11
|
+
definition.clientConfig = {
|
|
12
|
+
readerRoles,
|
|
13
|
+
writerRoles
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const config = {
|
|
17
|
+
readerRoles,
|
|
18
|
+
writerRoles,
|
|
19
|
+
messageWaitForEvents,
|
|
20
|
+
messageSkipEmit,
|
|
21
|
+
groupMessages
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default config
|
package/message.js
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import definition from './definition.js'
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
readerRoles = ['reader', 'speaker', 'vip', 'moderator', 'owner'],
|
|
5
|
-
writerRoles = ['speaker', 'vip', 'moderator', 'owner'],
|
|
6
|
-
messageWaitForEvents = false,
|
|
7
|
-
messageSkipEmit = false,
|
|
8
|
-
groupMessages = false
|
|
9
|
-
} = config
|
|
10
|
-
|
|
2
|
+
import config from './config.js'
|
|
11
3
|
|
|
12
4
|
import accessControl from '@live-change/access-control-service/access.js'
|
|
13
5
|
const { clientHasAccessRoles } = accessControl(definition)
|
|
@@ -148,7 +140,7 @@ async function postMessage(props, { client, service }, emit) {
|
|
|
148
140
|
if(!data.user) {
|
|
149
141
|
data.session = client.session
|
|
150
142
|
}
|
|
151
|
-
if(messageSkipEmit) {
|
|
143
|
+
if(config.messageSkipEmit) {
|
|
152
144
|
await Message.create({
|
|
153
145
|
id: message,
|
|
154
146
|
...data
|
|
@@ -175,12 +167,12 @@ definition.action({
|
|
|
175
167
|
//console.log("POST MESSAGE", fromType, fromId, fromSession, '=>', toType, toId, toSession, "BY", client)
|
|
176
168
|
if(toType !== fromType || toId !== fromId) return false // different channel
|
|
177
169
|
if(client.session !== fromSession) return false
|
|
178
|
-
const hasRole = await clientHasAccessRoles(client, { objectType: toType, object: toId }, writerRoles)
|
|
170
|
+
const hasRole = await clientHasAccessRoles(client, { objectType: toType, object: toId }, config.writerRoles)
|
|
179
171
|
return hasRole
|
|
180
172
|
},
|
|
181
173
|
queuedBy: (props) => props.from+':'+props.to, // without this, messages order can be changed
|
|
182
174
|
// and it will block ice connection state
|
|
183
|
-
waitForEvents: messageWaitForEvents,
|
|
175
|
+
waitForEvents: config.messageWaitForEvents,
|
|
184
176
|
async execute(props, { client, service }, emit) {
|
|
185
177
|
console.error('postMessage is deprecated, use postMessages instead')
|
|
186
178
|
await postMessage(props, { client, service }, emit)
|
|
@@ -216,16 +208,16 @@ definition.action({
|
|
|
216
208
|
// console.log("POST MESSAGE", fromType, fromId, fromSession, '=>', toType, toId, toSession, "BY", client)
|
|
217
209
|
if(toType !== fromType || toId !== fromId) return false // different channel
|
|
218
210
|
if(client.session !== fromSession) return false
|
|
219
|
-
const hasRole = await clientHasAccessRoles(client, { objectType: toType, object: toId }, writerRoles)
|
|
211
|
+
const hasRole = await clientHasAccessRoles(client, { objectType: toType, object: toId }, config.writerRoles)
|
|
220
212
|
return hasRole
|
|
221
213
|
},
|
|
222
214
|
queuedBy: (props) => props.from+':'+props.to, // without this, messages order can be changed
|
|
223
215
|
// and it will block ice connection state
|
|
224
|
-
waitForEvents: messageWaitForEvents,
|
|
216
|
+
waitForEvents: config.messageWaitForEvents,
|
|
225
217
|
async execute(props, { client, service }, emit) {
|
|
226
218
|
let lastSent = ''
|
|
227
219
|
let lastMessages
|
|
228
|
-
if(messageWaitForEvents) {
|
|
220
|
+
if(config.messageWaitForEvents) {
|
|
229
221
|
lastMessages = await Message.rangeGet({
|
|
230
222
|
gte: `${props.to}_`,
|
|
231
223
|
lte: `${props.to}_\xFF\xFF\xFF\xFF`,
|
|
@@ -236,7 +228,7 @@ definition.action({
|
|
|
236
228
|
}
|
|
237
229
|
const messages = props.messages
|
|
238
230
|
for(const message of messages) {
|
|
239
|
-
if(messageWaitForEvents) {
|
|
231
|
+
if(config.messageWaitForEvents) {
|
|
240
232
|
const sent = new Date(message.sent).toISOString()
|
|
241
233
|
if(lastSent > sent) {
|
|
242
234
|
console.error("Message out of order", lastSent, '>', sent, "BY", props.from)
|
|
@@ -248,7 +240,7 @@ definition.action({
|
|
|
248
240
|
lastSent = sent
|
|
249
241
|
}
|
|
250
242
|
}
|
|
251
|
-
if(groupMessages) {
|
|
243
|
+
if(config.groupMessages) {
|
|
252
244
|
await postMessage({
|
|
253
245
|
from: props.from,
|
|
254
246
|
to: props.to,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/peer-connection-service",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.199",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -11,5 +11,5 @@
|
|
|
11
11
|
},
|
|
12
12
|
"author": "Michał Łaszczewski <michal@emikse.com>",
|
|
13
13
|
"license": "BSD-3-Clause",
|
|
14
|
-
"gitHead": "
|
|
14
|
+
"gitHead": "1900043a10cf9ad49b9cc33a539fb973706de962"
|
|
15
15
|
}
|
package/peer.js
CHANGED
|
@@ -2,11 +2,7 @@ import App from '@live-change/framework'
|
|
|
2
2
|
const app = App.app()
|
|
3
3
|
|
|
4
4
|
import definition from './definition.js'
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
readerRoles = ['reader', 'speaker', 'vip', 'moderator', 'owner', 'member'].
|
|
8
|
-
writerRoles = ['speaker', 'vip', 'moderator', 'owner']
|
|
9
|
-
} = config
|
|
5
|
+
import config from './config.js'
|
|
10
6
|
|
|
11
7
|
import accessControl from '@live-change/access-control-service/access.js'
|
|
12
8
|
const { clientHasAccessRoles } = accessControl(definition)
|
|
@@ -42,7 +38,7 @@ definition.view({
|
|
|
42
38
|
if(visibilityTest) return true
|
|
43
39
|
const { channelType, channel } = params
|
|
44
40
|
//console.log("CHECK PEERS ACCESS", params, client, visibilityTest)
|
|
45
|
-
return clientHasAccessRoles(client, { objectType: channelType, object: channel }, readerRoles)
|
|
41
|
+
return clientHasAccessRoles(client, { objectType: channelType, object: channel }, config.readerRoles)
|
|
46
42
|
},
|
|
47
43
|
async daoPath({ channelType, channel }, { client, service }, method) {
|
|
48
44
|
return Peer.indexRangePath('byChannel', [ channelType, channel.split(':')[0] ])
|
package/peerState.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import definition from './definition.js'
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
readerRoles = ['reader', 'speaker', 'vip', 'moderator', 'owner'],
|
|
5
|
-
writerRoles = ['speaker', 'vip', 'moderator', 'owner']
|
|
6
|
-
} = config
|
|
2
|
+
import config from './config.js'
|
|
7
3
|
|
|
8
4
|
import accessControl from '@live-change/access-control-service/access.js'
|
|
9
5
|
const { clientHasAccessRoles } = accessControl(definition)
|
|
@@ -61,7 +57,7 @@ definition.action({
|
|
|
61
57
|
if(visibilityTest) return true
|
|
62
58
|
const [toType, toId, toSession] = peer.split(':')
|
|
63
59
|
if(client.session !== toSession) return false
|
|
64
|
-
const hasRole = await clientHasAccessRoles(client, { objectType: toType, object: toId }, writerRoles)
|
|
60
|
+
const hasRole = await clientHasAccessRoles(client, { objectType: toType, object: toId }, config.writerRoles)
|
|
65
61
|
return hasRole
|
|
66
62
|
},
|
|
67
63
|
async execute(props, { client, service }, emit) {
|
package/turn.js
CHANGED
|
@@ -7,11 +7,6 @@ const urls = config?.turn?.urls || process.env.TURN_URLS?.split(';')
|
|
|
7
7
|
const secret = config?.turn?.secret || process.env.TURN_SECRET
|
|
8
8
|
const turnExpireTime = config?.turn?.expire || (+process.env.TURN_EXPIRE) || (60 * 60) // 1 hour for default
|
|
9
9
|
|
|
10
|
-
const {
|
|
11
|
-
readerRoles = ['reader', 'speaker', 'vip', 'moderator', 'owner'],
|
|
12
|
-
writerRoles = ['speaker', 'vip', 'moderator', 'owner']
|
|
13
|
-
} = config
|
|
14
|
-
|
|
15
10
|
import accessControl from '@live-change/access-control-service/access.js'
|
|
16
11
|
const { clientHasAccessRoles } = accessControl(definition)
|
|
17
12
|
|
|
@@ -65,7 +60,7 @@ definition.view({
|
|
|
65
60
|
const [ channelType, channel, session, instance ] = peer.split(':')
|
|
66
61
|
if(session !== client.session) throw new Error('wrongSession')
|
|
67
62
|
const result = await clientHasAccessRoles(client, { objectType: channelType.split('.')[0], object: channel },
|
|
68
|
-
writerRoles)
|
|
63
|
+
config.writerRoles)
|
|
69
64
|
return result
|
|
70
65
|
},
|
|
71
66
|
observable({ peer }, context) {
|