コード例 #1
0
        /// <summary>Starts the server.</summary>
        public bool Start()
        {
            if (Started)
            {
                return(true);
            }

            Listener = new HttpListener();

            string baseLocation = "http://localhost:" + Port + "/";

            // Http only:
            Listener.Prefixes.Add(baseLocation);

            BaseLocation = new Dom.Location(baseLocation);

            try{
                // Go!
                Listener.Start();

                // Await:
                Listener.BeginGetContext(new AsyncCallback(OnRequest), Listener);
            }catch (Exception e) {
                // Already running.
                Listener = null;
                UnityEngine.Debug.LogError("Error: " + e);
            }

            return(Started);
        }
コード例 #2
0
        /// <summary>Loads a slides JSON file at the given path (relative to the given location)
        /// optionally into the given timeline.</summary>
        internal static Promise open(string startPath, Dom.Location relativeTo, Timeline into)
        {
            // Use this to establish when it's ready:
            Promise p = new Promise();

            // Append .json if it's needed:
            if (!startPath.Contains(".") && !startPath.Contains("://"))
            {
                startPath += ".json";
            }

            // Localise it:
            startPath = startPath.Replace("{language}", UI.Language);

            // Load the file now:
            DataPackage req = new DataPackage(
                startPath,
                relativeTo
                );

            if (into == null)
            {
                into = new Timeline(null);
            }

            // Delegate:
            req.onload = delegate(UIEvent e){
                try{
                    // Response is a block of options:
                    JSObject options = JSON.Parse(req.responseText);

                    // Load it up and run the callback:
                    into.load(options);
                }catch {
                    // Invalid json.
                    p.reject(into);
                    return;
                }

                // Run the promise now:
                p.resolve(into);
            };

            req.onerror = delegate(UIEvent e){
                into.status_ = TIMELINE_UNAVAILABLE;
                p.reject(into);
            };

            // Send!
            req.send();

            return(p);
        }
コード例 #3
0
ファイル: Widget.cs プロジェクト: HippoAR/DemoPowerUI
        /// <summary>Navigates the widget to the given URL. Should only be used once;
        /// close and open another widget (or use links inside the iframe).</summary>
        internal virtual void Goto(string url, Dictionary <string, object> globals)
        {
            // Set location:
            Location = url;

            if (contentDocument == null)
            {
                // Doesn't navigate.
                return;
            }

            // Use an event which runs between the clear and load:
            contentDocument.AfterClearBeforeSet = delegate(Dom.Event acs){
                // Hook up title change:
                contentDocument.ontitlechange = delegate(Dom.Event e){
                    // Set the 'title' element, if we have one:
                    HtmlElement t = TitleElement;

                    if (t != null)
                    {
                        t.innerHTML = contentDocument.title;
                    }
                };

                // Apply globals to the script engine when it's ready:
                if (globals != null)
                {
                    contentDocument.addEventListener("scriptenginestart", delegate(Dom.Event e){
                        foreach (KeyValuePair <string, object> kvp in globals)
                        {
                            // Skip if it starts with -spark-
                            if (kvp.Key.StartsWith("-spark-"))
                            {
                                continue;
                            }

                            // Set it:
                            contentDocument.setJsVariable(kvp.Key, kvp.Value);
                        }
                    });
                }
            };

            // Run the open events:
            trigger("open");
            trigger("animateshow");

            // Create the location (relative to resources:// by default):
            Dom.Location loc = new Dom.Location(url, null);

            // Navigate CD now:
            contentDocument.location = loc;
        }
コード例 #4
0
 /// <summary>Loads a slides JSON file at the given path (relative to the given location).</summary>
 internal static Promise open(string startPath, Dom.Location relativeTo)
 {
     return(open(startPath, relativeTo, null));
 }