1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-10-31 14:10:08 +00:00

Merge branch 'nodePush'

This commit is contained in:
Tim Düsterhus 2012-04-27 19:33:44 +02:00
commit 9529347589
13 changed files with 178 additions and 20 deletions

View File

@ -25,6 +25,7 @@
if (file_exists('file.tar')) unlink('file.tar');
if (file_exists('template.tar')) unlink('template.tar');
if (file_exists('acptemplate.tar')) unlink('acptemplate.tar');
foreach (glob('file/acp/be.bastelstu.wcf.chat.serverPush/lib/*.js') as $nodeFile) unlink($nodeFile);
foreach (glob('file/js/*.js') as $jsFile) unlink($jsFile);
foreach (glob('file/style/*.css') as $cssFile) unlink($cssFile);
if (file_exists('be.bastelstu.wcf.chat.tar')) unlink('be.bastelstu.wcf.chat.tar');
@ -39,6 +40,11 @@
passthru('coffee -cb '.escapeshellarg($coffeeFile), $code);
if ($code != 0) exit($code);
}
foreach (glob('file/acp/be.bastelstu.wcf.chat.serverPush/lib/*.coffee') as $coffeeFile) {
echo $coffeeFile."\n";
passthru('coffee -cb '.escapeshellarg($coffeeFile), $code);
if ($code != 0) exit($code);
}
echo <<<EOT
Building CSS
@ -79,7 +85,7 @@
-----------------
EOT;
passthru('tar cvf ../file.tar * --exclude=*.coffee --exclude=*.scss --exclude=.sass-cache', $code);
passthru('tar cvf ../file.tar * --exclude=*.coffee --exclude=*.scss --exclude=.sass-cache --exclude=node_modules', $code);
if ($code != 0) exit($code);
echo <<<EOT
@ -118,5 +124,6 @@
if (file_exists('file.tar')) unlink('file.tar');
if (file_exists('template.tar')) unlink('template.tar');
if (file_exists('acptemplate.tar')) unlink('acptemplate.tar');
foreach (glob('file/acp/be.bastelstu.wcf.chat.serverPush/lib/*.js') as $nodeFile) unlink($nodeFile);
foreach (glob('file/js/*.js') as $jsFile) unlink($jsFile);
foreach (glob('file/style/*.css') as $cssFile) unlink($cssFile);

View File

@ -0,0 +1 @@
node_modules

View File

@ -0,0 +1,6 @@
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

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

View File

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

View File

@ -0,0 +1,49 @@
###
# node.js Pushserver for Tims Chat.
#
# @author Tim Düsterhus
# @copyright 2010-2012 Tim Düsterhus
# @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
# @package be.bastelstu.wcf.chat
###
process.title = 'Tims Chat Pushserver'
io = require 'socket.io'
net = require 'net'
config = require('../config.js').config
log = (message) ->
console.log '[be.bastelstu.wcf.chat.serverPush] '+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
@socket.set 'browser client etag', true
@socket.set 'browser client minification', true
@socket.set 'browser client gzig', true
@socket.configure 'development', (() ->
@socket.set 'log level', 3
@socket.set 'browser client etag', false
@socket.set 'browser client minification', false
).bind(@)
initUnixSocket: () ->
log 'Initializing Unix-Socket'
socket = net.createServer ((c) ->
@socket.sockets.emit 'newMessage'
c.end()
).bind(@)
socket.listen process.cwd() + '/../data.sock'
new Server()

View File

@ -0,0 +1,19 @@
{
"name" : "be.bastelstu.wcf.chat.serverPush",
"description" : "Server-Pushing for Tims Chat",
"homepage" : "https://github.com/wbbaddons/Tims-Chat",
"keywords" : ["chat"],
"author" : "Tim Düsterhus <timwolla@googlemail.com>",
"contributors" : [
],
"dependencies" : {
"socket.io" : "0.8.7"
},
"devDependencies": {
"jshint" : "*"
},
"engines" : { "node" : ">=0.6.0",
"npm" : ">=1.0"
},
"version" : "1.0.0"
}

View File

@ -7,16 +7,24 @@
# @package be.bastelstu.wcf.chat
###
window.consoleMock = console
window.consoleMock ?=
window.console ?=
log: () ->,
warn: () ->,
error: () ->
(($, window, console) ->
(($, window, windowConsole) ->
window.be ?= {}
be.bastelstu ?= {}
be.bastelstu.WCF ?= {}
console =
log: (message) ->
windowConsole.log '[be.bastelstu.WCF.Chat] '+message
warn: (message) ->
windowConsole.warn '[be.bastelstu.WCF.Chat] '+message
error: (message) ->
windowConsole.error '[be.bastelstu.WCF.Chat] '+message
be.bastelstu.WCF.Chat =
# Tims Chat stops loading when this reaches zero
# TODO: We need an explosion animation
@ -44,12 +52,16 @@ window.consoleMock ?=
events:
newMessage: $.Callbacks()
userMenu: $.Callbacks()
# socket.io
socket: null
pe:
getMessages: null
refreshRoomList: null
fish: null
init: () ->
console.log '[be.bastelstu.WCF.Chat] Initializing'
console.log 'Initializing'
@bindEvents()
@events.newMessage.add $.proxy @notify, @
@ -57,8 +69,9 @@ window.consoleMock ?=
@pe.getMessages = new WCF.PeriodicalExecuter $.proxy(@getMessages, @), @config.reloadTime * 1e3
@refreshRoomList()
@getMessages()
@initPush()
console.log '[be.bastelstu.WCF.Chat] Finished initializing - Shields at 104 percent'
console.log 'Finished initializing - Shields at 104 percent'
###
# Autocompletes a username
###
@ -124,7 +137,7 @@ window.consoleMock ?=
firstChars = @autocompleteValue.substring(@autocompleteValue.lastIndexOf(' ')+1)
console.log '[be.bastelstu.WCF.Chat] Autocompleting "' + firstChars + '"'
console.log 'Autocompleting "' + firstChars + '"'
return if firstChars.length is 0
# Insert name and increment offset
@ -221,7 +234,7 @@ window.consoleMock ?=
###
freeTheFish: () ->
return if $.wcfIsset 'fish'
console.warn '[be.bastelstu.WCF.Chat] Freeing the fish'
console.warn 'Freeing the fish'
fish = $ '<div id="fish">' + WCF.String.escapeHTML('><((((\u00B0>') + '</div>'
fish.css
position: 'absolute'
@ -261,12 +274,12 @@ window.consoleMock ?=
@handleUsers(data.users)
, @)
error: $.proxy((jqXHR, textStatus, errorThrown) ->
console.error '[be.bastelstu.WCF.Chat] Battle Station hit - shields at ' + (--@shields / 3 * 104) + ' percent'
console.error 'Battle Station hit - shields at ' + (--@shields / 3 * 104) + ' percent'
if @shields is 0
@pe.refreshRoomList.stop()
@pe.getMessages.stop()
@freeTheFish()
console.error '[be.bastelstu.WCF.Chat] We got destroyed, but could free our friend the fish before he was killed as well. Have a nice life in freedom!'
console.error 'We got destroyed, but could free our friend the fish before he was killed as well. Have a nice life in freedom!'
alert 'herp i cannot load messages'
, @)
beforeSend: $.proxy(() ->
@ -318,7 +331,7 @@ window.consoleMock ?=
# Move the user to the correct position
if element[0]
console.log '[be.bastelstu.WCF.Chat] Moving User: "' + user.username + '"'
console.log 'Moving User: "' + user.username + '"'
element = element.detach()
if user.awayStatus?
element.addClass 'timsChatAway'
@ -330,7 +343,7 @@ window.consoleMock ?=
$('#timsChatUserList').append element
# Insert the user
else
console.log '[be.bastelstu.WCF.Chat] Inserting User: "' + user.username + '"'
console.log 'Inserting User: "' + user.username + '"'
li = $ '<li></li>'
li.attr 'id', id
li.addClass 'timsChatUser'
@ -360,12 +373,30 @@ window.consoleMock ?=
# Remove users that were not found
$('.timsChatUser').each () ->
if typeof foundUsers[$(@).attr('id')] is 'undefined'
console.log '[be.bastelstu.WCF.Chat] Removing User: "' + $(@).data('username') + '"'
console.log 'Removing User: "' + $(@).data('username') + '"'
$(@).remove();
$('#toggleUsers .badge').text(users.length);
###
# Initializes Server-Push
###
initPush: () ->
if typeof window.io isnt 'undefined'
console.log 'Initializing socket.io'
@socket = io.connect @config.socketIOPath
@socket.on 'connect', $.proxy((data) ->
console.log 'Connected on socket.io'
@pe.getMessages.stop()
, @)
@socket.on 'disconnect', $.proxy((data) ->
console.log 'Losing connection to socket.io'
@pe.getMessages = new WCF.PeriodicalExecuter $.proxy(@getMessages, @), @config.reloadTime * 1e3
, @)
@socket.on 'newMessage', $.proxy((data) ->
@getMessages()
, @)
###
# Inserts text into our input.
#
# @param string text
@ -412,7 +443,7 @@ window.consoleMock ?=
# Refreshes the room-list.
###
refreshRoomList: () ->
console.log '[be.bastelstu.WCF.Chat] Refreshing the roomlist'
console.log 'Refreshing the roomlist'
$('#toggleRooms a').addClass 'ajaxLoad'
$.ajax $('#toggleRooms a').data('refreshUrl'),
@ -435,7 +466,7 @@ window.consoleMock ?=
@changeRoom $ event.target
, @
console.log '[be.bastelstu.WCF.Chat] Found ' + data.length + ' rooms'
console.log 'Found ' + data.length + ' rooms'
, @)
###
# Handles submitting of messages.
@ -504,4 +535,4 @@ window.consoleMock ?=
$.ajax @config.unloadURL,
type: 'POST'
async: false
)(jQuery, @, consoleMock)
)(jQuery, @, console)

View File

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

View File

@ -61,6 +61,12 @@
<defaultvalue>1</defaultvalue>
<showorder>9</showorder>
</option>
<option name="chat_socket_io_path">
<categoryname>chat.general</categoryname>
<optiontype>text</optiontype>
<defaultvalue><![CDATA[]]></defaultvalue>
<showorder>10</showorder>
</option>
<!-- general chat options end -->
<!--log options-->

View File

@ -5,7 +5,7 @@
<packagedescription><![CDATA[Chat for WoltLab Community Framework™]]></packagedescription>
<standalone>0</standalone>
<isunique>1</isunique>
<version>3.0.0 Alpha 12</version>
<version>3.0.0 Alpha 13</version>
<date>2011-11-26</date>
<plugin>com.woltlab.wcf.message</plugin> <!-- TODO: Correct me -->
</packageinformation>

View File

@ -126,7 +126,8 @@
// populate config
be.bastelstu.WCF.Chat.config = {
reloadTime: {@CHAT_RELOADTIME},
unloadURL: '{link controller='Chat' action='Leave'}{/link}'
unloadURL: '{link controller='Chat' action='Leave'}{/link}',
socketIOPath: '{@CHAT_SOCKET_IO_PATH|encodeJS}'
}
WCF.Language.addObject({
'wcf.chat.query': '{lang}wcf.chat.query{/lang}',
@ -155,7 +156,7 @@
$('#timsChatCopyright').click(function (event) {
event.preventDefault();
if ($.wcfIsset('timsChatCopyrightDialog')) return WCF.showDialog('timsChatCopyrightDialog', { title: 'Tims Chat{if CHAT_SHOW_VERSION} {$chatVersion}{/if}' });
var container = $('<fieldset id="timsChatCopyrightDialog"></fieldset>');
var container = $('<div id="timsChatCopyrightDialog"></div>');
container.load('{link controller='Chat' action='Copyright'}{/link}', function() {
$('body').append(container);
WCF.showDialog('timsChatCopyrightDialog', { title: 'Tims Chat{if CHAT_SHOW_VERSION} {$chatVersion}{/if}' });

View File

@ -1,2 +1,3 @@
<script type="text/javascript" src="{@$__wcf->getPath('wcf')}js/be.bastelstu.WCF.Chat.js{if $chatVersion|isset}?version={$chatVersion|urlencode}{/if}"></script>
<script type="text/javascript" src="{@$__wcf->getPath('wcf')}js/jCounter.jQuery.js"></script>
{if CHAT_SOCKET_IO_PATH}<script type="text/javascript" src="{CHAT_SOCKET_IO_PATH}/socket.io/socket.io.js"></script>{/if}