public void Start(string url)
        {
            button_.interactable = false;

            downloader_ = new FunapiHttpDownloader();
            downloader_.VerifyCallback   += onDownloadVerify;
            downloader_.ReadyCallback    += onDownloadReady;
            downloader_.UpdateCallback   += onDownloadUpdate;
            downloader_.FinishedCallback += onDownloadFinished;

            downloader_.GetDownloadList(url, FunapiUtils.GetLocalDataPath);
        }
Exemplo n.º 2
0
    public void OnGUI()
    {
        //----------------------------------------------------------------------------
        // FunapiNetwork test
        //----------------------------------------------------------------------------
        with_session_reliability_ = GUI.Toggle(new Rect(30, 5, 130, 20), with_session_reliability_, " session reliability");
        with_protobuf_            = GUI.Toggle(new Rect(180, 5, 150, 20), with_protobuf_, " google protocol buffer");

        GUI.Label(new Rect(30, 40, 300, 20), "[FunapiNetwork] - " + kServerIp);
        GUI.enabled = (network_ == null || !network_.Started);
        if (GUI.Button(new Rect(30, 60, 240, 40), "Connect (TCP)"))
        {
            Connect(TransportProtocol.kTcp);
        }
        if (GUI.Button(new Rect(30, 105, 240, 40), "Connect (UDP)"))
        {
            Connect(TransportProtocol.kUdp);
        }
        if (GUI.Button(new Rect(30, 150, 240, 40), "Connect (HTTP)"))
        {
            Connect(TransportProtocol.kHttp);
        }

        GUI.enabled = (network_ != null && network_.Connected);
        if (GUI.Button(new Rect(30, 195, 240, 40), "Disconnect"))
        {
            Disconnect();
        }

        if (GUI.Button(new Rect(30, 240, 240, 40), "Send a message"))
        {
            SendEchoMessage();
        }

        //----------------------------------------------------------------------------
        // Announcements test
        //----------------------------------------------------------------------------
        GUI.enabled = true;
        GUI.Label(new Rect(30, 300, 300, 20), string.Format("[Announcer] - {0}:{1}", kAnnouncementIp, kAnnouncementPort));
        if (GUI.Button(new Rect(30, 320, 240, 40), "Update announcements"))
        {
            if (announcement_ == null)
            {
                announcement_ = new FunapiAnnouncement();
                announcement_.ResultCallback += new FunapiAnnouncement.EventHandler(OnAnnouncementResult);

                string url = "";
                if (FunapiConfig.IsValid)
                {
                    url = FunapiConfig.AnnouncementUrl;
                }

                if (url.Length <= 0)
                {
                    url = string.Format("http://{0}:{1}", kAnnouncementIp, kAnnouncementPort);
                }

                if (url.Length <= 0)
                {
                    return;
                }

                announcement_.Init(url);
            }

            announcement_.UpdateList(5);
        }

        //----------------------------------------------------------------------------
        // Resource download test
        //----------------------------------------------------------------------------
        GUI.enabled = downloader_ == null;
        GUI.Label(new Rect(30, 380, 300, 20), string.Format("[Downloader] - {0}:{1}", kDownloadServerIp, kDownloadServerPort));
        if (GUI.Button(new Rect(30, 400, 240, 40), "Resource downloader (HTTP)"))
        {
            string download_url = "";

            if (FunapiConfig.IsValid)
            {
                FunapiConfig.GetDownloaderUrl(out download_url);
            }

            if (download_url == "")
            {
                download_url = string.Format("http://{0}:{1}", kDownloadServerIp, kDownloadServerPort);
            }

            downloader_ = new FunapiHttpDownloader();
            downloader_.VerifyCallback   += new FunapiHttpDownloader.VerifyEventHandler(OnDownloadVerify);
            downloader_.ReadyCallback    += new FunapiHttpDownloader.ReadyEventHandler(OnDownloadReady);
            downloader_.UpdateCallback   += new FunapiHttpDownloader.UpdateEventHandler(OnDownloadUpdate);
            downloader_.FinishedCallback += new FunapiHttpDownloader.FinishEventHandler(OnDownloadFinished);
            downloader_.GetDownloadList(download_url, FunapiUtils.GetLocalDataPath);
        }

        //----------------------------------------------------------------------------
        // FunapiMulticasting test
        //----------------------------------------------------------------------------
        GUI.enabled = (multicast_ == null);
        GUI.Label(new Rect(280, 40, 300, 20), "[Muticasting]");
        string multicast_title = "Create 'multicast'";

        if (GUI.Button(new Rect(280, 60, 240, 40), multicast_title))
        {
            FunapiTransport transport = null;
            if (network_ == null || (transport = network_.GetTransport(TransportProtocol.kTcp)) == null)
            {
                DebugUtils.LogWarning("You should connect to tcp transport first.");
            }
            else
            {
                multicast_          = new FunapiMulticastClient(network_, transport.Encoding);
                multicast_encoding_ = transport.Encoding;
            }
        }

        GUI.enabled     = (multicast_ != null && multicast_.Connected && !multicast_.InChannel(kMulticastTestChannel));
        multicast_title = "Join a channel";
        if (GUI.Button(new Rect(280, 105, 240, 40), multicast_title))
        {
            multicast_.JoinChannel(kMulticastTestChannel, OnMulticastChannelSignalled);
            DebugUtils.Log("Joining the multicast channel '{0}'", kMulticastTestChannel);
        }

        GUI.enabled     = (multicast_ != null && multicast_.Connected && multicast_.InChannel(kMulticastTestChannel));
        multicast_title = "Send a message";
        if (GUI.Button(new Rect(280, 150, 240, 40), multicast_title))
        {
            if (multicast_encoding_ == FunEncoding.kJson)
            {
                Dictionary <string, object> mcast_msg = new Dictionary <string, object>();
                mcast_msg["_channel"] = kMulticastTestChannel;
                mcast_msg["_bounce"]  = true;
                mcast_msg["message"]  = "multicast test message";

                multicast_.SendToChannel(mcast_msg);
            }
            else
            {
                /*PbufHelloMessage hello_msg = new PbufHelloMessage();
                 * hello_msg.message = "multicast test message";
                 *
                 * FunMulticastMessage mcast_msg = new FunMulticastMessage();
                 * mcast_msg.channel = kMulticastTestChannel;
                 * mcast_msg.bounce = true;
                 * Extensible.AppendValue(mcast_msg, (int)MulticastMessageType.pbuf_hello, hello_msg);
                 *
                 * multicast_.SendToChannel(mcast_msg);*/
            }

            DebugUtils.Log("Sending a message to the multicast channel '{0}'", kMulticastTestChannel);
        }

        GUI.enabled     = (multicast_ != null && multicast_.Connected && multicast_.InChannel(kMulticastTestChannel));
        multicast_title = "Leave a channel";
        if (GUI.Button(new Rect(280, 195, 240, 40), multicast_title))
        {
            multicast_.LeaveChannel(kMulticastTestChannel);
            DebugUtils.Log("Leaving the multicast channel '{0}'", kMulticastTestChannel);
        }

        GUI.Label(new Rect(280, 250, 300, 20), "[Multicast Chat]");
        GUI.enabled = (chat_ == null);
        string chat_title = "Create 'chat'";

        if (GUI.Button(new Rect(280, 270, 240, 40), chat_title))
        {
            FunapiTransport transport = null;
            if (network_ == null || (transport = network_.GetTransport(TransportProtocol.kTcp)) == null)
            {
                DebugUtils.LogWarning("You should connect to tcp transport first.");
            }
            else
            {
                chat_ = new FunapiChatClient(network_, transport.Encoding);
            }
        }

        GUI.enabled = (chat_ != null && chat_.Connected && !chat_.InChannel(kChatTestChannel));
        chat_title  = "Join a channel";
        if (GUI.Button(new Rect(280, 315, 240, 40), chat_title))
        {
            chat_.JoinChannel(kChatTestChannel, kChatUserName, OnChatChannelReceived);
            DebugUtils.Log("Joining the chat channel '{0}'", kChatTestChannel);
        }

        GUI.enabled = (chat_ != null && chat_.Connected && chat_.InChannel(kChatTestChannel));
        chat_title  = "Send a message";
        if (GUI.Button(new Rect(280, 360, 240, 40), chat_title))
        {
            chat_.SendText(kChatTestChannel, "hello world");

            DebugUtils.Log("Sending a message to the chat channel '{0}'", kChatTestChannel);
        }

        GUI.enabled = (chat_ != null && chat_.Connected && chat_.InChannel(kChatTestChannel));
        chat_title  = "Leave a channel";
        if (GUI.Button(new Rect(280, 405, 240, 40), chat_title))
        {
            chat_.LeaveChannel(kChatTestChannel);
            DebugUtils.Log("Leaving the chat channel '{0}'", kChatTestChannel);
        }
    }