diff --git a/contrib/build.php b/contrib/build.php index 9e8e351..19e9037 100755 --- a/contrib/build.php +++ b/contrib/build.php @@ -1,6 +1,6 @@ #!/usr/bin/env php " - "@package be.bastelstu.chat" - "@subpackage nodePush" - -Setup ------ - -Load required namespaces. - - io = require 'socket.io' - net = require 'net' - fs = require 'fs' - -Load config - - config = require '../config.js' - -Prepare environment - - log = (message) -> - console.log "[be.bastelstu.chat.nodePush] #{message}" - - # Ensure our namespace is present - be = be ? {} - be.bastelstu ?= {} - be.bastelstu.chat ?= {} - -be.bastelstu.chat.nodePush -========================== - - class be.bastelstu.chat.nodePush - -Methods -------- -**constructor()** - - constructor: -> - log 'Starting Pushserver for Tims Chat' - log "PID is #{process.pid}" - log "Using port: #{config.port}" - - @initUnixSocket() - @initSocketIO() - -Bind shutdown function to needed events. - - process.on 'exit', @shutdown.bind @ - process.on 'uncaughtException', @shutdown.bind @ - process.on 'SIGINT', @shutdown.bind @ - process.on 'SIGTERM', @shutdown.bind @ - -Set nice title for PS. - - process.title = 'nodePush - Tims Chat' - -Set newMessage event once a minute to allow for easier timeout detection in chat. - - setInterval => - @socket.sockets.emit 'newMessage' - , 60e3 - -**initSocketIO()** -Initialize socket server. - - initSocketIO: -> - log 'Initializing socket.io' - @socket = io.listen config.port - - @socket.set 'log level', 1 - @socket.set 'browser client etag', true - @socket.set 'browser client minification', true - @socket.set 'browser client gzip', true - - @socket.configure 'development', => - @socket.set 'log level', 3 - @socket.set 'browser client etag', false - @socket.set 'browser client minification', false - -**initUnixSocket()** -Initialize PHP side unix socket. - - initUnixSocket: -> - log 'Initializing Unix-Socket' - socket = net.createServer (c) => - setTimeout => - @socket.sockets.emit 'newMessage' - , 20 - - c.end() - - socket.listen "#{__dirname}/../data.sock" - fs.chmod "#{__dirname}/../data.sock", '777' - -**shutdown()** -Perform clean shutdown of nodePush. - - shutdown: -> - return unless fs.existsSync "#{__dirname}/../data.sock" - - log 'Shutting down' - fs.unlinkSync "#{__dirname}/../data.sock" - process.exit() - -And finally start the service. - - new be.bastelstu.chat.nodePush() \ No newline at end of file diff --git a/file/acp/be.bastelstu.chat.nodePush/package.json b/file/acp/be.bastelstu.chat.nodePush/package.json deleted file mode 100644 index c778ac2..0000000 --- a/file/acp/be.bastelstu.chat.nodePush/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name" : "be.bastelstu.chat.nodePush", - "description" : "node.js-Pushing for Tims Chat", - "homepage" : "https://github.com/wbbaddons/Tims-Chat", - "keywords" : ["chat"], - "author" : "Tim Düsterhus ", - "contributors" : [ - ], - "dependencies" : { - "socket.io" : "0.8.7" - }, - "engines" : { "node" : ">=0.6.0", - "npm" : ">=1.0" - }, - "version" : "3.0.0" -} diff --git a/file/js/be.bastelstu.Chat.litcoffee b/file/js/be.bastelstu.Chat.litcoffee index dbd0f7e..da04385 100644 --- a/file/js/be.bastelstu.Chat.litcoffee +++ b/file/js/be.bastelstu.Chat.litcoffee @@ -560,26 +560,26 @@ Remove all users that left the chat. Initialize socket.io to enable nodePush. initPush: -> - if window.io? - console.log 'Initializing nodePush' - @socket = io.connect @config.socketIOPath - - @socket.on 'connect', => - console.log 'Connected to nodePush' + be.bastelstu.wcf.nodePush.onConnect => + console.log 'Disabling periodic loading' Disable `@pe.getMessages` once we are connected. @pe.getMessages.stop() - @socket.on 'disconnect', => - console.log 'Lost connection to nodePush' + be.bastelstu.wcf.nodePush.onDisconnect => + console.log 'Enabling periodic loading' Reenable `@pe.getMessages` once we are disconnected. @pe.getMessages = new WCF.PeriodicalExecuter $.proxy(@getMessages, @), @config.reloadTime * 1e3 - @socket.on 'newMessage', => + be.bastelstu.wcf.nodePush.onMessage 'be.bastelstu.chat.newMessage', => @getMessages() + + be.bastelstu.wcf.nodePush.onMessage 'tick60', => + @getMessages() + **insertText(text, options)** Inserts the given `text` into the input. If `options.append` is truthy the given `text` will be appended and replaces the existing text otherwise. If `options.submit` is truthy the message will be submitted afterwards. diff --git a/file/lib/data/message/MessageEditor.class.php b/file/lib/data/message/MessageEditor.class.php index 7fae0cf..6403409 100644 --- a/file/lib/data/message/MessageEditor.class.php +++ b/file/lib/data/message/MessageEditor.class.php @@ -20,13 +20,7 @@ class MessageEditor extends \wcf\data\DatabaseObjectEditor { * Notify the Push-Server. */ public static function create(array $parameters = array()) { - try { - if (\chat\util\ChatUtil::nodePushRunning()) { - $sock = stream_socket_client('unix://'.CHAT_DIR.'acp/be.bastelstu.chat.nodePush/data.sock', $errno, $errstr, 1); - fclose($sock); - } - } - catch (\Exception $e) { } + \wcf\system\nodePush\NodePushHandler::getInstance()->sendMessage('be.bastelstu.chat.newMessage'); return parent::create($parameters); } diff --git a/file/lib/data/room/Room.class.php b/file/lib/data/room/Room.class.php index f187b41..1edbb00 100644 --- a/file/lib/data/room/Room.class.php +++ b/file/lib/data/room/Room.class.php @@ -167,7 +167,7 @@ public function getUsers() { * @return \wcf\data\user\UserList */ public static function getDeadUsers() { - if (\chat\util\ChatUtil::nodePushRunning()) { + if (\wcf\system\nodePush\NodePushHandler::getInstance()->isRunning()) { $time = TIME_NOW - 120; } else { diff --git a/file/lib/util/ChatUtil.class.php b/file/lib/util/ChatUtil.class.php index 03d6dfa..243f346 100644 --- a/file/lib/util/ChatUtil.class.php +++ b/file/lib/util/ChatUtil.class.php @@ -95,19 +95,6 @@ public static function gradient($string, $start, $end) { return $result; } - /** - * Checks whether nodePush is running. - * - * @return boolean - */ - public static function nodePushRunning() { - if (!CHAT_SOCKET_IO_PATH) return false; - if (!file_exists(CHAT_DIR.'acp/be.bastelstu.chat.nodePush/data.sock')) return false; - if (!is_writable(CHAT_DIR.'acp/be.bastelstu.chat.nodePush/data.sock')) return false; - - return true; - } - /** * Reads user data. * diff --git a/package.xml b/package.xml index c1a3757..2ea26d5 100644 --- a/package.xml +++ b/package.xml @@ -17,6 +17,7 @@ com.woltlab.wcf be.bastelstu.max.wcf.jCounter + be.bastelstu.wcf.nodePush com.woltlab.wcf.bbcode com.woltlab.wcf.message com.woltlab.wcf.user diff --git a/template/chat.tpl b/template/chat.tpl index 1d0aa31..63d5c15 100644 --- a/template/chat.tpl +++ b/template/chat.tpl @@ -29,9 +29,7 @@ window.chat = new be.bastelstu.Chat( { reloadTime: {@CHAT_RELOADTIME}, - unloadURL: '{link application="chat" controller="Leave"}{/link}', - messageURL: '{link application="chat" controller="NewMessages"}{/link}', - socketIOPath: '{@CHAT_SOCKET_IO_PATH|encodeJS}' + messageURL: '{link application="chat" controller="NewMessages"}{/link}' }, new WCF.Template('{ldelim}$title} - {"chat.general.title"|language|encodeJS} - {PAGE_TITLE|language|encodeJS}'), new WCF.Template('{@$messageTemplate|encodeJS}'), diff --git a/template/javascriptInclude.tpl b/template/javascriptInclude.tpl index 4177af0..f19054d 100644 --- a/template/javascriptInclude.tpl +++ b/template/javascriptInclude.tpl @@ -1,4 +1,3 @@ -{if CHAT_SOCKET_IO_PATH}{/if} {event name='javascript'} \ No newline at end of file