wormling / phparia

Framework for creating ARI (Asterisk REST Interface) applications.
http://phparia.org
Apache License 2.0
39 stars 35 forks source link

Bridge getChannels() return empty array #10

Open hartois opened 8 years ago

hartois commented 8 years ago

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 commented 8 years ago

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

wormling commented 8 years ago

$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?

hartois commented 8 years ago

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

wormling commented 8 years ago

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.

hartois commented 8 years ago

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
    ......
});
wormling commented 8 years ago

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?

hartois commented 8 years ago

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.

wormling commented 8 years ago

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

hartois commented 8 years ago

Any news on this issue?

zloi-bandit commented 6 years ago

Sorry for ugly view

zloi-bandit commented 6 years ago

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.