@live-change/peer-connection-service 0.8.34 → 0.8.36
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/index.js +4 -2
- package/message.js +22 -15
- package/package.json +2 -2
- package/peer.js +19 -16
- package/peerState.js +20 -11
- package/turn.js +18 -10
package/index.js
CHANGED
package/message.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import definition from './definition.js'
|
|
2
|
+
const config = definition.config
|
|
3
|
+
const {
|
|
4
|
+
readerRoles = ['reader', 'speaker', 'vip', 'moderator', 'owner'],
|
|
5
|
+
writerRoles = ['speaker', 'vip', 'moderator', 'owner']
|
|
6
|
+
} = config
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
import accessControl from '@live-change/access-control-service/access.js'
|
|
10
|
+
const { clientHasAccessRoles } = accessControl(definition)
|
|
11
|
+
|
|
12
|
+
import { Peer } from './peer.js'
|
|
2
13
|
|
|
3
14
|
const messageFields = {
|
|
4
15
|
to: {
|
|
@@ -73,9 +84,8 @@ definition.view({
|
|
|
73
84
|
access: async({ peer }, { client, service, visibilityTest }) => {
|
|
74
85
|
if(visibilityTest) return true
|
|
75
86
|
if(!peer) throw new Error("peer parameter is required")
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return peer.split('_')[2] == publicSessionInfo.id
|
|
87
|
+
console.log('MESSAGES ACCESS', peer.split(':'), "[2] == ", client.session)
|
|
88
|
+
return peer.split(':')[2] === client.session
|
|
79
89
|
},
|
|
80
90
|
async daoPath({ peer, gt, lt, gte, lte, limit, reverse }, { client, service }, method) {
|
|
81
91
|
const channelId = peer
|
|
@@ -121,8 +131,7 @@ async function postMessage(props, { client, service }, emit, conversation) {
|
|
|
121
131
|
}
|
|
122
132
|
data.timestamp = now
|
|
123
133
|
if(!data.user) {
|
|
124
|
-
|
|
125
|
-
data.session = publicInfo.id
|
|
134
|
+
data.session = client.session
|
|
126
135
|
}
|
|
127
136
|
emit({
|
|
128
137
|
type: "MessageCreated",
|
|
@@ -140,15 +149,13 @@ definition.action({
|
|
|
140
149
|
access: async ({ from, to }, context) => {
|
|
141
150
|
const { client, service, visibilityTest } = context
|
|
142
151
|
if(visibilityTest) return true
|
|
143
|
-
const [fromType, fromId, fromSession] = from.split('
|
|
144
|
-
const [toType, toId, toSession] = to.split('
|
|
145
|
-
|
|
146
|
-
if(toId
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return
|
|
150
|
-
? checkPrivAccess(toId, context)
|
|
151
|
-
: checkIfRole(toType.split('.')[0], toId, ['speaker', 'vip', 'moderator', 'owner'], context)
|
|
152
|
+
const [fromType, fromId, fromSession] = from.split(':')
|
|
153
|
+
const [toType, toId, toSession] = to.split(':')
|
|
154
|
+
console.log("POST MESSAGE", fromType, fromId, fromSession, '=>', toType, toId, toSession, "BY", client)
|
|
155
|
+
if(toType !== fromType || toId !== fromId) return false // different channel
|
|
156
|
+
if(client.session !== fromSession) return false
|
|
157
|
+
const hasRole = await clientHasAccessRoles(client, { objectType: toType, object: toId }, writerRoles)
|
|
158
|
+
return hasRole
|
|
152
159
|
},
|
|
153
160
|
async execute(props, { client, service }, emit) {
|
|
154
161
|
const result = await postMessage(props, { client, service }, emit)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/peer-connection-service",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.36",
|
|
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": "24694d1687f0ab2d6eb7edd95e5274428cfd44eb"
|
|
15
15
|
}
|
package/peer.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import definition from './definition.js'
|
|
2
|
+
const config = definition.config
|
|
3
|
+
const {
|
|
4
|
+
readerRoles = ['reader', 'speaker', 'vip', 'moderator', 'owner'].
|
|
5
|
+
writerRoles = ['speaker', 'vip', 'moderator', 'owner']
|
|
6
|
+
} = config
|
|
2
7
|
|
|
3
|
-
|
|
8
|
+
import accessControl from '@live-change/access-control-service/access.js'
|
|
9
|
+
const { clientHasAccessRoles } = accessControl(definition)
|
|
4
10
|
|
|
5
|
-
const Peer = definition.model({
|
|
11
|
+
export const Peer = definition.model({
|
|
6
12
|
name: "Peer",
|
|
7
13
|
itemOfAny: {
|
|
8
14
|
to: ['channel', 'session']
|
|
@@ -33,8 +39,7 @@ definition.view({
|
|
|
33
39
|
if(visibilityTest) return true
|
|
34
40
|
const { channelType, channel } = params
|
|
35
41
|
//console.log("CHECK PEERS ACCESS", params, client, visibilityTest)
|
|
36
|
-
return
|
|
37
|
-
['reader', 'speaker', 'vip', 'moderator', 'owner'])
|
|
42
|
+
return clientHasAccessRoles(client, { objectType: channelType, object: channel }, readerRoles)
|
|
38
43
|
},
|
|
39
44
|
async daoPath({ channelType, channel }, { client, service }, method) {
|
|
40
45
|
return Peer.indexRangePath('byChannel', [ channelType, channel.split('.')[0] ])
|
|
@@ -43,16 +48,16 @@ definition.view({
|
|
|
43
48
|
|
|
44
49
|
definition.event({
|
|
45
50
|
name: "peerOnline",
|
|
46
|
-
async execute({ channelType, channel,
|
|
47
|
-
const peer = channelType + ':' + channel + ':' +
|
|
48
|
-
await Peer.create({ id: peer, channelType, channel, instance,
|
|
51
|
+
async execute({ channelType, channel, session, instance }) {
|
|
52
|
+
const peer = channelType + ':' + channel + ':' + session + ':' + instance
|
|
53
|
+
await Peer.create({ id: peer, channelType, channel, instance, session })
|
|
49
54
|
}
|
|
50
55
|
})
|
|
51
56
|
|
|
52
57
|
definition.event({
|
|
53
58
|
name: "peerOffline",
|
|
54
|
-
async execute({ channelType, channel,
|
|
55
|
-
const peer = channelType + ':' + channel + ':' +
|
|
59
|
+
async execute({ channelType, channel, session, instance }) {
|
|
60
|
+
const peer = channelType + ':' + channel + ':' + session + ':' + instance
|
|
56
61
|
Peer.delete(peer)
|
|
57
62
|
}
|
|
58
63
|
})
|
|
@@ -76,13 +81,12 @@ definition.trigger({
|
|
|
76
81
|
},
|
|
77
82
|
async execute({ session, peer }, context, emit) {
|
|
78
83
|
console.log("PEER ONLINE PARAMS", { session, peer })
|
|
79
|
-
const [ channelType, channel,
|
|
80
|
-
if(sessionType !== 'session_Session') throw new Error('wrongSessionType')
|
|
84
|
+
const [ channelType, channel, peerSession, instance ] = peer.split(':')
|
|
81
85
|
if(peerSession !== session) throw new Error('wrongSession')
|
|
82
86
|
/// TODO: check channel access
|
|
83
87
|
emit({
|
|
84
88
|
type: 'peerOnline',
|
|
85
|
-
channelType, channel,
|
|
89
|
+
channelType, channel, session, instance
|
|
86
90
|
})
|
|
87
91
|
}
|
|
88
92
|
})
|
|
@@ -93,12 +97,11 @@ definition.trigger({
|
|
|
93
97
|
},
|
|
94
98
|
async execute({ session, peer }, context, emit) {
|
|
95
99
|
console.log("PEER OFFLINE PARAMS", { session, peer })
|
|
96
|
-
const [ channelType, channel,
|
|
97
|
-
if(
|
|
98
|
-
if(peerSession != session) throw new Error('wrongSession')
|
|
100
|
+
const [ channelType, channel, peerSession, instance ] = peer.split(':')
|
|
101
|
+
if(peerSession !== session) throw new Error('wrongSession')
|
|
99
102
|
emit({
|
|
100
103
|
type: 'peerOffline',
|
|
101
|
-
channelType, channel,
|
|
104
|
+
channelType, channel, session, instance
|
|
102
105
|
})
|
|
103
106
|
}
|
|
104
107
|
})
|
package/peerState.js
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import definition from './definition.js'
|
|
2
|
+
const config = definition.config
|
|
3
|
+
const {
|
|
4
|
+
readerRoles = ['reader', 'speaker', 'vip', 'moderator', 'owner'],
|
|
5
|
+
writerRoles = ['speaker', 'vip', 'moderator', 'owner']
|
|
6
|
+
} = config
|
|
7
|
+
|
|
8
|
+
import accessControl from '@live-change/access-control-service/access.js'
|
|
9
|
+
const { clientHasAccessRoles } = accessControl(definition)
|
|
10
|
+
|
|
11
|
+
import { Peer } from './peer.js'
|
|
2
12
|
|
|
3
|
-
const { Peer } = require('./peer.js')
|
|
4
13
|
|
|
5
14
|
const peerStateFields = {
|
|
15
|
+
online: {
|
|
16
|
+
type: Boolean
|
|
17
|
+
},
|
|
6
18
|
audioState: {
|
|
7
19
|
type: String
|
|
8
20
|
},
|
|
@@ -41,10 +53,9 @@ definition.view({
|
|
|
41
53
|
access: async ({ peer }, context) => {
|
|
42
54
|
const { client, service, visibilityTest } = context
|
|
43
55
|
if(visibilityTest) return true
|
|
44
|
-
const [toType, toId, toSession] = peer.split('
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
: checkIfRole(toType.split('.')[0], toId, ['speaker', 'vip', 'moderator', 'owner'], context)
|
|
56
|
+
const [toType, toId, toSession] = peer.split(':')
|
|
57
|
+
const hasRole = await clientHasAccessRoles(client, { objectType: toType, object: toId }, writerRoles)
|
|
58
|
+
return hasRole
|
|
48
59
|
},
|
|
49
60
|
async daoPath({ peer }, { client, service }, method) {
|
|
50
61
|
return PeerState.path(peer)
|
|
@@ -63,12 +74,10 @@ definition.action({
|
|
|
63
74
|
access: async ({ peer }, context) => {
|
|
64
75
|
const { client, service, visibilityTest } = context
|
|
65
76
|
if(visibilityTest) return true
|
|
66
|
-
const [toType, toId, toSession] = peer.split('
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return
|
|
70
|
-
? checkPrivAccess(toId, context)
|
|
71
|
-
: checkIfRole(toType.split('.')[0], toId, ['speaker', 'vip', 'moderator', 'owner'], context)
|
|
77
|
+
const [toType, toId, toSession] = peer.split(':')
|
|
78
|
+
if(client.session !== toSession) return false
|
|
79
|
+
const hasRole = await clientHasAccessRoles(client, { objectType: toType, object: toId }, writerRoles)
|
|
80
|
+
return hasRole
|
|
72
81
|
},
|
|
73
82
|
async execute(props, { client, service }, emit) {
|
|
74
83
|
let data = { }
|
package/turn.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import crypto from 'crypto'
|
|
2
|
+
import ReactiveDao from '@live-change/dao'
|
|
3
3
|
import definition from './definition.js'
|
|
4
4
|
const config = definition.config
|
|
5
5
|
|
|
@@ -7,9 +7,16 @@ 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 {
|
|
10
|
+
const {
|
|
11
|
+
readerRoles = ['reader', 'speaker', 'vip', 'moderator', 'owner'],
|
|
12
|
+
writerRoles = ['speaker', 'vip', 'moderator', 'owner']
|
|
13
|
+
} = config
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
import accessControl from '@live-change/access-control-service/access.js'
|
|
16
|
+
const { clientHasAccessRoles } = accessControl(definition)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
import { Peer } from './peer.js'
|
|
13
20
|
|
|
14
21
|
function randomHexString(size) {
|
|
15
22
|
return new Promise((resolve, reject) => {
|
|
@@ -24,11 +31,12 @@ async function createTurnConfiguration({ client }) {
|
|
|
24
31
|
const expire = Date.now() / 1000 + turnExpireTime | 0
|
|
25
32
|
const username = await randomHexString(10)
|
|
26
33
|
const rusername = expire + ':' + username
|
|
34
|
+
console.log("TURN SECRET", secret, rusername)
|
|
27
35
|
const password = crypto
|
|
28
36
|
.createHmac('sha1', secret)
|
|
29
37
|
.update(rusername)
|
|
30
38
|
.digest('base64')
|
|
31
|
-
/// TODO: select nearest servers by geoip
|
|
39
|
+
/// TODO: select nearest servers by geoip and loadbalancing
|
|
32
40
|
return {
|
|
33
41
|
urls,
|
|
34
42
|
credentialType: 'password',
|
|
@@ -51,11 +59,11 @@ definition.view({
|
|
|
51
59
|
},
|
|
52
60
|
access: async ({ peer }, { client, service, visibilityTest }) => {
|
|
53
61
|
if(visibilityTest) return true
|
|
54
|
-
const [ channelType, channel,
|
|
55
|
-
if(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
const [ channelType, channel, session, instance ] = peer.split(':')
|
|
63
|
+
if(session !== client.session) throw new Error('wrongSession')
|
|
64
|
+
const result = await clientHasAccessRoles(client, { objectType: channelType.split('.')[0], object: channel },
|
|
65
|
+
writerRoles)
|
|
66
|
+
return result
|
|
59
67
|
},
|
|
60
68
|
observable({ peer }, context) {
|
|
61
69
|
const observable = new ReactiveDao.ObservableValue()
|