1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-22 21:40:08 +00:00

Use new nodePush package

This commit is contained in:
Tim Düsterhus 2013-04-29 16:56:20 +02:00
parent bd649d50a6
commit 037e35ba0d
15 changed files with 17 additions and 197 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env php
<?php
namespace be\bastelstu\wcf\chat;
namespace be\bastelstu\chat;
/**
* Builds the Chat
*
@ -37,12 +37,12 @@
EOT;
foreach (glob('file/js/*.{litcoffee,coffee}', GLOB_BRACE) as $coffeeFile) {
echo $coffeeFile."\n";
passthru('coffee -cb '.escapeshellarg($coffeeFile), $code);
passthru('coffee -c '.escapeshellarg($coffeeFile), $code);
if ($code != 0) exit($code);
}
foreach (glob('file/acp/be.bastelstu.chat.nodePush/lib/*.{litcoffee,coffee}', GLOB_BRACE) as $coffeeFile) {
echo $coffeeFile."\n";
passthru('coffee -cb '.escapeshellarg($coffeeFile), $code);
passthru('coffee -c '.escapeshellarg($coffeeFile), $code);
if ($code != 0) exit($code);
}
echo <<<EOT
@ -74,7 +74,7 @@
-----------------
EOT;
passthru('tar cvf ../file.tar * --exclude=*.coffee --exclude=*.scss --exclude=.sass-cache --exclude=node_modules', $code);
passthru('tar cvf ../file.tar * --exclude=*coffee --exclude=*.scss --exclude=.sass-cache --exclude=node_modules', $code);
if ($code != 0) exit($code);
echo <<<EOT

View File

@ -1 +0,0 @@
node_modules

View File

@ -1 +0,0 @@
deny from all

View File

@ -1,6 +0,0 @@
node.js-Push for Tims Chat
==========================
This directory contains files for the node.js-Server that provides Push-Messages for Tims Chat.
DO NOT DELETE THIS DIRECTORY!

View File

@ -1,18 +0,0 @@
#!/bin/sh
cd `dirname $0`
if [ -d "bin" ]; then
cd "../"
fi
if [ "$(id -u)" -eq 0 ]; then
echo "You may not start nodePush as root!"
exit 1
fi
echo "Installing dependencies"
/usr/bin/env npm install
cd "../lib"
/usr/bin/env node server.js

View File

@ -1,3 +0,0 @@
module.exports = {
port: 9001
}

View File

@ -1,114 +0,0 @@
nodePush Pushserver for Tims Chat
=================================
Copyright Information
---------------------
"@author Tim Düsterhus"
"@copyright 2010-2013 Tim Düsterhus"
"@license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>"
"@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()

View File

@ -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 <timwolla@bastelstu.be>",
"contributors" : [
],
"dependencies" : {
"socket.io" : "0.8.7"
},
"engines" : { "node" : ">=0.6.0",
"npm" : ">=1.0"
},
"version" : "3.0.0"
}

View File

@ -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.

View File

@ -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);
}

View File

@ -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 {

View File

@ -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.
*

View File

@ -17,6 +17,7 @@
<requiredpackages>
<requiredpackage minversion="2.0.0 Alpha 1">com.woltlab.wcf</requiredpackage>
<requiredpackage file="requirements/be.bastelstu.max.wcf.jCounter.tar">be.bastelstu.max.wcf.jCounter</requiredpackage>
<requiredpackage file="requirements/be.bastelstu.wcf.nodePush.tar">be.bastelstu.wcf.nodePush</requiredpackage>
<requiredpackage file="requirements/com.woltlab.wcf.bbcode.tar">com.woltlab.wcf.bbcode</requiredpackage>
<requiredpackage file="requirements/com.woltlab.wcf.message.tar">com.woltlab.wcf.message</requiredpackage>
<requiredpackage file="requirements/com.woltlab.wcf.user.tar">com.woltlab.wcf.user</requiredpackage>

View File

@ -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}'),

View File

@ -1,4 +1,3 @@
<script type="text/javascript" src="{$__wcf->getPath('chat')}js/be.bastelstu.Chat.js?version={PACKAGE_VERSION|rawurlencode}"></script>
{if CHAT_SOCKET_IO_PATH}<script type="text/javascript" src="{CHAT_SOCKET_IO_PATH}/socket.io/socket.io.js"></script>{/if}
<script type="text/javascript" src="{$__wcf->getPath('chat')}js/be.bastelstu.Chat.Log.js?version={PACKAGE_VERSION|rawurlencode}"></script>
{event name='javascript'}