From 58ec55bed2b797341bfd85d7b9ca7875a1618873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 27 Apr 2012 19:33:28 +0200 Subject: [PATCH] PHP now triggers newMessage-event --- .../lib/server.coffee | 16 +++++++++++++--- .../chat/message/ChatMessageEditor.class.php | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/file/acp/be.bastelstu.wcf.chat.serverPush/lib/server.coffee b/file/acp/be.bastelstu.wcf.chat.serverPush/lib/server.coffee index 1fac265..28874f8 100644 --- a/file/acp/be.bastelstu.wcf.chat.serverPush/lib/server.coffee +++ b/file/acp/be.bastelstu.wcf.chat.serverPush/lib/server.coffee @@ -6,8 +6,10 @@ # @license Creative Commons Attribution-NonCommercial-ShareAlike # @package be.bastelstu.wcf.chat ### +process.title = 'Tims Chat Pushserver' io = require 'socket.io' +net = require 'net' config = require('../config.js').config @@ -17,8 +19,12 @@ log = (message) -> class Server constructor: () -> log 'Starting Pushserver for Tims Chat' + log 'PID is ' + process.pid log 'Using port: ' + config.port + @initUnixSocket() + @initSocketIO() + initSocketIO: () -> @socket = io.listen config.port @socket.set 'log level', 1 @@ -31,9 +37,13 @@ class Server @socket.set 'browser client etag', false @socket.set 'browser client minification', false ).bind(@) - - setInterval((() -> + initUnixSocket: () -> + log 'Initializing Unix-Socket' + socket = net.createServer ((c) -> @socket.sockets.emit 'newMessage' - ).bind(@), 5000) + c.end() + ).bind(@) + + socket.listen process.cwd() + '/../data.sock' new Server() \ No newline at end of file diff --git a/file/lib/data/chat/message/ChatMessageEditor.class.php b/file/lib/data/chat/message/ChatMessageEditor.class.php index 53c10fd..b105ce2 100644 --- a/file/lib/data/chat/message/ChatMessageEditor.class.php +++ b/file/lib/data/chat/message/ChatMessageEditor.class.php @@ -16,6 +16,22 @@ class ChatMessageEditor extends \wcf\data\DatabaseObjectEditor { */ protected static $baseClass = '\wcf\data\chat\message\ChatMessage'; + /** + * Notify the Push-Server. + */ + public static function create(array $parameters = array()) { + try { + if (CHAT_SOCKET_IO_PATH) { + if (file_exists(WCF_DIR.'acp/be.bastelstu.wcf.chat.serverPush/data.sock')) { + $sock = stream_socket_client('unix://data.sock', $errno, $errstr, 1); + fclose($sock); + } + } + } + catch (\Exception $e) { } + + return parent::create($parameters); + } /** * Removes old messages.