Use airplayer (#452)
* Use airplayer * Mock AirPlay volume support * Add AirPlay event support
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
"url": "https://github.com/feross/webtorrent-desktop/issues"
|
"url": "https://github.com/feross/webtorrent-desktop/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"airplay-js": "guerrerocarlos/node-airplay-js",
|
"airplayer": "^2.0.0",
|
||||||
"application-config": "^0.2.1",
|
"application-config": "^0.2.1",
|
||||||
"bitfield": "^1.0.2",
|
"bitfield": "^1.0.2",
|
||||||
"chromecasts": "^1.8.0",
|
"chromecasts": "^1.8.0",
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ module.exports = {
|
|||||||
setRate
|
setRate
|
||||||
}
|
}
|
||||||
|
|
||||||
var airplay = require('airplay-js')
|
var airplayer = require('airplayer')()
|
||||||
var chromecasts = require('chromecasts')()
|
var chromecasts = require('chromecasts')()
|
||||||
var dlnacasts = require('dlnacasts')()
|
var dlnacasts = require('dlnacasts')()
|
||||||
|
|
||||||
@@ -41,10 +41,9 @@ function init (appState, callback) {
|
|||||||
state.devices.dlna = dlnaPlayer(player)
|
state.devices.dlna = dlnaPlayer(player)
|
||||||
})
|
})
|
||||||
|
|
||||||
var browser = airplay.createBrowser()
|
airplayer.on('update', function (player) {
|
||||||
browser.on('deviceOn', function (player) {
|
|
||||||
state.devices.airplay = airplayPlayer(player)
|
state.devices.airplay = airplayPlayer(player)
|
||||||
}).start()
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// chromecast player implementation
|
// chromecast player implementation
|
||||||
@@ -129,13 +128,31 @@ function chromecastPlayer (player) {
|
|||||||
|
|
||||||
// airplay player implementation
|
// airplay player implementation
|
||||||
function airplayPlayer (player) {
|
function airplayPlayer (player) {
|
||||||
|
function addEvents () {
|
||||||
|
player.on('event', function (event) {
|
||||||
|
switch (event.state) {
|
||||||
|
case 'loading':
|
||||||
|
break
|
||||||
|
case 'playing':
|
||||||
|
state.playing.isPaused = false
|
||||||
|
break
|
||||||
|
case 'paused':
|
||||||
|
state.playing.isPaused = true
|
||||||
|
break
|
||||||
|
case 'stopped':
|
||||||
|
break
|
||||||
|
}
|
||||||
|
update()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function open () {
|
function open () {
|
||||||
player.play(state.server.networkURL, 0, function (res) {
|
player.play(state.server.networkURL, function (err, res) {
|
||||||
if (res.statusCode !== 200) {
|
if (err) {
|
||||||
state.playing.location = 'local'
|
state.playing.location = 'local'
|
||||||
state.errors.push({
|
state.errors.push({
|
||||||
time: new Date().getTime(),
|
time: new Date().getTime(),
|
||||||
message: 'Could not connect to AirPlay.'
|
message: 'Could not connect to AirPlay. ' + err.message
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
state.playing.location = 'airplay'
|
state.playing.location = 'airplay'
|
||||||
@@ -145,11 +162,11 @@ function airplayPlayer (player) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function play (callback) {
|
function play (callback) {
|
||||||
player.rate(1, callback)
|
player.resume(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function pause (callback) {
|
function pause (callback) {
|
||||||
player.rate(0, callback)
|
player.pause(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function stop (callback) {
|
function stop (callback) {
|
||||||
@@ -157,13 +174,18 @@ function airplayPlayer (player) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function status () {
|
function status () {
|
||||||
player.status(function (status) {
|
player.playbackInfo(function (err, res, status) {
|
||||||
state.playing.isPaused = status.rate === 0
|
if (err) {
|
||||||
state.playing.currentTime = status.position
|
state.playing.location = 'local'
|
||||||
// TODO: get airplay volume, implementation needed. meanwhile set value in setVolume
|
state.errors.push({
|
||||||
// According to docs is in [-30 - 0] (db) range
|
time: new Date().getTime(),
|
||||||
// should be converted to [0 - 1] using (val / 30 + 1)
|
message: 'Could not connect to AirPlay. ' + err.message
|
||||||
update()
|
})
|
||||||
|
} else {
|
||||||
|
state.playing.isPaused = status.rate === 0
|
||||||
|
state.playing.currentTime = status.position
|
||||||
|
update()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,12 +194,13 @@ function airplayPlayer (player) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function volume (volume, callback) {
|
function volume (volume, callback) {
|
||||||
// TODO remove line below once we can fetch the information in status update
|
// AirPlay doesn't support volume
|
||||||
|
// TODO: We should just disable the volume slider
|
||||||
state.playing.volume = volume
|
state.playing.volume = volume
|
||||||
volume = (volume - 1) * 30
|
|
||||||
player.volume(volume, callback)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addEvents()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
player: player,
|
player: player,
|
||||||
open: open,
|
open: open,
|
||||||
|
|||||||
Reference in New Issue
Block a user