43 if(count($packets) === 0){
44 throw new \InvalidArgumentException(
"Cannot broadcast empty list of packets");
47 return Timings::$broadcastPackets->time(
function() use ($recipients, $packets) :
bool{
50 foreach($recipients as $player){
51 if($player->isConnected()){
52 $sessions[] = $player->getNetworkSession();
55 if(count($sessions) === 0){
60 $uniqueBroadcasters = [];
62 $broadcasterTargets = [];
63 foreach($sessions as $recipient){
64 $broadcaster = $recipient->getBroadcaster();
65 $uniqueBroadcasters[spl_object_id($broadcaster)] = $broadcaster;
66 $broadcasterTargets[spl_object_id($broadcaster)][spl_object_id($recipient)] = $recipient;
68 foreach($uniqueBroadcasters as $broadcaster){
69 $broadcaster->broadcastPackets($broadcasterTargets[spl_object_id($broadcaster)], $packets);
81 $uniqueBroadcasters = [];
82 $broadcasterTargets = [];
84 foreach($recipients as $recipient){
85 $session = $recipient->getNetworkSession();
86 $broadcaster = $session->getEntityEventBroadcaster();
87 $uniqueBroadcasters[spl_object_id($broadcaster)] = $broadcaster;
88 $broadcasterTargets[spl_object_id($broadcaster)][spl_object_id($session)] = $session;
91 foreach($uniqueBroadcasters as $k => $broadcaster){
92 $callback($broadcaster, $broadcasterTargets[$k]);