Automatically determine which version of Socket.io is used
The Version 0.X and 1.X of Socket.io is get the version of /socket.io/socket.io.js like next.
public function getVersion()
{
// get socket.io version
$url = 'http://' . $this->url['host'] . ':' . $this->url['port'];
if (true === $this->url['secured']) {
$url = 'https://' . $this->url['host'] . ':' . $this->url['port'];
}
$url .= '/socket.io/socket.io.js';
// need to ini_set('allow_url_fopen', 'On');
$socketio = file_get_contents($url);
preg_match_all('/io\.version = [\'\"]([0-9\.]+)[\'\"];/', $socketio, $match);
if (isset($match[1]) === false)
return '1.x.x';
return $match[1][0];
}
If elephant.io/src/Client.php of refacto-3.0 is used like next, i want to listen for your think.
// The Client class was used getVersion() into the Client::__construct.
$client = new Client('http://localhost:9001');
$client->initialize();
$client->emit('broadcast', ['foo' => 'bar']);
$client->close();
I don't think it should be done in the Client, as it could be used for something else than Socket.io. But, as I already discussed it in https://github.com/Wisembly/elephant.io/pull/53#issuecomment-50449345, it should maybe be put into a factory of some sorts.
I'll try to add something later, so I'm keeping this ticket open to leave a reminder. :)
The issue of https://github.com/Wisembly/elephant.io/pull/53 was solved about question of myself. so i was able to understand for direction of this project.
Thanks!! :)