public void updateLatestMessageDict(wsGetMessageData data) { if (!latestMessageDict.ContainsKey(data.user)) { latestMessageDict.Add(data.user, data); } else { latestMessageDict[data.user] = data; } }
public void onMessage(object sender, MessageEventArgs e) { //Debug.Log("WebSocket Message Data: " + e.Data); wsGetMessageData msgData = JsonUtility.FromJson <wsGetMessageData>(e.Data); if (msgData.type == "message") { updateLatestMessageDict(msgData); } Debug.Log(msgData.text + " from " + msgData.user + " Type: " + msgData.type); }
// Update is called once per frame void Update() { if (WebSocketConnectionViaSlack.instance.latestMessageDict.ContainsKey(userID)) { wsGetMessageData data = WebSocketConnectionViaSlack.instance.latestMessageDict[userID]; if (currentTS == null) { currentTS = data.ts; } else if (!currentTS.Equals(data.ts)) { text.text = data.text; } } }
void Websocket_MessageReceived(MessageWebSocket sender, MessageWebSocketMessageReceivedEventArgs args) { //if (OnMessaged != null) //{ var reader = args.GetDataReader(); reader.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8; string readStr = reader.ReadString(reader.UnconsumedBufferLength); Debug.Log(readStr); wsGetMessageData msgData = JsonUtility.FromJson <wsGetMessageData>(readStr); Debug.Log(msgData.text + " from " + msgData.user + " Type: " + msgData.type); if (msgData.type == "message") { updateLatestMessageDict(msgData); } //} }