summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/UniWebView/Script/UniWebViewMessage.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-01-25 14:28:30 +0800
committerchai <chaifix@163.com>2021-01-25 14:28:30 +0800
commit6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch)
tree7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/UniWebView/Script/UniWebViewMessage.cs
+scripts
Diffstat (limited to 'Client/Assets/Scripts/UniWebView/Script/UniWebViewMessage.cs')
-rw-r--r--Client/Assets/Scripts/UniWebView/Script/UniWebViewMessage.cs87
1 files changed, 87 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/UniWebView/Script/UniWebViewMessage.cs b/Client/Assets/Scripts/UniWebView/Script/UniWebViewMessage.cs
new file mode 100644
index 00000000..b9a2f225
--- /dev/null
+++ b/Client/Assets/Scripts/UniWebView/Script/UniWebViewMessage.cs
@@ -0,0 +1,87 @@
+//
+// UniWebViewMessage.cs
+// Created by Wang Wei(@onevcat) on 2013-10-20.
+//
+using System.Collections.Generic;
+using UnityEngine;
+
+/// <summary>
+/// This structure represent a message from webview.
+/// </summary>
+/// <description>
+/// All url with a scheme of "uniwebview" in the webpage clicked will raise
+/// the OnReceivedMessage with a UniWebViewMessage object. You can listen to
+/// that event and get path and param from webpage.
+/// </description>
+public struct UniWebViewMessage {
+ /// <summary>
+ /// Gets the raw message.
+ /// </summary>
+ /// <value>
+ /// The raw message received from UniWebView. It should be a url containing information
+ /// delivered from webview.
+ /// </value>
+ public string rawMessage {get; private set;}
+
+ /// <summary>
+ /// The url scheme of this UniWebViewMessage
+ /// </summary>
+ /// <value>The scheme.</value>
+ /// <description>
+ /// Every message UniWebView can get is a url in a registered scheme.
+ /// The default scheme is "uniwebview". You can register your own scheme by
+ /// using the RegisterScheme method on UniWebView object.
+ /// </description>
+ public string scheme {get; private set;}
+
+ /// <summary>
+ /// The path of this UniWebViewMessage
+ /// </summary>
+ /// <value>The path.</value>
+ /// <description>
+ /// A url "uniwebview://yourPath?param1=value1&param2=value2", path = yourPath
+ /// </description>
+ public string path {get; private set;}
+
+ /// <summary>
+ /// The arguments of this UniWebViewMessage
+ /// </summary>
+ /// <value>The arguments.</value>
+ /// <description>
+ /// A url "uniwebview://yourPath?param1=value1&param2=value2", args[param1] = value1, args[param2] = value2
+ /// </description>
+ public Dictionary<string, string> args{get; private set;}
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="UniWebViewMessage"/> struct.
+ /// </summary>
+ /// <param name="rawMessage">Raw message which will be parsed to a UniWebViewMessage.</param>
+ public UniWebViewMessage(string rawMessage) : this() {
+ this.rawMessage = rawMessage;
+ string[] schemeSplit = rawMessage.Split(new string[] {"://"}, System.StringSplitOptions.None);
+ if (schemeSplit.Length >= 2) {
+ this.scheme = schemeSplit[0];
+ string pathAndArgsString = "";
+ int index = 1;
+ while (index < schemeSplit.Length) {
+ pathAndArgsString = string.Concat(pathAndArgsString, schemeSplit[index]);
+ index++;
+ }
+
+ string[] split = pathAndArgsString.Split("?"[0]);
+
+ this.path = split[0].TrimEnd('/');
+ this.args = new Dictionary<string, string>();
+ if (split.Length > 1) {
+ foreach (string pair in split[1].Split("&"[0])) {
+ string[] elems = pair.Split("="[0]);
+ if (elems.Length > 1) {
+ args[elems[0]] = WWW.UnEscapeURL(elems[1]);
+ }
+ }
+ }
+ } else {
+ Debug.LogError("Bad url scheme. Can not be parsed to UniWebViewMessage: " + rawMessage);
+ }
+ }
+} \ No newline at end of file