protected function addStream(Stream $stream, $type) { $index = (int) $stream->stream(); if ($stream->stream()) { $stream->setStreamSet($this); $this->streams[$type][intval($stream->stream())] = $stream->stream(); $this->streamsObjects[$type][intval($stream->stream())] = $stream; } else { $stream->on("open", function ($event, $stream) use(&$index, $type) { $index = intval($stream->stream()); $stream->setStreamSet($this); $this->streams[$type][$index] = $stream->stream(); $this->streamsObjects[$type][$index] = $stream; }); } $stream->on("close", function ($event, $stream) use(&$index, $type) { $this->removeStream($index, $type); }); }