Skip to content

Commit

Permalink
add chat features
Browse files Browse the repository at this point in the history
  • Loading branch information
joshshifman committed Mar 30, 2017
1 parent 9ede76f commit ca8e728
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 25 deletions.
72 changes: 66 additions & 6 deletions MediVision_Unity/Assets/Scenes/HUD.unity
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ MonoBehaviour:
debug_capture_on: 0
disconnectionMessage: Stream Disconnected
___________________________: 0
--- !u!114 &331957774 stripped
MonoBehaviour:
m_PrefabParentObject: {fileID: 114912508763807164, guid: 08bf54483fb250346b11c66b8be528c9,
type: 2}
m_PrefabInternal: {fileID: 471524086}
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
--- !u!1001 &348723320
Prefab:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -346,6 +352,7 @@ GameObject:
- component: {fileID: 361102408}
- component: {fileID: 361102407}
- component: {fileID: 361102406}
- component: {fileID: 361102405}
m_Layer: 5
m_Name: Chat_panel (1)
m_TagString: Untagged
Expand Down Expand Up @@ -373,6 +380,26 @@ RectTransform:
m_AnchoredPosition: {x: 5.89, y: -5.37}
m_SizeDelta: {x: 255.80005, y: 0}
m_Pivot: {x: 0.5, y: 0}
--- !u!114 &361102405
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 361102403}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b6e4a2c4eb860a74fae66269c1bcca00, type: 3}
m_Name:
m_EditorClassIdentifier:
serverURL: http://34.198.160.73/api/stream/query/
stream_id:
IP:
urlSuffix: socket.io/?EIO=4&transport=websocket
checkConnectionDelay: 5
msgPrefab: {fileID: 696921162}
currentMesage: {fileID: 331957774}
msgParentPanel: {fileID: 361102404}
titleText: {fileID: 1581492273}
--- !u!114 &361102406
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -496,7 +523,7 @@ Prefab:
- target: {fileID: 224118964369250636, guid: 08bf54483fb250346b11c66b8be528c9,
type: 2}
propertyPath: m_AnchoredPosition.y
value: 0
value: -28.85
objectReference: {fileID: 0}
- target: {fileID: 224118964369250636, guid: 08bf54483fb250346b11c66b8be528c9,
type: 2}
Expand All @@ -516,7 +543,7 @@ Prefab:
- target: {fileID: 224118964369250636, guid: 08bf54483fb250346b11c66b8be528c9,
type: 2}
propertyPath: m_AnchorMin.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 224118964369250636, guid: 08bf54483fb250346b11c66b8be528c9,
type: 2}
Expand All @@ -526,7 +553,7 @@ Prefab:
- target: {fileID: 224118964369250636, guid: 08bf54483fb250346b11c66b8be528c9,
type: 2}
propertyPath: m_AnchorMax.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 224118964369250636, guid: 08bf54483fb250346b11c66b8be528c9,
type: 2}
Expand All @@ -546,17 +573,17 @@ Prefab:
- target: {fileID: 224946664677755714, guid: 08bf54483fb250346b11c66b8be528c9,
type: 2}
propertyPath: m_AnchorMin.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 224946664677755714, guid: 08bf54483fb250346b11c66b8be528c9,
type: 2}
propertyPath: m_AnchorMax.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 224946664677755714, guid: 08bf54483fb250346b11c66b8be528c9,
type: 2}
propertyPath: m_AnchoredPosition.y
value: 0
value: -9.85
objectReference: {fileID: 0}
- target: {fileID: 224946664677755714, guid: 08bf54483fb250346b11c66b8be528c9,
type: 2}
Expand All @@ -568,6 +595,16 @@ Prefab:
propertyPath: m_Material
value:
objectReference: {fileID: 2100000, guid: 7187377b157675449ad892634f194ca6, type: 2}
- target: {fileID: 114912508763807164, guid: 08bf54483fb250346b11c66b8be528c9,
type: 2}
propertyPath: m_Text
value:
objectReference: {fileID: 0}
- target: {fileID: 114584777811179402, guid: 08bf54483fb250346b11c66b8be528c9,
type: 2}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 08bf54483fb250346b11c66b8be528c9, type: 2}
m_IsPrefabParent: 0
Expand All @@ -586,6 +623,7 @@ GameObject:
- component: {fileID: 633141678}
- component: {fileID: 633141677}
- component: {fileID: 633141680}
- component: {fileID: 633141681}
m_Layer: 0
m_Name: HUD
m_TagString: Untagged
Expand Down Expand Up @@ -729,6 +767,28 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
PivotAxis: 1
--- !u!114 &633141681
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 633141672}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dd4333e6f284c4e4eb1c7257fe866c40, type: 3}
m_Name:
m_EditorClassIdentifier:
IP_box: {fileID: 300801562}
IP_Fade_Delay: 3
IP_Fade_Speed: 0.01
debug_capture_on: 0
disconnectionMessage: Stream Disconnected
___________________________: 0
--- !u!1 &696921162 stripped
GameObject:
m_PrefabParentObject: {fileID: 1513393013730664, guid: 08bf54483fb250346b11c66b8be528c9,
type: 2}
m_PrefabInternal: {fileID: 471524086}
--- !u!1001 &976442468
Prefab:
m_ObjectHideFlags: 0
Expand Down
77 changes: 60 additions & 17 deletions MediVision_Unity/Assets/Scripts/ChatBoxMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ public class ChatBoxMain : MonoBehaviour
public string urlSuffix = "socket.io/?EIO=4&transport=websocket";
public float checkConnectionDelay = 5; //seconds
public GameObject msgPrefab;
public Text currentMesage;
public Transform msgParentPanel;
public Text titleText;

float timeOfLastCheck = 0;
bool alreadyCalled = false;



// Use this for initialization
void Start()
{
Debug.Log("I am alive!");
StartCoroutine(GetText());

Debug.Log("CHATBOX MAIN HAS STARTED");


}

Expand All @@ -43,12 +47,23 @@ string GetIP()

// Update is called once per frame
void Update()
{
{
if (HUD.S.captureOn() && !alreadyCalled) {
Debug.Log("CALLED COROUTINE TO GET STREAM ID");
StartCoroutine(GetText());
alreadyCalled = true;
}
}

IEnumerator GetText()
{
StreamID stream_info;
Debug.Log("IN GET TEXT");


Debug.Log("WAIING FOR 5 SECONDS...");
yield return new WaitForSeconds(5f);


string url = getURL();
Debug.Log(url);

Expand All @@ -61,24 +76,30 @@ IEnumerator GetText()
}
else
{
stream_info = JsonUtility.FromJson<StreamID>(www.downloadHandler.text);
Debug.Log("PARSING JSON...");
StreamID stream_info = JsonUtility.FromJson<StreamID>(www.downloadHandler.text);

Debug.Log("RAW JSON STRING: ");
Debug.Log(www.downloadHandler.text);

Debug.Log("STREAM ID: ");
Debug.Log(stream_info.stream_id);
Debug.Log(stream_info.stream_id.ToString());

StartCoroutine(getMessage(stream_info));
StartCoroutine(getMessage(stream_info.stream_id));
}
}

public IEnumerator getMessage(StreamID stream_info) {
public IEnumerator getMessage(string id) {


while (true) {

Debug.Log("IN GETMESSAGE()");


yield return new WaitForSeconds(5f);

string url = "http://34.198.160.73/api/chat/" + stream_info.stream_id + "?viewer_only=false";
string url = "http://34.198.160.73/api/chat/" + id + "?viewer_only=false";
Debug.Log(url);

ChatResponse chat;
Expand All @@ -93,25 +114,47 @@ public IEnumerator getMessage(StreamID stream_info) {
else
{
chat = JsonUtility.FromJson<ChatResponse>(www.downloadHandler.text);
string message = chat.chat_messages[0].chat_content;
Debug.Log(message);
setMessage(message);

if (chat.chat_messages.Length > 0)
{
string message = chat.chat_messages[chat.chat_messages.Length - 1].chat_content;

Debug.Log("CHAT MESSAGE: ");
Debug.Log(message);


setMessage(message);
}

}
}
}

public void setMessage(string msg)
{
if (msg == "") return;
GameObject msgClone = Instantiate(msgPrefab);
msgClone.transform.SetParent(msgParentPanel);
msgClone.transform.SetSiblingIndex(msgParentPanel.transform.childCount - 2);
msgClone.GetComponent<Message>().showMessage(msg);

Debug.Log("IN SET MESSAGE");

//if (msg == "") return;
//GameObject msgClone = Instantiate(msgPrefab);
//msgClone.transform.SetParent(msgParentPanel);
//msgClone.transform.SetSiblingIndex(msgParentPanel.transform.childCount - 2);

//var currentPos = msgClone.transform.position;
//msgClone.transform.position = new Vector3(currentPos.x, currentPos.y, 1.75f);

//var scale = new Vector3(1, 1, 1);
//msgClone.transform.localScale = scale;

//msgClone.GetComponent<Message>().showMessage(msg);

currentMesage.text = msg;

}

public string getURL()
{
return serverURL + "10.0.0.1"; //GetIP();
return serverURL + GetIP();
}

string requestStreamIdentifier()
Expand Down
6 changes: 4 additions & 2 deletions MediVision_Unity/Assets/Scripts/HUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

public class HUD : MonoBehaviour
{
static public HUD S;

//inspector variables
public Text IP_box;
public float IP_Fade_Delay = 3f;
Expand All @@ -22,7 +24,7 @@ public class HUD : MonoBehaviour

private void Awake()
{

S = this;
}

// Use this for initialization
Expand Down Expand Up @@ -74,7 +76,7 @@ void ip_fade()
}
}

bool captureOn()
public bool captureOn()
{
if (debug_capture_on)
{
Expand Down
1 change: 1 addition & 0 deletions MediVision_Unity/Assets/Scripts/JSONResponses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void Update () {
}
}

[System.Serializable]
public class StreamID {

public string stream_id;
Expand Down

0 comments on commit ca8e728

Please sign in to comment.