Professional Documents
Culture Documents
using System;
using System.Collections;
using System.Collections.Generic;
public class LiveChatScript : MonoBehaviour {
/*
Start chat<POST
This function creates new chat for a visitor and returns unique session
ID, which is required to send, receive or close a given chat.
Get pending messages<GET
Returns messages and events in a pending chat. Important note: In order
to persist the chat session, you must send that request every few seconds.
Otherwise, the chat will be closed after ~30 seconds.
if (lastMessageID.Length > 0)
{
uri += string.Format("&last_message_id={0}", lastMessage
ID);
}
Send message<POST
Sends a new message as the visitor.
Close chat<POST
Ends the chat as a visitor.
Program flow
StartScene
button start chat
onClick ->vytvo se http dotaz start chat ->odpovdtrue vytvo se nov www
objekt s daty z odpovdi(listener pro get_pending_messages) a loadlevel(chatScene)
false chybo
v hlka
chatscene
inputfield inputMessage -> onValueChanged ulo se text
button buttonQuit -> onClick ->
button buttonSend -> onClick -> vytvo se http dotaz send_message >odpovdtrue pidej rectChatArea jinak chybov hlka
rectView rectChatArea ->v update http dotaz getpending.. a zprac
ovn
*/
//tdy pro JSON
//pro send_message a close_chat
[Serializable]
public class BasicResponseFormat
{
public bool success;
}
//bez securedSessionId nelze nic
[Serializable]
public class StartChatResponseFormat
{
public string secureSessionId;
Debug.Log(url);
WWW www = new WWW(url, rawData, headers);
StartCoroutine(WaitForRequest(www));
}