Skip to content

Commit

Permalink
Client-Server update
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrxtchy committed Nov 12, 2018
1 parent ef0e0a2 commit 4c2558a
Show file tree
Hide file tree
Showing 10 changed files with 258 additions and 160 deletions.
2 changes: 1 addition & 1 deletion websocket.html → Web-Overlay/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</head>
<body>
<div id='content'>
<span class="channelName">Channel Name</span>
<span class="channelName">Not Connected</span>
<div id='userlist'>
</div>
</div>
Expand Down
9 changes: 7 additions & 2 deletions socket.js → Web-Overlay/socket.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
websocket = new WebSocket('ws://localhost:8000/');

startsocket()
function startsocket(){
websocket = new WebSocket('ws://localhost:58008/ws');
websocket.onopen = function(evt) { onOpen(evt) };
websocket.onclose = function(evt) { onClose(evt) };
websocket.onmessage = function(evt) { onMessage(evt) };
Expand All @@ -12,6 +15,7 @@
function onClose(evt)
{
console.log("disconnected from WebSocket");
setTimeout(startsocket, 1000 * 3)
}

function onMessage(evt)
Expand All @@ -28,4 +32,5 @@
function doSend(message)
{
console.log(message);
}
}
}
File renamed without changes.
18 changes: 6 additions & 12 deletions ts3.js → Web-Overlay/ts3.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,14 @@ CLIENT_MOVE = {
LEFT: 1
}

AVATAR_CODE = {
ERROR: 0,
PATH: 1
}

function parseAvatarPath(argument) {
if(argument[AVATAR_CODE.ERROR] != 0 || argument[AVATAR_CODE.PATH] == ""){
if (argument == ""){
avatars = ['https://discordapp.com/assets/322c936a8c8be1b803cd94861bdfa868.png','https://discordapp.com/assets/6debd47ed13483642cf09e832ed0bc1b.png','https://discordapp.com/assets/0e291f67c9274a1abdddeb3fd919cbaa.png','https://discordapp.com/assets/dd4dbc0016779df1378e7812eabaa04d.png','https://discordapp.com/assets/1cbd08c76f8af6dddce02c5138971129.png']
return avatars[Math.floor(Math.random()*avatars.length)];
} else {
return 'file:///' + argument[AVATAR_CODE.PATH].replace(/\\/g,'/');
//return 'file:///' + argument[AVATAR_CODE.PATH].replace(/\\/g,'/');
return 'http://localhost:58008/'+argument;
}


}

function createClientDiv(argument) {
Expand Down Expand Up @@ -78,10 +72,10 @@ function nearbyClientMoveEvent(data){

switch(data.status){
case CLIENT_MOVE.JOINED:
document.getElementById('userlist').appendChild(createClientDiv(data.client))
document.getElementById('userlist').appendChild(createClientDiv(data.client));
break;
case CLIENT_MOVE.LEFT:
var user = document.getElementById('client_' + data.client[CLIENTINFO.CLIENT_ID]).remove()
var user = document.getElementById('client_' + data.client[CLIENTINFO.CLIENT_ID]).remove();
break;
}
}
Expand All @@ -95,7 +89,7 @@ function onClientMoveEvent(data){
}

function onClientDisplayNameChanged(argument){
document.getElementById('client_' + argument.client[CLIENTINFO.CLIENT_ID]).childNodes[1].innerText = argument.client[CLIENTINFO.CLIENT_NAME]
document.getElementById('client_' + argument.client[CLIENTINFO.CLIENT_ID]).childNodes[1].innerText = argument.client[CLIENTINFO.CLIENT_NAME];
}

function handleMessage(data){
Expand Down
178 changes: 178 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@

from ts3plugin import ts3plugin
import ts3lib, ts3defines, json, subprocess
try:
from websocket import create_connection
except ImportError:
ts3lib.printMessageToCurrentTab("Installing websocket-client")
from devtools import PluginInstaller
try:
PluginInstaller.installPackages(PluginInstaller, ['websocket-client'])
except TypeError as e:
pass
from websocket import create_connection
from os import path
from os import name as osName

class tshelp:
@staticmethod
def getChannelName(serverConnectionHandlerID, channelID):
return ts3lib.getChannelVariableAsString(serverConnectionHandlerID, channelID, ts3defines.ChannelProperties.CHANNEL_NAME)[1]

@staticmethod
def getChannelID(serverConnectionHandlerID):
return ts3lib.getChannelOfClient(serverConnectionHandlerID, ts3lib.getClientID(serverConnectionHandlerID)[1])[1]

@staticmethod
def getNearbyClients(serverConnectionHandlerID):
users = ts3lib.getChannelClientList(serverConnectionHandlerID, tshelp.getChannelID(serverConnectionHandlerID))[1]
userDetailed = []
for user in users:
userDetailed.append([user, ts3lib.getClientDisplayName(serverConnectionHandlerID, user)[1], tshelp.getAvatar(serverConnectionHandlerID, user)])
return userDetailed

@staticmethod
def getClientInfo(serverConnectionHandlerID, clientID):
return [clientID, ts3lib.getClientDisplayName(serverConnectionHandlerID, clientID)[1], tshelp.getAvatar(serverConnectionHandlerID, clientID)]

@staticmethod
def getServerName(serverConnectionHandlerID):
return ts3lib.getServerVariableAsString(serverConnectionHandlerID, ts3defines.VirtualServerProperties.VIRTUALSERVER_NAME)[1]

@staticmethod
def getAvatar(serverConnectionHandlerID, clientID):
avatar = ts3lib.getAvatar(serverConnectionHandlerID, clientID)
if avatar[0] != 0:
return ""
else:
return path.relpath(avatar[1], ts3lib.getConfigPath())

class ClientInfo(object):
"""docstring for ClientInfo"""
CLIENT_ID = 0
CLIENT_NAME = 1
CLIENT_AVATAR = 2

class socketplugin(ts3plugin):
"""docstring for overlayplugin"""
name = "socket"
requestAutoload = False
version = "0.1"
apiVersion = 21
author = "Scratch"
description = "Overlay helper"
offersConfigure = False
commandKeyword = ""
infoTitle = ""
tshelp = tshelp()
menuItems = [
(ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL, 0, "Start/Stop Overlay", "scripts/%s/icon.png"%__name__),
(ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL, 1, "Refresh Overlay", "scripts/%s/icon.png"%__name__)
]
hotkeys = []

def __init__(self):
self.ws = None
self.wsserver = None
self.currentActiveServer = ts3lib.getCurrentServerConnectionHandlerID()


def send(self, message):
if self.ws != None:
try:
self.ws.send(json.dumps(message))
except Exception as e:
self.stop()

def onMenuItemEvent(self, serverConnectionHandlerID, atype, menuItemID, selectedItemID):
if menuItemID == 0:
if self.ws == None:
startupinfo = None
if osName == 'nt':
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
self.wsserver = subprocess.Popen(path.realpath(path.dirname(__file__) + '/ws.exe'), startupinfo=startupinfo, cwd=path.realpath(path.dirname(__file__)))
#path.realpath(__file__)

#Open Socket
ts3lib.printMessageToCurrentTab("Openning Overlay Socket Connection")
self.ws = create_connection("ws://localhost:58008/ws")
self.send({'debug': 'teamspeak connect'})
self.send({'event': 'updateChannelClients', 'clients': tshelp.getNearbyClients(self.currentActiveServer), 'channelName': tshelp.getChannelName(self.currentActiveServer,tshelp.getChannelID(self.currentActiveServer))})
else:
self.stop()

elif menuItemID == 1:
self.send({'event': 'updateChannelClients', 'clients': tshelp.getNearbyClients(self.currentActiveServer), 'channelName': tshelp.getChannelName(self.currentActiveServer,tshelp.getChannelID(self.currentActiveServer))})

def stop(self):
#Close Socket
if self.ws != None:
self.send({'debug': 'teamspeak disconnect'})
self.ws.close()
ts3lib.printMessageToCurrentTab("Closing Overlay Socket Connection")
self.ws = None
if self.wsserver != None:
self.wsserver.kill()
self.wsserver = None

def onTalkStatusChangeEvent(self, serverConnectionHandlerID, status, isReceivedWhisper, clientID):
name = ts3lib.getClientDisplayName(serverConnectionHandlerID, clientID)[1]
if serverConnectionHandlerID == self.currentActiveServer:
self.send({'event': 'onTalkStatusChangeEvent', 'clientID': clientID, 'status': status})

# {'event': 'onTalkStatusChangeEvent', 'cilentID': clientID, 'status': status}

# if status == ts3defines.TalkStatus.STATUS_TALKING:
# ts3lib.printMessageToCurrentTab("%s started talking" % name)
#elif status == ts3defines.TalkStatus.STATUS_NOT_TALKING:
# ts3lib.printMessageToCurrentTab("%s stopped talking" % name)


def onClientSelfVariableUpdateEvent(self, serverConnectionHandlerID, flag, oldValue, newValue):
if flag == ts3defines.ClientProperties.CLIENT_INPUT_HARDWARE:
self.currentActiveServer = serverConnectionHandlerID
# {'event': 'onClientSelfVariableUpdateEvent', 'flag': flag, 'data': [oldValue, newValue]}
self.send({'event': 'ActiveServerSwap', 'serverConnectionHandlerID': serverConnectionHandlerID,'channelName': tshelp.getChannelName(serverConnectionHandlerID,tshelp.getChannelID(serverConnectionHandlerID)), 'serverName': tshelp.getServerName(serverConnectionHandlerID), 'clients': tshelp.getNearbyClients(self.currentActiveServer)})

#ts3lib.printMessageToCurrentTab("Switched Server Mic to %s" % tshelp.getServerName(serverConnectionHandlerID))


def onClientMoveEvent(self, serverConnectionHandlerID, clientID, oldChannelID, newChannelID, visibility, moveMessage):
#Log Channel Change
#ts3lib.printMessageToCurrentTab("Switched room from %s to %s" % (tshelp.getChannelName(serverConnectionHandlerID,oldChannelID), tshelp.getChannelName(serverConnectionHandlerID,newChannelID)))
if self.currentActiveServer == serverConnectionHandlerID and clientID == ts3lib.getClientID(serverConnectionHandlerID)[1]: #If User Moves
self.send({'event': 'onClientMoveEvent', 'channelID' : newChannelID, 'channelName': tshelp.getChannelName(serverConnectionHandlerID,newChannelID), 'clients': tshelp.getNearbyClients(self.currentActiveServer)})
# self.send({'event': 'updateChannelClients', 'clients': tshelp.getNearbyClients(self.currentActiveServer)}))
# updateChannelClients()
elif self.currentActiveServer == serverConnectionHandlerID and clientID != ts3lib.getClientID(serverConnectionHandlerID)[1] and (tshelp.getChannelID(serverConnectionHandlerID) == oldChannelID or tshelp.getChannelID(serverConnectionHandlerID) == newChannelID):
EVENT = 0
if tshelp.getChannelID(serverConnectionHandlerID) == newChannelID:
EVENT = 0
else:
EVENT = 1
self.send({'event': 'nearbyClientMoveEvent', 'client': tshelp.getClientInfo(serverConnectionHandlerID, clientID), 'status': EVENT})

def onClientMoveTimeoutEvent(self, serverConnectionHandlerID, clientID, oldChannelID, newChannelID, visibility, timeoutMessage):
if self.currentActiveServer == serverConnectionHandlerID and oldChannelID == tshelp.getChannelID(serverConnectionHandlerID):
self.send({'event': 'nearbyClientMoveEvent', 'client': tshelp.getClientInfo(serverConnectionHandlerID, clientID), 'status': 1})


def onConnectStatusChangeEvent(self, serverConnectionHandlerID, newStatus, errorNumber):
#if newStatus == ts3defines.ConnectStatus.STATUS_DISCONNECTED:
if newStatus == ts3defines.ConnectStatus.STATUS_CONNECTED:
self.currentActiveServer = serverConnectionHandlerID
self.send({'event': 'ActiveServerSwap', 'serverConnectionHandlerID': serverConnectionHandlerID,'channelName': tshelp.getChannelName(serverConnectionHandlerID,tshelp.getChannelID(serverConnectionHandlerID)), 'serverName': tshelp.getServerName(serverConnectionHandlerID), 'clients': tshelp.getNearbyClients(self.currentActiveServer)})

def onClientDisplayNameChanged(self, serverConnectionHandlerID, clientID, displayName, uniqueClientIdentifier):
if self.currentActiveServer == serverConnectionHandlerID:
self.send({'event': 'onClientDisplayNameChanged', 'client':[clientID, displayName]})

def onClientKickFromServerEvent(self, serverConnectionHandlerID, clientID, oldChannelID, newChannelID, visibility, kickerID, kickerName, kickerUniqueIdentifier, kickMessage):
if self.currentActiveServer == serverConnectionHandlerID and oldChannelID == tshelp.getChannelID(serverConnectionHandlerID):
self.send({'event': 'nearbyClientMoveEvent', 'client': tshelp.getClientInfo(serverConnectionHandlerID, clientID), 'status': 1})

def onClientMoveMovedEvent(self, serverConnectionHandlerID, clientID, oldChannelID, newChannelID, visibility, moverID, moverName, moverUniqueIdentifier, moveMessage):
if self.currentActiveServer == serverConnectionHandlerID and oldChannelID == tshelp.getChannelID(serverConnectionHandlerID):
self.send({'event': 'nearbyClientMoveEvent', 'client': tshelp.getClientInfo(serverConnectionHandlerID, clientID), 'status': 1})

Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 0 additions & 95 deletions python/socketplugin/__init__.py

This file was deleted.

27 changes: 0 additions & 27 deletions python/tshelp.py

This file was deleted.

Loading

0 comments on commit 4c2558a

Please sign in to comment.