forked from amilajack/popcorn-time-desktop
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
465 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// @flow | ||
import { Client, DefaultMediaReceiver } from 'castv2-client'; | ||
import mdns from 'mdns'; | ||
import type { | ||
PlayerProviderInterface, | ||
deviceType, | ||
metadataType | ||
} from './PlayerProviderInterface'; | ||
|
||
type castv2DeviceType = { | ||
fullname: string, | ||
addresses: Array<string>, | ||
port: number, | ||
txtRecord: { | ||
fn: string | ||
} | ||
}; | ||
|
||
class ChromecastPlayerProvider implements PlayerProviderInterface { | ||
provider = 'Chromecast'; | ||
|
||
providerId = 'chromecast'; | ||
|
||
supportsSubtitles = true; | ||
|
||
selectedDevice: deviceType; | ||
|
||
devices: Array<deviceType> = []; | ||
|
||
browser: { | ||
on: (event: string, cb: (device: castv2DeviceType) => void) => void, | ||
start: () => void, | ||
stop: () => void | ||
}; | ||
|
||
constructor() { | ||
this.browser = mdns.createBrowser(mdns.tcp('googlecast')); | ||
} | ||
|
||
getDevices(timeout: number = 2000) { | ||
return new Promise(resolve => { | ||
const devices = []; | ||
|
||
this.browser.on('serviceUp', service => { | ||
devices.push({ | ||
name: service.txtRecord.fn, | ||
id: service.fullname, | ||
address: service.addresses[0], | ||
port: service.port | ||
}); | ||
}); | ||
|
||
this.browser.start(); | ||
|
||
setTimeout(() => { | ||
this.browser.stop(); | ||
resolve(devices); | ||
this.devices = devices; | ||
}, timeout); | ||
}); | ||
} | ||
|
||
selectDevice(deviceId: string) { | ||
const selectedDevice = this.devices.find(device => device.id === deviceId); | ||
if (!selectedDevice) { | ||
throw new Error('Cannot find selected device'); | ||
} | ||
this.selectedDevice = selectedDevice; | ||
return selectedDevice; | ||
} | ||
|
||
play(contentUrl: string, metadata: metadataType) { | ||
const client = new Client(); | ||
|
||
if (!this.selectDevice) { | ||
throw new Error('No device selected'); | ||
} | ||
|
||
return new Promise((resolve, reject) => { | ||
client.connect(this.selectedDevice.address, () => { | ||
client.launch(DefaultMediaReceiver, (err, player) => { | ||
if (err) reject(err); | ||
|
||
console.log(contentUrl); | ||
|
||
const media = { | ||
// Here you can plug an URL to any mp4, webm, mp3 or jpg file with the proper contentType. | ||
contentId: contentUrl, | ||
// contentType: 'video/mp4', | ||
streamType: 'BUFFERED', // or LIVE | ||
|
||
// Title and cover displayed while buffering | ||
metadata: { | ||
type: 0, | ||
metadataType: 0, | ||
title: metadata.title, | ||
images: [ | ||
{ | ||
url: metadata.image.poster | ||
} | ||
] | ||
} | ||
}; | ||
|
||
player.load(media, { autoplay: true }, _err => { | ||
if (_err) reject(_err); | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
export default ChromecastPlayerProvider; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Provide a single API interface for all the providers | ||
* @flow | ||
*/ | ||
import ChromecastPlayerProvider from './ChromecastPlayerProvider'; | ||
import type { | ||
PlayerProviderInterface, | ||
deviceType | ||
} from './PlayerProviderInterface'; | ||
|
||
export default class PlayerAdapter { | ||
providers: Array<PlayerProviderInterface> = [new ChromecastPlayerProvider()]; | ||
|
||
devices: Array<deviceType>; | ||
|
||
selectedDevice: deviceType; | ||
|
||
getDevices() { | ||
return Promise.all( | ||
this.providers.map(provider => provider.getDevices(2000)) | ||
); | ||
} | ||
|
||
/** | ||
* @TODO: Proxy all other method calls (ex. play, etc) to the selectedDevice | ||
* instance | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,60 @@ | ||
// @flow | ||
// Initialize the player | ||
export interface PlayerAdapterInterface { | ||
|
||
export type deviceType = { | ||
id: string, | ||
name: string, | ||
address: string, | ||
port: number | ||
}; | ||
|
||
export type metadataType = { | ||
title: string, | ||
image: { | ||
poster: string | ||
} | ||
}; | ||
|
||
export interface PlayerProviderInterface { | ||
provider: string, | ||
|
||
providerId: string, | ||
|
||
selectedDevice?: deviceType, | ||
|
||
devices: Array<deviceType>, | ||
|
||
supportedFormats: Array<string>, | ||
|
||
supportsSubtitles: boolean, | ||
|
||
svgIconFilename: string, | ||
|
||
setup: () => void, | ||
contentUrl: string, | ||
|
||
start: () => void, | ||
port: number, | ||
|
||
pause: () => void, | ||
constructor: () => void, | ||
|
||
restart: () => void, | ||
getDevices: (timeout: number) => Promise<Array<deviceType>>, | ||
|
||
seek: (seconds: number) => void, | ||
|
||
selectDevice: (deviceId: string) => deviceType, | ||
|
||
play: (contentUrl: string, metadata: metadataType) => Promise<void>, | ||
|
||
pause: () => Promise<void>, | ||
|
||
restart: () => Promise<void>, | ||
|
||
/** | ||
* Handle any logic to remove the traces of the player from memory | ||
*/ | ||
cleanup: () => void, | ||
destroy: () => Promise<void>, | ||
|
||
/** | ||
* Check if the plugin is supported on the machine | ||
*/ | ||
isSupported: () => void, | ||
|
||
supportedFormats: Array<string>, | ||
|
||
supportsSubtitles: boolean, | ||
|
||
svgIconFilename: string | ||
isSupported: () => Promise<boolean> | ||
} |
File renamed without changes.
Empty file.
Oops, something went wrong.