diff --git a/CHANGELOG.md b/CHANGELOG.md index ec473fd..82d475e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # YouTube Live Embed Changelog +### 1.0.8 - 2020-11-14 +### Added +- Support for webhook to toggle livestream status on and off. + +## 1.0.7 - 2020-11-12 +### Fixed +- Fixed additional issue with regex of livestream page to get videoId + +## 1.0.6 - 2020-11-12 +### Fixed +- Fixed issue with regex of livestream page to get videoId so the chat would load properly + ## 1.0.5 2020-07-12 ### Fixed diff --git a/composer.json b/composer.json index 80a2728..babeb2b 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "nystudio107/craft-youtubeliveembed", "description": "This plugin allows you to embed a YouTube live stream and/or live chat on your webpage", "type": "craft-plugin", - "version": "1.0.7", + "version": "1.0.8", "keywords": [ "craft", "cms", @@ -40,7 +40,8 @@ "hasCpSection": false, "changelogUrl": "https://raw.githubusercontent.com/nystudio107/craft-youtubeliveembed/master/CHANGELOG.md", "components": { - "embed": "nystudio107\\youtubeliveembed\\services\\Embed" + "embed": "nystudio107\\youtubeliveembed\\services\\Embed", + "stream": "nystudio107\\youtubelivembed\\services\\Stream" }, "class": "nystudio107\\youtubeliveembed\\YoutubeLiveEmbed" } diff --git a/src/YoutubeLiveEmbed.php b/src/YoutubeLiveEmbed.php index 1f2c7d0..32e064e 100644 --- a/src/YoutubeLiveEmbed.php +++ b/src/YoutubeLiveEmbed.php @@ -11,6 +11,7 @@ namespace nystudio107\youtubeliveembed; use nystudio107\youtubeliveembed\services\Embed as EmbedService; +use nystudio107\youtubeliveembed\services\Stream as StreamService; use nystudio107\youtubeliveembed\variables\YoutubeLiveEmbedVariable; use nystudio107\youtubeliveembed\models\Settings; @@ -30,6 +31,7 @@ * @since 1.0.0 * * @property EmbedService $embed + * @property StreamService $stream */ class YoutubeLiveEmbed extends Plugin { @@ -52,7 +54,7 @@ class YoutubeLiveEmbed extends Plugin /** * @var string */ - public $schemaVersion = '1.0.0'; + public $schemaVersion = '1.0.9'; // Public Methods // ========================================================================= @@ -63,6 +65,9 @@ class YoutubeLiveEmbed extends Plugin public function init() { parent::init(); + $this->setComponents([ + 'stream' => services\Stream::class, + ]); self::$plugin = $this; self::$youtubeChannelId = $this->getSettings()->youtubeChannelId; diff --git a/src/config.php b/src/config.php index 4c01999..bca38c8 100644 --- a/src/config.php +++ b/src/config.php @@ -26,4 +26,5 @@ // YouTube Channel ID "youtubeChannelId" => '', "isLive" => false, + "connectionToken" => '', ]; diff --git a/src/controllers/StreamController.php b/src/controllers/StreamController.php new file mode 100644 index 0000000..583f9c2 --- /dev/null +++ b/src/controllers/StreamController.php @@ -0,0 +1,47 @@ +stream->setStreamStatus($yttoken); + } +} \ No newline at end of file diff --git a/src/models/Settings.php b/src/models/Settings.php index 49e9f0a..d5abb0d 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -32,6 +32,11 @@ class Settings extends Model */ public $isLive = false; + /** + * @var string + */ + public $connectionToken = ''; + // Public Methods // ========================================================================= @@ -44,6 +49,7 @@ public function rules() ['youtubeChannelId', 'string'], ['youtubeChannelId', 'default', 'value' => ''], ['isLive', 'boolean'], + ['connectionToken', 'string'], ]; } } diff --git a/src/services/Stream.php b/src/services/Stream.php new file mode 100644 index 0000000..2c627d4 --- /dev/null +++ b/src/services/Stream.php @@ -0,0 +1,44 @@ +plugins->getPlugin('youtubeliveembed'); + $isLive = (YoutubeLiveEmbed::$plugin->embed->isLive() ? false : true); + + if ($this->getToken() == $yttoken) { + return Craft::$app->plugins->savePluginSettings($myPlugin, array('isLive' => $isLive)); + } + } + + protected function getToken(): string + { + return YoutubeLiveEmbed::getInstance()->settings->connectionToken; + } +} diff --git a/src/templates/settings.twig b/src/templates/settings.twig index c916ad1..5b985a2 100644 --- a/src/templates/settings.twig +++ b/src/templates/settings.twig @@ -22,6 +22,13 @@ name: 'youtubeChannelId', value: settings['youtubeChannelId'] }) }} +{{ forms.textField({ + label: 'Connection Token', + instructions: 'A connection token you can use to toggle the stream status via cURL.', + id: 'connectionToken', + name: 'connectionToken', + value: settings['connectionToken'] +}) }} {{ forms.lightswitchField({ label: 'Is the stream live?', instructions: 'Manually choose whether the stream is live or not',