Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secure websockets #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions libraries/Codeigniter_websocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,29 @@ public function __construct(array $config = array())
public function run()
{
// Initiliaze all the necessary class
$server = IoServer::factory(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't remove the previous Timer.

new HttpServer(
new WsServer(
new Server()
)
),
$this->port,
$this->host
);

//If you want to use timer
if ($this->timer != false) {
$server->loop->addPeriodicTimer($this->timer_interval, function () {
if (!empty($this->callback['citimer'])) {
call_user_func_array($this->callback['citimer'], array(date('d-m-Y h:i:s a', time())));
}
});

}

// Run the socket connection !
$server->run();
// wss://
// https://github.com/ratchetphp/Ratchet/issues/489#issuecomment-457714221
// https://forums.phpfreaks.com/topic/309486-websockets-will-not-work-over-tlsssl/?do=findComment&comment=1571386
$app = new \Ratchet\Http\HttpServer(
new \Ratchet\WebSocket\WsServer(
new Server()
)
);

$loop = \React\EventLoop\Factory::create();

$secure_websockets = new \React\Socket\Server($this->host . ':' . $this->port, $loop);
$secure_websockets = new \React\Socket\SecureServer($secure_websockets, $loop, [
'local_cert' => '/path/to/server.crt',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local_cert
local_pk
allow_self_signed
verify_peer

The above parameters should not be hardcoded. Please use the codeigniter_websocket.php config file to maintain the value.

'local_pk' => '/path/to/server.key',
'allow_self_signed' => TRUE, // allow self signed certs, should be false in production
'verify_peer' => FALSE
]);

$secure_websockets_server = new \Ratchet\Server\IoServer($app, $secure_websockets, $loop);

$secure_websockets_server->run();
}

/**
Expand Down