Skip to content

Commit

Permalink
fix indent
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostrick committed Dec 25, 2017
1 parent be34199 commit 4580fcb
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 51 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const search = require('./lib/search'),
Connecter = require('./lib/connect')
Connecter = require('./lib/connect')

module.exports = { search, Connecter }
82 changes: 41 additions & 41 deletions lib/connect.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
const googletts = require('google-tts-api'),
Client = require('castv2-client').Client,
DefaultMediaReceiver = require('castv2-client').DefaultMediaReceiver
Client = require('castv2-client').Client,
DefaultMediaReceiver = require('castv2-client').DefaultMediaReceiver

const Connecter = (() => {
const playMethod = Symbol('playMethod')

class Connecter {

constructor(ip){
this.ip = ip
this.lang = 'en'
}

config(options = {}) {
this.lang = options.lang || this.lang
}

async speak(message, speed = 1, timeout = 3000) {
const url = await googletts(message, this.lang, speed, timeout)
return await this[playMethod](url)
}

async [playMethod](url) {

const client = new Client()
const params = {
contentId: url,
contentType: 'audio/mp3',
streamType: 'BUFFERED'
}

const status = await new Promise((resolve, reject) => client.connect(this.ip, () => {
client.launch(DefaultMediaReceiver, (err, player) => {
player.load(params, { autoplay: true }, (err, status) => {
err ? reject() : resolve(status)
})
})
}))

client.close()
return status
}
const playMethod = Symbol('playMethod')

class Connecter {

constructor(ip){
this.ip = ip
this.lang = 'en'
}

config(options = {}) {
this.lang = options.lang || this.lang
}

async speak(message, speed = 1, timeout = 3000) {
const url = await googletts(message, this.lang, speed, timeout)
return await this[playMethod](url)
}

async [playMethod](url) {

const client = new Client()
const params = {
contentId: url,
contentType: 'audio/mp3',
streamType: 'BUFFERED'
}

const status = await new Promise((resolve, reject) => client.connect(this.ip, () => {
client.launch(DefaultMediaReceiver, (err, player) => {
player.load(params, { autoplay: true }, (err, status) => {
err ? reject() : resolve(status)
})
})
}))

client.close()
return status
}
}

return Connecter;
return Connecter;

})()

Expand Down
18 changes: 9 additions & 9 deletions lib/search.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const mdns = require('mdns'),
browser = mdns.createBrowser(mdns.tcp('googlecast'))
browser = mdns.createBrowser(mdns.tcp('googlecast'))

async function search(waitTime = 1000) {

let services = []
let services = []

browser.start()
browser.on('serviceUp', service => { services.push(service) })
await new Promise(resolve => setTimeout(resolve, 1000))
browser.stop()
browser.start()
browser.on('serviceUp', service => { services.push(service) })
await new Promise(resolve => setTimeout(resolve, 1000))
browser.stop()

return services
.filter(service => { if(service.txtRecord.md === 'Google Home') return service })
.map(service => { return Object.assign(service.txtRecord, {address: service.addresses[0]}) })
return services
.filter(service => { if(service.txtRecord.md === 'Google Home') return service })
.map(service => { return Object.assign(service.txtRecord, {address: service.addresses[0]}) })
}

module.exports = search

0 comments on commit 4580fcb

Please sign in to comment.