From 4359b574e8ed505b3f4019f70823e34cf571ba76 Mon Sep 17 00:00:00 2001
From: Roxie Linden <roxie@lindenlab.com>
Date: Thu, 28 Sep 2023 10:55:13 -0700
Subject: Transmit position and power when joining

---
 indra/newview/llvoicewebrtc.cpp | 101 +++++++++++++++++++++-------------------
 indra/newview/llvoicewebrtc.h   |   4 +-
 2 files changed, 55 insertions(+), 50 deletions(-)

(limited to 'indra/newview')

diff --git a/indra/newview/llvoicewebrtc.cpp b/indra/newview/llvoicewebrtc.cpp
index a1e63c29cf..ccaa02b704 100644
--- a/indra/newview/llvoicewebrtc.cpp
+++ b/indra/newview/llvoicewebrtc.cpp
@@ -1124,7 +1124,7 @@ bool LLWebRTCVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession
     // tell peers that this participant has joined.
 
     Json::FastWriter writer;
-    Json::Value      root;
+    Json::Value      root = getPositionAndVolumeUpdateJson(true);
     root["j"]             = true;
     std::string json_data = writer.write(root);
     mWebRTCDataInterface->sendData(json_data, false);
@@ -2167,60 +2167,63 @@ void LLWebRTCVoiceClient::setHidden(bool hidden)
     }
 }
 
-void LLWebRTCVoiceClient::sendPositionAndVolumeUpdate(void)
-{	
-
+Json::Value LLWebRTCVoiceClient::getPositionAndVolumeUpdateJson(bool force)
+{
+    Json::Value root = Json::objectValue;
 
-    if (mWebRTCDataInterface && mWebRTCAudioInterface)
+    if ((mSpatialCoordsDirty || force) && inSpatialChannel())
     {
-        Json::Value  root = Json::objectValue;
-        
-        if (mSpatialCoordsDirty && inSpatialChannel())
-        {
-            root["sp"] = Json::objectValue;
-            root["sp"]["x"] = (int)(mAvatarPosition[0]*100);
-            root["sp"]["y"] = (int)(mAvatarPosition[1]*100);
-            root["sp"]["z"] = (int)(mAvatarPosition[2]*100);
-            root["sh"] = Json::objectValue;
-            root["sh"]["x"] = (int)(mAvatarRot[0]*100);
-            root["sh"]["y"] = (int)(mAvatarRot[1]*100);
-            root["sh"]["z"] = (int)(mAvatarRot[2]*100);
-            root["sh"]["w"] = (int)(mAvatarRot[3]*100);
+        root["sp"]      = Json::objectValue;
+        root["sp"]["x"] = (int) (mAvatarPosition[0] * 100);
+        root["sp"]["y"] = (int) (mAvatarPosition[1] * 100);
+        root["sp"]["z"] = (int) (mAvatarPosition[2] * 100);
+        root["sh"]      = Json::objectValue;
+        root["sh"]["x"] = (int) (mAvatarRot[0] * 100);
+        root["sh"]["y"] = (int) (mAvatarRot[1] * 100);
+        root["sh"]["z"] = (int) (mAvatarRot[2] * 100);
+        root["sh"]["w"] = (int) (mAvatarRot[3] * 100);
+
+        root["lp"]      = Json::objectValue;
+        root["lp"]["x"] = (int) (mCameraPosition[0] * 100);
+        root["lp"]["y"] = (int) (mCameraPosition[1] * 100);
+        root["lp"]["z"] = (int) (mCameraPosition[2] * 100);
+        root["lh"]      = Json::objectValue;
+        root["lh"]["x"] = (int) (mCameraRot[0] * 100);
+        root["lh"]["y"] = (int) (mCameraRot[1] * 100);
+        root["lh"]["z"] = (int) (mCameraRot[2] * 100);
+        root["lh"]["w"] = (int) (mCameraRot[3] * 100);
+
+        mSpatialCoordsDirty = false;
+    }
 
-            
-            root["lp"] = Json::objectValue;
-            root["lp"]["x"] = (int)(mCameraPosition[0]*100);
-            root["lp"]["y"] = (int)(mCameraPosition[1]*100);
-            root["lp"]["z"] = (int)(mCameraPosition[2]*100);
-            root["lh"] = Json::objectValue;
-            root["lh"]["x"] = (int)(mCameraRot[0]*100);
-            root["lh"]["y"] = (int)(mCameraRot[1]*100);
-            root["lh"]["z"] = (int)(mCameraRot[2]*100);
-            root["lh"]["w"] = (int)(mCameraRot[3]*100);
+    F32 audio_level = 0.0;
 
-            mSpatialCoordsDirty = false;
-        }
-        
-        
-        F32 audio_level = 0.0;
-        
-		if (!mMuteMic)
-        {
-            audio_level = (F32) mWebRTCDeviceInterface->getAudioLevel();
-        }
-        uint32_t uint_audio_level = mMuteMic ? 0 : (uint32_t) (audio_level * 128);
-        if (uint_audio_level != mAudioLevel)
+    if (!mMuteMic)
+    {
+        audio_level = (F32) mWebRTCDeviceInterface->getAudioLevel();
+    }
+    uint32_t uint_audio_level = mMuteMic ? 0 : (uint32_t) (audio_level * 128);
+    if (force || (uint_audio_level != mAudioLevel))
+    {
+        root["p"]                         = uint_audio_level;
+        mAudioLevel                       = uint_audio_level;
+        participantStatePtr_t participant = findParticipantByID(gAgentID);
+        if (participant)
         {
-            root["p"]					      = uint_audio_level;
-            mAudioLevel                       = uint_audio_level;
-            participantStatePtr_t participant = findParticipantByID(gAgentID);
-            if (participant)
-            {
-                participant->mPower = audio_level;
-                participant->mIsSpeaking = participant->mPower > SPEAKING_AUDIO_LEVEL;
-            }
+            participant->mPower      = audio_level;
+            participant->mIsSpeaking = participant->mPower > SPEAKING_AUDIO_LEVEL;
         }
-        
+    }
+    return root;
+}
+
+void LLWebRTCVoiceClient::sendPositionAndVolumeUpdate()
+{	
+
+
+    if (mWebRTCDataInterface && mWebRTCAudioInterface)
+    {
+        Json::Value root = getPositionAndVolumeUpdateJson(false);
         
         if (root.size() > 0)
         {
diff --git a/indra/newview/llvoicewebrtc.h b/indra/newview/llvoicewebrtc.h
index 1d013c6609..bd4346022f 100644
--- a/indra/newview/llvoicewebrtc.h
+++ b/indra/newview/llvoicewebrtc.h
@@ -40,6 +40,7 @@ class LLWebRTCProtocolParser;
 #include "lleventcoro.h"
 #include "llcoros.h"
 #include <queue>
+#include "json/reader.h"
 
 #ifdef LL_USESYSTEMLIBS
 # include "expat.h"
@@ -806,7 +807,8 @@ private:
 	std::string getAudioSessionHandle();
 			
     void setHidden(bool hidden) override; //virtual
-	void sendPositionAndVolumeUpdate(void);
+    Json::Value getPositionAndVolumeUpdateJson(bool force);
+	void sendPositionAndVolumeUpdate();
 
 	void sendFriendsListUpdates();
 
-- 
cgit v1.2.3