Skip to content

Commit

Permalink
Ability to set a positional context and position (#76)
Browse files Browse the repository at this point in the history
* Added the ability to set a position
  • Loading branch information
yquemener authored Jul 27, 2020
1 parent 4e4ea13 commit 5011492
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pymumble_py3/mumble.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def __init__(self, host, user, port=64738, password='', certfile=None, keyfile=N
self.ready_lock = threading.Lock() # released when the connection is fully established with the server
self.ready_lock.acquire()

self.positional = None

def init_connection(self):
"""Initialize variables that are local to a connection, (needed if the client automatically reconnect)"""
self.ready_lock.acquire(False) # reacquire the ready-lock in case of reconnection
Expand Down Expand Up @@ -526,7 +528,6 @@ def sound_received(self, message):
# raise InvalidFormatError("Invalid audio frame size")

pos += size # go further in the packet, after the audio frame

# TODO: get position info

def set_application_string(self, string):
Expand Down Expand Up @@ -664,6 +665,8 @@ def treat_command(self, cmd):
userstate.texture = cmd.parameters["texture"]
if "user_id" in cmd.parameters:
userstate.user_id = cmd.parameters["user_id"]
if "plugin_context" in cmd.parameters:
userstate.plugin_context = cmd.parameters["plugin_context"]

self.send_message(PYMUMBLE_MSG_TYPES_USERSTATE, userstate)
cmd.response = True
Expand Down
2 changes: 2 additions & 0 deletions pymumble_py3/soundoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def send_audio(self):
sequence = VarInt(self.sequence).encode()

udppacket = struct.pack('!B', header | self.target) + sequence + payload
if self.mumble_object.positional:
udppacket += struct.pack("fff", self.mumble_object.positional[0], self.mumble_object.positional[1], self.mumble_object.positional[2])

self.Log.debug("audio packet to send: sequence:{sequence}, type:{type}, length:{len}".format(
sequence=self.sequence,
Expand Down
8 changes: 7 additions & 1 deletion pymumble_py3/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def update(self, message):
actions["actor"] = message.actor

for (field, value) in message.ListFields():
if field.name in ("session", "actor", "comment", "texture"):
if field.name in ("session", "actor", "comment", "texture", "plugin_context", "plugin_identity"):
continue
actions.update(self.update_field(field.name, value))

Expand Down Expand Up @@ -210,6 +210,12 @@ def register(self):
cmd = messages.ModUserState(self.mumble_object.users.myself_session, params)
self.mumble_object.execute_command(cmd)

def update_context(self, context_name):
params = {"session": self["session"],
"plugin_context": context_name}
cmd = messages.ModUserState(self.mumble_object.users.myself_session, params)
self.mumble_object.execute_command(cmd)

def move_in(self, channel_id, token=None):
if token:
authenticate = mumble_pb2.Authenticate()
Expand Down

0 comments on commit 5011492

Please sign in to comment.