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

Adding node.js Pushing

This commit is contained in:
Tim Düsterhus 2012-04-27 15:42:44 +02:00
parent 5cde0d1b90
commit f5d9044d4b
10 changed files with 137 additions and 19 deletions

View File

@ -25,6 +25,7 @@
if (file_exists('file.tar')) unlink('file.tar'); if (file_exists('file.tar')) unlink('file.tar');
if (file_exists('template.tar')) unlink('template.tar'); if (file_exists('template.tar')) unlink('template.tar');
if (file_exists('acptemplate.tar')) unlink('acptemplate.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/js/*.js') as $jsFile) unlink($jsFile);
foreach (glob('file/style/*.css') as $cssFile) unlink($cssFile); foreach (glob('file/style/*.css') as $cssFile) unlink($cssFile);
if (file_exists('be.bastelstu.wcf.chat.tar')) unlink('be.bastelstu.wcf.chat.tar'); if (file_exists('be.bastelstu.wcf.chat.tar')) unlink('be.bastelstu.wcf.chat.tar');
@ -39,6 +40,11 @@
passthru('coffee -cb '.escapeshellarg($coffeeFile), $code); passthru('coffee -cb '.escapeshellarg($coffeeFile), $code);
if ($code != 0) exit($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 echo <<<EOT
Building CSS Building CSS
@ -79,7 +85,7 @@
----------------- -----------------
EOT; 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); if ($code != 0) exit($code);
echo <<<EOT echo <<<EOT
@ -118,5 +124,6 @@
if (file_exists('file.tar')) unlink('file.tar'); if (file_exists('file.tar')) unlink('file.tar');
if (file_exists('template.tar')) unlink('template.tar'); if (file_exists('template.tar')) unlink('template.tar');
if (file_exists('acptemplate.tar')) unlink('acptemplate.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/js/*.js') as $jsFile) unlink($jsFile);
foreach (glob('file/style/*.css') as $cssFile) unlink($cssFile); 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,28 @@
###
# 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
###
io = require 'socket.io'
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 'Using port: ' + config.port
@socket = io.listen config.port
setInterval((() ->
@socket.sockets.emit 'newMessage'
).bind(@), 5000)
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 # @package be.bastelstu.wcf.chat
### ###
window.consoleMock = console window.console ?=
window.consoleMock ?=
log: () ->, log: () ->,
warn: () ->, warn: () ->,
error: () -> error: () ->
(($, window, console) -> (($, window, windowConsole) ->
window.be ?= {} window.be ?= {}
be.bastelstu ?= {} be.bastelstu ?= {}
be.bastelstu.WCF ?= {} 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 = be.bastelstu.WCF.Chat =
# Tims Chat stops loading when this reaches zero # Tims Chat stops loading when this reaches zero
# TODO: We need an explosion animation # TODO: We need an explosion animation
@ -44,12 +52,16 @@ window.consoleMock ?=
events: events:
newMessage: $.Callbacks() newMessage: $.Callbacks()
userMenu: $.Callbacks() userMenu: $.Callbacks()
# socket.io
socket: null
pe: pe:
getMessages: null getMessages: null
refreshRoomList: null refreshRoomList: null
fish: null fish: null
init: () -> init: () ->
console.log '[be.bastelstu.WCF.Chat] Initializing' console.log 'Initializing'
@bindEvents() @bindEvents()
@events.newMessage.add $.proxy @notify, @ @events.newMessage.add $.proxy @notify, @
@ -57,8 +69,9 @@ window.consoleMock ?=
@pe.getMessages = new WCF.PeriodicalExecuter $.proxy(@getMessages, @), @config.reloadTime * 1e3 @pe.getMessages = new WCF.PeriodicalExecuter $.proxy(@getMessages, @), @config.reloadTime * 1e3
@refreshRoomList() @refreshRoomList()
@getMessages() @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 # Autocompletes a username
### ###
@ -124,7 +137,7 @@ window.consoleMock ?=
firstChars = @autocompleteValue.substring(@autocompleteValue.lastIndexOf(' ')+1) firstChars = @autocompleteValue.substring(@autocompleteValue.lastIndexOf(' ')+1)
console.log '[be.bastelstu.WCF.Chat] Autocompleting "' + firstChars + '"' console.log 'Autocompleting "' + firstChars + '"'
return if firstChars.length is 0 return if firstChars.length is 0
# Insert name and increment offset # Insert name and increment offset
@ -221,7 +234,7 @@ window.consoleMock ?=
### ###
freeTheFish: () -> freeTheFish: () ->
return if $.wcfIsset 'fish' 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 = $ '<div id="fish">' + WCF.String.escapeHTML('><((((\u00B0>') + '</div>'
fish.css fish.css
position: 'absolute' position: 'absolute'
@ -261,12 +274,12 @@ window.consoleMock ?=
@handleUsers(data.users) @handleUsers(data.users)
, @) , @)
error: $.proxy((jqXHR, textStatus, errorThrown) -> 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 if @shields is 0
@pe.refreshRoomList.stop() @pe.refreshRoomList.stop()
@pe.getMessages.stop() @pe.getMessages.stop()
@freeTheFish() @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' alert 'herp i cannot load messages'
, @) , @)
beforeSend: $.proxy(() -> beforeSend: $.proxy(() ->
@ -318,7 +331,7 @@ window.consoleMock ?=
# Move the user to the correct position # Move the user to the correct position
if element[0] if element[0]
console.log '[be.bastelstu.WCF.Chat] Moving User: "' + user.username + '"' console.log 'Moving User: "' + user.username + '"'
element = element.detach() element = element.detach()
if user.awayStatus? if user.awayStatus?
element.addClass 'timsChatAway' element.addClass 'timsChatAway'
@ -330,7 +343,7 @@ window.consoleMock ?=
$('#timsChatUserList').append element $('#timsChatUserList').append element
# Insert the user # Insert the user
else else
console.log '[be.bastelstu.WCF.Chat] Inserting User: "' + user.username + '"' console.log 'Inserting User: "' + user.username + '"'
li = $ '<li></li>' li = $ '<li></li>'
li.attr 'id', id li.attr 'id', id
li.addClass 'timsChatUser' li.addClass 'timsChatUser'
@ -360,12 +373,30 @@ window.consoleMock ?=
# Remove users that were not found # Remove users that were not found
$('.timsChatUser').each () -> $('.timsChatUser').each () ->
if typeof foundUsers[$(@).attr('id')] is 'undefined' if typeof foundUsers[$(@).attr('id')] is 'undefined'
console.log '[be.bastelstu.WCF.Chat] Removing User: "' + $(@).data('username') + '"' console.log 'Removing User: "' + $(@).data('username') + '"'
$(@).remove(); $(@).remove();
$('#toggleUsers .badge').text(users.length); $('#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. # Inserts text into our input.
# #
# @param string text # @param string text
@ -412,7 +443,7 @@ window.consoleMock ?=
# Refreshes the room-list. # Refreshes the room-list.
### ###
refreshRoomList: () -> refreshRoomList: () ->
console.log '[be.bastelstu.WCF.Chat] Refreshing the roomlist' console.log 'Refreshing the roomlist'
$('#toggleRooms a').addClass 'ajaxLoad' $('#toggleRooms a').addClass 'ajaxLoad'
$.ajax $('#toggleRooms a').data('refreshUrl'), $.ajax $('#toggleRooms a').data('refreshUrl'),
@ -435,7 +466,7 @@ window.consoleMock ?=
@changeRoom $ event.target @changeRoom $ event.target
, @ , @
console.log '[be.bastelstu.WCF.Chat] Found ' + data.length + ' rooms' console.log 'Found ' + data.length + ' rooms'
, @) , @)
### ###
# Handles submitting of messages. # Handles submitting of messages.
@ -504,4 +535,4 @@ window.consoleMock ?=
$.ajax @config.unloadURL, $.ajax @config.unloadURL,
type: 'POST' type: 'POST'
async: false async: false
)(jQuery, @, consoleMock) )(jQuery, @, console)

View File

@ -61,6 +61,12 @@
<defaultvalue>1</defaultvalue> <defaultvalue>1</defaultvalue>
<showorder>9</showorder> <showorder>9</showorder>
</option> </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 --> <!-- general chat options end -->
<!--log options--> <!--log options-->

View File

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

View File

@ -115,6 +115,7 @@
{include file='chatCopyright'} {include file='chatCopyright'}
</div> </div>
{include file='chatJavascriptInclude'} {include file='chatJavascriptInclude'}
{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"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[
(function ($, window) { (function ($, window) {
@ -126,7 +127,8 @@
// populate config // populate config
be.bastelstu.WCF.Chat.config = { be.bastelstu.WCF.Chat.config = {
reloadTime: {@CHAT_RELOADTIME}, 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.Language.addObject({
'wcf.chat.query': '{lang}wcf.chat.query{/lang}', 'wcf.chat.query': '{lang}wcf.chat.query{/lang}',
@ -155,7 +157,7 @@
$('#timsChatCopyright').click(function (event) { $('#timsChatCopyright').click(function (event) {
event.preventDefault(); event.preventDefault();
if ($.wcfIsset('timsChatCopyrightDialog')) return WCF.showDialog('timsChatCopyrightDialog', { title: 'Tims Chat{if CHAT_SHOW_VERSION} {$chatVersion}{/if}' }); 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() { container.load('{link controller='Chat' action='Copyright'}{/link}', function() {
$('body').append(container); $('body').append(container);
WCF.showDialog('timsChatCopyrightDialog', { title: 'Tims Chat{if CHAT_SHOW_VERSION} {$chatVersion}{/if}' }); WCF.showDialog('timsChatCopyrightDialog', { title: 'Tims Chat{if CHAT_SHOW_VERSION} {$chatVersion}{/if}' });