Skip to content

Commit

Permalink
Merge branch 'release/1.0.8' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Irelan committed Nov 14, 2020
2 parents 06b0a8f + 5d38e5d commit c83a6c2
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 3 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
Expand Down
7 changes: 6 additions & 1 deletion src/YoutubeLiveEmbed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,6 +31,7 @@
* @since 1.0.0
*
* @property EmbedService $embed
* @property StreamService $stream
*/
class YoutubeLiveEmbed extends Plugin
{
Expand All @@ -52,7 +54,7 @@ class YoutubeLiveEmbed extends Plugin
/**
* @var string
*/
public $schemaVersion = '1.0.0';
public $schemaVersion = '1.0.9';

// Public Methods
// =========================================================================
Expand All @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
// YouTube Channel ID
"youtubeChannelId" => '',
"isLive" => false,
"connectionToken" => '',
];
47 changes: 47 additions & 0 deletions src/controllers/StreamController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* YouTube Live Embed plugin for Craft CMS 3.x
*
* This plugin allows you to embed a YouTube live stream and/or live chat on your webpage
*
* @link https://nystudio107.com
* @copyright Copyright (c) 2019 nystudio107
*/

namespace nystudio107\youtubeliveembed\controllers;

use nystudio107\youtubeliveembed\YoutubeLiveEmbed;

use Craft;
use craft\web\Controller;

/**
* @author nystudio107
* @package YoutubeLiveEmbed
* @since 1.0.9
*/
class StreamController extends Controller
{
// Protected Properties
// =========== ==============================================================

protected $allowAnonymous = [
'update-stream-status',
];

// Public Methods
// =========================================================================


/**
* Toggles the stream to live or offline in plugin
*
* @param string $yttoken
* @return
*/

public function actionUpdateStreamStatus($yttoken = '')
{
return YoutubeLiveEmbed::$plugin->stream->setStreamStatus($yttoken);
}
}
6 changes: 6 additions & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class Settings extends Model
*/
public $isLive = false;

/**
* @var string
*/
public $connectionToken = '';

// Public Methods
// =========================================================================

Expand All @@ -44,6 +49,7 @@ public function rules()
['youtubeChannelId', 'string'],
['youtubeChannelId', 'default', 'value' => ''],
['isLive', 'boolean'],
['connectionToken', 'string'],
];
}
}
44 changes: 44 additions & 0 deletions src/services/Stream.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* YouTube Live Embed plugin for Craft CMS 3.x
*
* This plugin allows you to embed a YouTube live stream and/or live chat on your webpage
*
* @link https://nystudio107.com
* @copyright Copyright (c) 2019 nystudio107
*/

namespace nystudio107\youtubeliveembed\services;

use nystudio107\youtubeliveembed\YoutubeLiveEmbed;
use nystudio107\youtubeliveembed\helpers\PluginTemplate;

use Craft;
use craft\base\Component;
use craft\helpers\UrlHelper;

/** @noinspection MissingPropertyAnnotationsInspection */

/**
* @author nystudio107
* @package YoutubeLiveEmbed
* @since 1.0.0
*/
class Stream extends Component
{

public function setStreamStatus($yttoken)
{
$myPlugin = Craft::$app->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;
}
}
7 changes: 7 additions & 0 deletions src/templates/settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit c83a6c2

Please sign in to comment.