protected function poll($cb = null)
{
$this->appInstance->subscribe('s2c:' . $this->sessId, [$this, 's2c'], function ($redis) use($cb) {
$this->appInstance->publish('poll:' . $this->sessId, json_encode($this->pollMode), function ($redis) use($cb) {
if (!$redis) {
$cb === null || $cb();
return;
}
if ($redis->result > 0) {
$cb === null || $cb();
return;
}
$this->appInstance->setnx('sess:' . $this->sessId, $this->attrs->server['REQUEST_URI'], function ($redis) use($cb) {
if (!$redis || $redis->result === 0) {
$this->error(3000);
$cb === null || $cb();
return;
}
$this->appInstance->expire('sess:' . $this->sessId, $this->appInstance->config->deadsessiontimeout->value, function ($redis) use($cb) {
if (!$redis || $redis->result === 0) {
$this->error(3000);
$cb === null || $cb();
return;
}
$this->appInstance->subscribe('state:' . $this->sessId, function ($redis) use($cb) {
if (!$redis) {
return;
}
list(, $chan, $state) = $redis->result;
if ($state === 'started') {
$this->sendFrame('o');
if (!in_array('stream', $this->pollMode)) {
$this->finish();
return;
}
}
$this->appInstance->publish('poll:' . $this->sessId, json_encode($this->pollMode), function ($redis) use($cb) {
if (!$redis || $redis->result === 0) {
$this->error(3000);
$cb === null || $cb();
return;
}
$cb === null || $cb();
});
}, function ($redis) use($cb) {
if (!$this->appInstance->beginSession($this->path, $this->sessId, $this->attrs->server)) {
$this->header('404 Not Found');
$this->finish();
$this->unsubscribeReal('state:' . $this->sessId);
}
$cb === null || $cb();
});
});
});
});
});
}