Merge pull request #17 from JurajNyiri/workaround_cors_playmedia

Add: Workaround for users encountering CORS errors when requesting to play media through plexPlayer
pull/30/head 1.3.1
Juraj Nyíri 3 years ago committed by GitHub
commit 93e543fd5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -377,6 +377,34 @@ You can use _:desc_ or _:asc_ after every value to change the order from ascendi
| mediaHeight | Sorts by resolution |
| mediaBitrate | Sorts by bitrate |
## FAQ
<details>
<summary>I am using plexPlayer and nothing happens when play button is pressed</summary>
- Make sure that your device is turned on, and has Plex running
- Reload tab
- Try hitting play button again
If it still doesn't work and everything else works, you are probably encountering CORS issue. You can check this by opening developer tools and looking into console log or network tab.
The reason why this is happening only for this call is right now unknown, but there is a workaround.
Edit configuration.yaml of your Home Assistant and add following rest_command:
```
rest_command:
pmha_playmedia:
url: "{{ url }}"
headers:
X-Plex-Target-Client-Identifier: "{{ target_client_identifier }}"
X-Plex-Client-Identifier: "{{ client_identifier }}"
```
Restart Home Assistant, clear browser cache and try hitting play again. It should now work.
</details>
## Ask for help or help development
Join [Discord](https://discord.gg/jqqz9jQXWx) or [Home Assistant Community](https://community.home-assistant.io/t/custom-component-card-plex-meets-home-assistant/304349).

@ -18973,6 +18973,19 @@ class PlayController {
}
}
catch (err) {
try {
await this.hass.callService('rest_command', 'pmha_playmedia', {
// eslint-disable-next-line @typescript-eslint/camelcase
url,
// eslint-disable-next-line @typescript-eslint/camelcase
target_client_identifier: machineID,
// eslint-disable-next-line @typescript-eslint/camelcase
client_identifier: 'PlexMeetsHomeAssistant'
});
}
catch (homeAssistantErr) {
// pass
}
if (lodash.includes(err.message, '404')) {
throw Error('Defined plexPlayer is currently not available for playback.');
}

@ -182,6 +182,18 @@ class PlayController {
throw Error('Error while asking plex to play a movie - target device not available.');
}
} catch (err) {
try {
await this.hass.callService('rest_command', 'pmha_playmedia', {
// eslint-disable-next-line @typescript-eslint/camelcase
url,
// eslint-disable-next-line @typescript-eslint/camelcase
target_client_identifier: machineID,
// eslint-disable-next-line @typescript-eslint/camelcase
client_identifier: 'PlexMeetsHomeAssistant'
});
} catch (homeAssistantErr) {
// pass
}
if (_.includes(err.message, '404')) {
throw Error('Defined plexPlayer is currently not available for playback.');
} else {

Loading…
Cancel
Save