From dad53180bc6c554336c3a30abf64e45c242b2262 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 29 Aug 2014 17:19:38 +0200 Subject: [PATCH] Add event source to the public api --- lib/private/eventsource.php | 2 +- lib/private/server.php | 9 +++++++++ lib/public/ieventsource.php | 32 ++++++++++++++++++++++++++++++++ lib/public/iservercontainer.php | 7 +++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 lib/public/ieventsource.php diff --git a/lib/private/eventsource.php b/lib/private/eventsource.php index 5a870ae3f3..22782d677e 100644 --- a/lib/private/eventsource.php +++ b/lib/private/eventsource.php @@ -12,7 +12,7 @@ * * use server side events with caution, to many open requests can hang the server */ -class OC_EventSource { +class OC_EventSource implements \OCP\IEventSource { /** * @var bool */ diff --git a/lib/private/server.php b/lib/private/server.php index 5d40f1327f..1c3b1b03ce 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -492,4 +492,13 @@ class Server extends SimpleContainer implements IServerContainer { } return new CertificateManager($user); } + + /** + * Returns a search instance + * + * @return \OCP\IEventSource + */ + function getEventSource() { + return new \OC_EventSource(); + } } diff --git a/lib/public/ieventsource.php b/lib/public/ieventsource.php new file mode 100644 index 0000000000..ea4bfc73d4 --- /dev/null +++ b/lib/public/ieventsource.php @@ -0,0 +1,32 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP; + +/** + * wrapper for server side events (http://en.wikipedia.org/wiki/Server-sent_events) + * includes a fallback for older browsers and IE + * + * use server side events with caution, to many open requests can hang the server + */ +interface IEventSource { + /** + * send a message to the client + * + * @param string $type + * @param mixed $data + * + * if only one parameter is given, a typeless message will be send with that parameter as data + */ + public function send($type, $data = null); + + /** + * close the connection of the event source + */ + public function close(); +} diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index 60b0b497c5..24d8894d9f 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -235,4 +235,11 @@ interface IServerContainer { * @return \OCP\ICertificateManager */ function getCertificateManager($user = null); + + /** + * Returns a search instance + * + * @return \OCP\IEventSource + */ + function getEventSource(); }