@babblevoice/projectrtp 2.3.8 → 2.4.0

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.
@@ -0,0 +1,65 @@
1
+ name: Build
2
+
3
+ # Controls when the workflow will run
4
+ on:
5
+ workflow_dispatch:
6
+ push:
7
+ branches:
8
+ - 'main'
9
+ - 'dev'
10
+ tags:
11
+ - 'v*.*.*'
12
+ pull_request:
13
+ branches:
14
+ - 'main'
15
+ - 'dev'
16
+
17
+ #GH
18
+ permissions:
19
+ contents: read
20
+
21
+ jobs:
22
+ build:
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ # Get the repository's code
26
+ - name: Checkout
27
+ uses: actions/checkout@v3
28
+ # https://github.com/docker/setup-qemu-action
29
+ - name: Set up QEMU
30
+ uses: docker/setup-qemu-action@v1
31
+ # https://github.com/docker/setup-buildx-action
32
+ - name: Set up Docker Buildx
33
+ id: buildx
34
+ uses: docker/setup-buildx-action@v2
35
+ - name: Login to Docker Hub
36
+ if: github.event_name != 'pull_request'
37
+ uses: docker/login-action@v2
38
+ with:
39
+ username: ${{ secrets.DOCKERHUB_USERNAME }}
40
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
41
+ - name: Docker meta
42
+ id: ourdockertags
43
+ uses: docker/metadata-action@v3
44
+ with:
45
+ # list of Docker images to use as base name for tags
46
+ images: |
47
+ docker.io/tinpotnick/projectrtp
48
+ # Docker tags based on the following events/attributes
49
+ tags: |
50
+ type=schedule
51
+ type=ref,event=branch
52
+ type=ref,event=pr
53
+ type=semver,pattern={{version}}
54
+ type=semver,pattern={{major}}.{{minor}}
55
+ type=semver,pattern={{major}}
56
+ type=sha
57
+
58
+ - name: Build and push
59
+ uses: docker/build-push-action@v2
60
+ with:
61
+ context: .
62
+ platforms: linux/amd64,linux/arm64
63
+ push: ${{ github.event_name != 'pull_request' }}
64
+ tags: ${{ steps.ourdockertags.outputs.tags }}
65
+ labels: ${{ steps.ourdockertags.outputs.labels }}
package/lib/node.js CHANGED
@@ -165,12 +165,13 @@ class rtpnode {
165
165
  * @param { object } connection
166
166
  * @returns { void }
167
167
  */
168
- send( msg, connection ) {
168
+ send( msg, connection, cb = undefined ) {
169
169
  this._post( msg, ( modifiedmsg ) => {
170
170
  if( this._destroying ) return
171
171
  msg.status = this.prtp.stats()
172
172
  msg.status.instance = instance
173
173
  connection.write( message.createmessage( modifiedmsg ) )
174
+ if (cb !== undefined) cb(msg)
174
175
  } )
175
176
  }
176
177
 
@@ -197,7 +198,9 @@ class rtpnode {
197
198
  * @returns { Promise< Boolean > }
198
199
  */
199
200
  async _processmessage( msg, con ) {
200
- return ( await this._openchannel( msg, con ) || this._updatechannel( msg, con ) )
201
+ if( "open" == msg.channel ) return await this._openchannel( msg, con )
202
+
203
+ return this._updatechannel( msg, con )
201
204
  }
202
205
 
203
206
  /**
@@ -287,21 +290,25 @@ class rtpnode {
287
290
  * @returns { Promise< Boolean > }
288
291
  */
289
292
  async _openchannel( msg, con ) {
290
- if( "open" !== msg.channel ) return false
291
293
  con.connectionlength += 1
292
294
  msg.forcelocal = true
293
295
 
294
- const chan = await this.prtp.openchannel( msg, ( x ) => {
295
- this.send( { ...{ "id": chan.id, "uuid": chan.uuid }, ...x }, con.connection )
296
- if( "close" === x.action ) {
297
- con.connectionlength -= 1
298
- channels.delete( chan.uuid )
299
-
300
- if( 0 == con.connectionlength && "listen" == con.mode ) {
301
- this.connections.delete( con.instance )
302
- con.connection.destroy()
303
- }
304
- }
296
+ const chan = await this.prtp.openchannel( msg, ( cookie ) => {
297
+ // TODO: we might want to ensure the actual event has been written
298
+ // to the server before cleaning up the channel on our side?
299
+ this.send( { ...{ "id": chan.id, "uuid": chan.uuid }, ...cookie },
300
+ con.connection,
301
+ ( cookie ) => {
302
+ if ( "close" === cookie.action ) {
303
+ con.connectionlength -= 1
304
+ channels.delete( chan.uuid )
305
+
306
+ if( 0 == con.connectionlength && "listen" == con.mode ) {
307
+ this.connections.delete( con.instance )
308
+ con.connection.destroy()
309
+ }
310
+ }
311
+ } )
305
312
  } )
306
313
  channels.set( chan.uuid, chan )
307
314
  this.send( { ...chan, ...{ "action": "open" } }, con.connection )
package/lib/server.js CHANGED
@@ -260,20 +260,27 @@ class channel {
260
260
  /**
261
261
  * This method forces an open channel on the same remote node.
262
262
  * @param { object } options
263
+ * @param { channelcallback } cb
263
264
  * @returns { Promise< channel > }
264
265
  */
265
- openchannel( options = {} ) {
266
+ openchannel( options = undefined, cb = undefined ) {
267
+ if( "function" == typeof options ) {
268
+ cb = options
269
+ options = {}
270
+ }
266
271
 
267
272
  options.channel = "open"
268
273
 
269
274
  const resolvepromise = new Promise( ( res ) => {
270
275
 
271
276
  const newchannel = new channel()
277
+ if( cb ) newchannel.em.on( "all", cb )
278
+
272
279
  newchannel.connection = this.connection
273
280
  newchannel.channels = this.channels
274
281
  newchannel.channels.push( newchannel )
282
+ newchannel.openresolve = res
275
283
  newchannel._write( options )
276
- res( newchannel )
277
284
  } )
278
285
 
279
286
  return resolvepromise
@@ -597,8 +604,6 @@ class channel {
597
604
  * @private
598
605
  */
599
606
  _runclose( msg ) {
600
- if( "close" !== msg.action ) return
601
-
602
607
  if( undefined !== this.openresolve ) {
603
608
  this.openresolve()
604
609
  delete this.openresolve
@@ -629,7 +634,7 @@ class channel {
629
634
  this.em.emit( "all", msg )
630
635
  this.em.emit( msg.action, msg )
631
636
 
632
- this._runclose( msg )
637
+ if( "close" == msg.action ) this._runclose( msg )
633
638
  }
634
639
 
635
640
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babblevoice/projectrtp",
3
- "version": "2.3.8",
3
+ "version": "2.4.0",
4
4
  "description": "A scalable Node addon RTP server",
5
5
  "main": "index.js",
6
6
  "directories": {