Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2245 from zazabe/fix-stream-media
Browse files Browse the repository at this point in the history
Remove unreliable hasStreamPublish method from StreamChannel_Media
  • Loading branch information
zazabe authored Jul 7, 2016
2 parents 2c2bb6f + 91b15d2 commit b8dd3ef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
4 changes: 1 addition & 3 deletions library/CM/MediaStreams/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public function checkStreams() {
if ($streamChannel instanceof CM_StreamChannel_DisallowInterface) {
/** @var CM_Model_StreamChannel_Media|CM_StreamChannel_DisallowInterface $streamChannel */
$streamChannelIsValid = $streamChannel->isValid();
if ($streamChannel->hasStreamPublish()) {
/** @var CM_Model_Stream_Publish $streamPublish */
$streamPublish = $streamChannel->getStreamPublish();
if ($streamPublish = $streamChannel->findStreamPublish()) {
if (!$streamChannelIsValid || !$this->_isPublishAllowed($streamPublish)) {
$this->_stopStream($streamPublish);
}
Expand Down
20 changes: 14 additions & 6 deletions library/CM/Model/StreamChannel/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,30 @@ public function getMediaId() {
return $mediaId;
}

/**
* @return CM_Model_Stream_Publish|null
*/
public function findStreamPublish() {
return $this->getStreamPublishs()->getItem(0);
}

/**
* @return CM_Model_Stream_Publish
* @throws CM_Exception_Invalid
*/
public function getStreamPublish() {
if (!$this->hasStreamPublish()) {
$publish = $this->findStreamPublish();
if (null === $publish) {
throw new CM_Exception_Invalid('StreamChannel `' . $this->getId() . '` has no StreamPublish.');
}
return $this->getStreamPublishs()->getItem(0);
return $publish;
}

/**
* @return boolean
* @return bool
*/
public function hasStreamPublish() {
return (boolean) $this->getStreamPublishs()->getCount();
return null !== $this->findStreamPublish();
}

/**
Expand All @@ -57,8 +65,8 @@ public function getServerId() {

public function jsonSerialize() {
$array = parent::jsonSerialize();
if ($this->hasStreamPublish()) {
$array['user'] = $this->getStreamPublish()->getUser();
if ($publish = $this->findStreamPublish()) {
$array['user'] = $publish->getUser();
}
return $array;
}
Expand Down
9 changes: 3 additions & 6 deletions tests/library/CM/MediaStreams/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ public function testCheckStreamsInvalidStreamChannel() {

$streamChannel = $this->mockClass('CM_Model_StreamChannel_Media', ['CM_StreamChannel_DisallowInterface'])->newInstanceWithoutConstructor();
$streamChannel->mockMethod('isValid')->set(false);
$streamChannel->mockMethod('hasStreamPublish')->set(true);
$streamChannel->mockMethod('getStreamPublish')->set($streamPublish);
$streamChannel->mockMethod('findStreamPublish')->set($streamPublish);
$streamChannel->mockMethod('getStreamSubscribes')->set([$streamSubscribe]);

$streamRepository = $this->mockClass('CM_MediaStreams_StreamRepository')->newInstanceWithoutConstructor();
Expand Down Expand Up @@ -37,8 +36,7 @@ public function testCheckStreamsValidStreamChannel() {

$streamChannel = $this->mockClass('CM_Model_StreamChannel_Media', ['CM_StreamChannel_DisallowInterface'])->newInstanceWithoutConstructor();
$streamChannel->mockMethod('isValid')->set(true);
$streamChannel->mockMethod('hasStreamPublish')->set(true);
$streamChannel->mockMethod('getStreamPublish')->set($streamPublish);
$streamChannel->mockMethod('findStreamPublish')->set($streamPublish);
$streamChannel->mockMethod('getStreamSubscribes')->set([$streamSubscribe]);

$streamRepository = $this->mockClass('CM_MediaStreams_StreamRepository')->newInstanceWithoutConstructor();
Expand Down Expand Up @@ -75,8 +73,7 @@ public function testCheckStreamsNoConnectionsDisallowed() {

$streamChannel = $this->mockClass('CM_Model_StreamChannel_Media')->newInstanceWithoutConstructor();
$isValidMethod = $streamChannel->mockMethod('isValid');
$streamChannel->mockMethod('hasStreamPublish')->set(true);
$streamChannel->mockMethod('getStreamPublish')->set($streamPublish);
$streamChannel->mockMethod('findStreamPublish')->set($streamPublish);
$streamChannel->mockMethod('getStreamSubscribes')->set([$streamSubscribe]);

$streamRepository = $this->mockClass('CM_MediaStreams_StreamRepository')->newInstanceWithoutConstructor();
Expand Down

0 comments on commit b8dd3ef

Please sign in to comment.