Skip to content

Commit

Permalink
fix for shairport-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
vapormusic committed Jan 27, 2023
1 parent be3e126 commit e015977
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
8 changes: 6 additions & 2 deletions lib/device_airtunes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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='))
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions lib/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){}
});
});
};
Expand Down
18 changes: 10 additions & 8 deletions lib/rtsp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 = ''
Expand Down

0 comments on commit e015977

Please sign in to comment.