phparia icon indicating copy to clipboard operation
phparia copied to clipboard

Bridge getChannels() return empty array

Open hartois opened this issue 8 years ago • 11 comments

Hello.

$bridge = $client->bridges()->createBridge(uniqid(),'mixing', $bridgeName);
$client->bridges()->addChannel($bridge->getId(),$call1);
$client->bridges()->addChannel($bridge->getId(),$call2);
print_r($bridge->getChannels());

Calls successfuly added, bridge working, but getChannels() return empty array. What am I doing wrong?

hartois avatar Mar 24 '16 13:03 hartois

Hmm $ari->bridges()->getBridge($bridge->getId())->getChannels(); returning channels list

hartois avatar Mar 24 '16 13:03 hartois

$bridge is an object containing the state of the bridge before the channels were added. I could modify resources to always call ARI, but I'd be a bit worried about the performance. Could also have a refresh option but that's similar to just querying for a new $bridge. Any ideas?

wormling avatar Mar 24 '16 18:03 wormling

I suggest add to bridge resource a listener to events ChannelEnteredBridge/ChannelLeft Bridge on AriClient May be as option

hartois avatar Mar 24 '16 18:03 hartois

Good idea. I'll can find the spots in the code that apply this weekend or you can submit a PR if you have the time.

wormling avatar Mar 24 '16 18:03 wormling

I think that I can not find the time earlier than a few days( If I have free time - I do PR I think that the opportunity to listen to these events on the bridge will also be very convenient. Such as:

$bridge = $client->bridges()->createBridge(uniqid(),'mixing', $bridgeName);
$bridge->on('ChannelEnteredBridge',function($event){
...
do some
... 
});

UPD: I will clarify. Now if set listener $bridge->on('ChannelEnteredBridge',function($event){ event will be fired on ALL bridges, but should only on the bridge an object which has been set listener

UPD2: Now I use some workaround

$bridgeId = $bridge->getId();
$bridge->on('ChannelLeftBridge', function (ChannelLeftBridge $event) use($bridgeId){
    if($event->getBridge()->getId() !== $bridgeId)
        return;
    ......
    some code
    ......
});

hartois avatar Mar 24 '16 18:03 hartois

IdentifiableEventInterface has a single getEventId() which should return the string used in emit(). ChannelLeftBridge class then implements this using:

return "{$this->getType()}_{$this->getChannel()->getId()}";

I'm not sure what the best way is to associate an event with a channel and a bridge but maybe change IdentifiableEventInterface::getEventId() to IdentifiableEventInterface::getEventIds() and implement it like:

return array( "{$this->getType()}_{$this->getChannel()->getId()}", "{$this->getType()}_{$this->getBridge()->getId()}" );

Then we could emit using a foreach which would send this event to both the channel and the bridge where we could have Bridge::on(ce)ChannelLeftBridge(...).

Thoughts?

  • This would cause a breaking change though since we would have more than one id. We would still need to implement getEventId() and set the eventId of two instances of the event object to avoid that.

wormling avatar Apr 17 '16 07:04 wormling

Ability to set a listener on both the channel and the bridge is logical and expected. More exact: if the event involves some more resources, it should be possible to install a listener on this resource. For me it is difficult to say how best to implement this.

hartois avatar Apr 26 '16 07:04 hartois

Working on 3.0 now so this will be implemented with breaking changes from 2.X soon.

wormling avatar Apr 26 '16 08:04 wormling

Any news on this issue?

hartois avatar Oct 20 '16 19:10 hartois

Sorry for ugly view

zloi-bandit avatar Dec 07 '17 13:12 zloi-bandit

Also had this problem. In file Resources/Bridge.php I've found that where class variables declared: ` /** * @var array Ids of channels participating in this bridge */ private $channelIds; also where method is declared:

/** * @return array Ids of channels participating in this bridge */ public function getChannelIds() { return $this->channelIds; }`

we have $channelIds, but where constructor is placed we have channels attribute:

`public function __construct(AriClient $client, $response) { parent::__construct($client, $response);

$this->bridgeClass = $this->getResponseValue('bridge_class');
$this->bridgeType = $this->getResponseValue('bridge_type');
$this->**channels** = $this->getResponseValue('channels');
$this->creator = $this->getResponseValue('creator');
$this->id = $this->getResponseValue('id');
$this->name = $this->getResponseValue('name');
$this->technology = $this->getResponseValue('technology');

}`

Maybe that is not good, but when I had corrected channels to channelIds in constructor, $bridgeChannelIds = $this->client->bridges()->getBridge($bridgeId)->getChannelIds() had began working.

zloi-bandit avatar Dec 07 '17 13:12 zloi-bandit