async startP2J() {
        const p2j = new P2J()
        const p2jPort = await getPort()

        let p2jServer = net.createServer(function(p2jStream) {
            p2jStream.pipe(p2j)

            // Close the p2j server on stream end
            p2jStream.on('end', function() {
                p2jServer.close()
            })
        })

        // Listen to pipe on localhost only
        p2jServer.listen(p2jPort, 'localhost')
      
        p2j.on('jpeg', (jpegFrame) => {
            // If updateSnapshot = true then publish the next full JPEG frame as new snapshot
            if (this.data.livestream.updateSnapshot) {
                this.data.snapshot.currentImage = jpegFrame
                this.data.snapshot.timestamp = Math.round(Date.now()/1000)
                this.publishSnapshot()
                this.data.livestream.updateSnapshot = false
            }
        })

        // Return TCP port for SIP stream to send stream
        return p2jPort
    }
// Start P2J server to emit complete JPEG images from livestream
Start P2J server to emit complete JPEG images from livestream
Start P2J server to emit complete JPEG images from livestream
async startP2J() {
        const p2j = new P2J()
        const p2jPort = await getPort()
        let p2jServer = net.createServer(function(p2jStream) {
            p2jStream.pipe(p2j)
            p2jStream.on('end', function() {
                p2jServer.close()
            })
        })
        p2jServer.listen(p2jPort, 'localhost')
        p2j.on('jpeg', (jpegFrame) => {
            if (this.data.livestream.updateSnapshot) {
                this.data.snapshot.currentImage = jpegFrame
                this.data.snapshot.timestamp = Math.round(Date.now()/1000)
                this.publishSnapshot()
                this.data.livestream.updateSnapshot = false
            }
        })
        return p2jPort
    }
async startP2J ( ) { const p2j = new P2J ( ) const p2jPort = await getPort ( ) let p2jServer = net . createServer ( function ( p2jStream ) { p2jStream . pipe ( p2j ) p2jStream . on ( 'end' , function ( ) { p2jServer . close ( ) } ) } ) p2jServer . listen ( p2jPort , 'localhost' ) p2j . on ( 'jpeg' , ( jpegFrame ) => { if ( this . data . livestream . updateSnapshot ) { this . data . snapshot . currentImage = jpegFrame this . data . snapshot . timestamp = Math . round ( Date . now ( ) / 1000 ) this . publishSnapshot ( ) this . data . livestream . updateSnapshot = false } } ) return p2jPort }
Start P2J server to emit complete JPEG images from livestream
Start P2J server to emit complete JPEG images from livestream
// Close the p2j server on stream end // Listen to pipe on localhost only // If updateSnapshot = true then publish the next full JPEG frame as new snapshot // Return TCP port for SIP stream to send stream