From e0159772f82bf3bf6c8c7d4648afcaa2c5780101 Mon Sep 17 00:00:00 2001 From: vapormusic Date: Fri, 27 Jan 2023 23:08:18 +0700 Subject: [PATCH] fix for shairport-sync --- lib/device_airtunes.js | 8 ++++++-- lib/devices.js | 5 +++-- lib/rtsp.js | 18 ++++++++++-------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/device_airtunes.js b/lib/device_airtunes.js index 0f476c9..bda137f 100644 --- a/lib/device_airtunes.js +++ b/lib/device_airtunes.js @@ -71,7 +71,7 @@ function AirTunesDevice(host, audioOut, options, mode = 0, txt = "") { console.log("yasc",this.txt) console.log('port', this.port) let a = this.txt.filter((u) => String(u).startsWith('et=')) - if((a[0]?? "").includes('4')){ + if(a == "et=4"){ this.mode = 2; } let b = this.txt.filter((u) => String(u).startsWith('cn=')) @@ -117,9 +117,13 @@ function AirTunesDevice(host, audioOut, options, mode = 0, txt = "") { this.borkedshp = true; } let k = this.txt.filter((u) => String(u).startsWith('am=')) - if ((k[0] ?? "").includes("AppleTV3,1") || (k[0] ?? "").includes("AirReceiver3,1") || (k[0] ?? "").includes("AirRecever3,1") ){ + if ((k[0] ?? "").includes("AppleTV3,1") || (k[0] ?? "").includes("AirReceiver3,1") || (k[0] ?? "").includes("AirRecever3,1") || (k[0] ?? "").includes('Shairport Sync')){ this.alacEncoding = true } + if ((k[0] ?? "").includes('Shairport Sync')){ + // shairport sync doesn't support airplay 2 via NTP + this.airplay2 = false + } console.log("needPin",this.needPin) console.log("mode-atv",this.mode) console.log("alacEncoding",this.alacEncoding) diff --git a/lib/devices.js b/lib/devices.js index 08735a9..e0ed52a 100644 --- a/lib/devices.js +++ b/lib/devices.js @@ -19,9 +19,10 @@ Devices.prototype.init = function() { var self = this; self.audioOut.on('need_sync', function(seq) { // relay to all devices + self.forEach(function(dev) { - if(dev.onSyncNeeded && dev.controlPort) - dev.onSyncNeeded(seq); + try{ if(dev.onSyncNeeded && dev.controlPort) + dev.onSyncNeeded(seq); } catch(e){} }); }); }; diff --git a/lib/rtsp.js b/lib/rtsp.js index 3aa056e..0629ec4 100644 --- a/lib/rtsp.js +++ b/lib/rtsp.js @@ -567,11 +567,11 @@ Client.prototype.sendNextRequest = async function(di) { this.encryptionKey = null; request = '' - // if (this.transient) { - // (this.status = PAIR_SETUP_1) - // this.sendNextRequest(); - // } else { - if (this.needPin || (this.airplay2 != null && this.password == null)){ + if (this.transient && (this.needPin != true) && (this.needPassword != true)) { + (this.status = PAIR_SETUP_1) + this.sendNextRequest(); + } else + if (this.needPin){ request += this.makeHead("POST","/pair-pin-start", "", true); if (this.airplay2){ request += 'User-Agent: AirPlay/409.16\r\n' @@ -810,7 +810,7 @@ Client.prototype.sendNextRequest = async function(di) { case AUTH_SETUP: request = '' request += this.makeHead("POST","/auth-setup", di); - request += 'Content-Length:' + 33 + '\r\n\r\n'; + request += 'Content-Length: ' + 33 + '\r\n\r\n'; let finalbuffer = Buffer.concat([Buffer.from(request, 'utf-8'), Buffer.from([0x01, // unencrypted 0x59,0x02,0xed,0xe9,0x0d,0x4e,0xf2,0xbd, // static Curve 25519 key @@ -904,9 +904,10 @@ Client.prototype.sendNextRequest = async function(di) { request += 'User-Agent: AirPlay/409.16\r\n' request += 'Connection: keep-alive\r\n' request += 'CSeq: ' + this.nextCSeq() + '\r\n\r\n' ; + if (this.credentials){ let enct1x = this.credentials.encrypt(Buffer.concat([Buffer.from(request, 'utf-8')])); this.socket.write(enct1x) - request = '' + request = ''} //console.log(request); break; case SETUP_AP2_1: @@ -958,7 +959,8 @@ Client.prototype.sendNextRequest = async function(di) { console.log('timing socket pinged', rinfo.port, rinfo.address) }); this.timingsocket.bind(this.timingPort, this.socket.address().address); - request += 'Content-Length:' + Buffer.byteLength(setap1) + '\r\n\r\n'; + request += 'Content-Length: ' + Buffer.byteLength(setap1) + '\r\n\r\n'; + console.log(request) let s1ct = this.credentials.encrypt(Buffer.concat([Buffer.from(request, 'utf-8'),setap1])); this.socket.write(s1ct); request = ''