@live-change/peer-connection-service 0.8.108 → 0.8.110
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/message.js +72 -2
- package/package.json +2 -2
- package/turn.js +1 -0
package/message.js
CHANGED
|
@@ -23,6 +23,9 @@ const messageFields = {
|
|
|
23
23
|
},
|
|
24
24
|
data: {
|
|
25
25
|
type: Object
|
|
26
|
+
},
|
|
27
|
+
sent: {
|
|
28
|
+
type: Date
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
31
|
|
|
@@ -110,7 +113,7 @@ definition.view({
|
|
|
110
113
|
|
|
111
114
|
let lastMessageTime = new Map()
|
|
112
115
|
|
|
113
|
-
|
|
116
|
+
function postMessage(props, { client, service }, emit, conversation) {
|
|
114
117
|
console.log("POST MESSAGE", props)
|
|
115
118
|
const channelId = props.to
|
|
116
119
|
let lastTime = lastMessageTime.get(channelId)
|
|
@@ -157,9 +160,76 @@ definition.action({
|
|
|
157
160
|
const hasRole = await clientHasAccessRoles(client, { objectType: toType, object: toId }, writerRoles)
|
|
158
161
|
return hasRole
|
|
159
162
|
},
|
|
163
|
+
queuedBy: (props) => props.to, // without this, messages order can be changed, it will block ice connection state
|
|
160
164
|
async execute(props, { client, service }, emit) {
|
|
161
|
-
|
|
165
|
+
throw new Error('postMessage is deprecated, use postMessages instead')
|
|
166
|
+
const result = postMessage(props, { client, service }, emit)
|
|
162
167
|
console.log("MESSAGE POSTED!")
|
|
163
168
|
return result
|
|
164
169
|
}
|
|
165
170
|
})
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
definition.action({
|
|
174
|
+
name: "postMessages",
|
|
175
|
+
properties: {
|
|
176
|
+
from: {
|
|
177
|
+
type: Peer,
|
|
178
|
+
validation: ['nonEmpty']
|
|
179
|
+
},
|
|
180
|
+
to: {
|
|
181
|
+
type: Peer,
|
|
182
|
+
validation: ['nonEmpty']
|
|
183
|
+
},
|
|
184
|
+
messages: {
|
|
185
|
+
type: Array,
|
|
186
|
+
of: {
|
|
187
|
+
type: Object,
|
|
188
|
+
messageFields
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
//queuedBy: (command) => `${command.toType}_${command.toId})`,
|
|
193
|
+
access: async ({ from, to }, context) => {
|
|
194
|
+
const { client, service, visibilityTest } = context
|
|
195
|
+
if(visibilityTest) return true
|
|
196
|
+
const [fromType, fromId, fromSession] = from.split(':')
|
|
197
|
+
const [toType, toId, toSession] = to.split(':')
|
|
198
|
+
// console.log("POST MESSAGE", fromType, fromId, fromSession, '=>', toType, toId, toSession, "BY", client)
|
|
199
|
+
if(toType !== fromType || toId !== fromId) return false // different channel
|
|
200
|
+
if(client.session !== fromSession) return false
|
|
201
|
+
const hasRole = await clientHasAccessRoles(client, { objectType: toType, object: toId }, writerRoles)
|
|
202
|
+
return hasRole
|
|
203
|
+
},
|
|
204
|
+
queuedBy: (props) => props.from+':'+props.to, // without this, messages order can be changed
|
|
205
|
+
// and it will block ice connection state
|
|
206
|
+
//waitForEvents: true,
|
|
207
|
+
async execute(props, { client, service }, emit) {
|
|
208
|
+
const lastMessages = await Message.rangeGet({
|
|
209
|
+
gte: `${props.to}_`,
|
|
210
|
+
lte: `${props.to}_\xFF\xFF\xFF\xFF`,
|
|
211
|
+
limit: 10,
|
|
212
|
+
reverse: true
|
|
213
|
+
})
|
|
214
|
+
let lastSent = lastMessages?.[0]?.sent
|
|
215
|
+
const messages = props.messages
|
|
216
|
+
for(const message of messages) {
|
|
217
|
+
message.from = props.from
|
|
218
|
+
message.to = props.to
|
|
219
|
+
const sent = new Date(message.sent).toISOString()
|
|
220
|
+
if(lastSent > sent) {
|
|
221
|
+
console.error("Message out of order", lastSent, '>', sent, "BY", props.from)
|
|
222
|
+
console.error("LAST MESSAGES", lastMessages)
|
|
223
|
+
console.error("RECEIVED MESSAGES", props.messages)
|
|
224
|
+
// process.exit(1)
|
|
225
|
+
throw new Error("Messages out of order")
|
|
226
|
+
}
|
|
227
|
+
lastSent = sent
|
|
228
|
+
}
|
|
229
|
+
for(const message of messages) {
|
|
230
|
+
postMessage(message, { client, service }, emit)
|
|
231
|
+
}
|
|
232
|
+
// console.log("MESSAGES POSTED!")
|
|
233
|
+
return 'ok'
|
|
234
|
+
}
|
|
235
|
+
})
|
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.110",
|
|
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": "8af31d640f43b00b2874f2c70fa4d4486541adfe"
|
|
15
15
|
}
|
package/turn.js
CHANGED
|
@@ -28,6 +28,7 @@ function randomHexString(size) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
async function createTurnConfiguration({ client }) {
|
|
31
|
+
if(!urls || !secret) return null
|
|
31
32
|
if(!urls) throw new Error('TURN urls not configured')
|
|
32
33
|
if(!secret) throw new Error('TURN secret not configured')
|
|
33
34
|
const expire = Date.now() / 1000 + turnExpireTime | 0
|