ConsoleBridgeMessage.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (c) 2024 Vuplex Inc. All rights reserved.
  2. //
  3. // Licensed under the Vuplex Commercial Software Library License, you may
  4. // not use this file except in compliance with the License. You may obtain
  5. // a copy of the License at
  6. //
  7. // https://vuplex.com/commercial-library-license
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma warning disable CS0649
  15. using System;
  16. using UnityEngine;
  17. namespace Vuplex.WebView.Internal {
  18. /// <summary>
  19. /// Used internally for implementing `IWebView.ConsoleMessageLogged`.
  20. /// </summary>
  21. [Serializable]
  22. class ConsoleBridgeMessage : BridgeMessage {
  23. public string message;
  24. public string level;
  25. public string source;
  26. public int line;
  27. public ConsoleMessageEventArgs ToEventArgs() {
  28. return new ConsoleMessageEventArgs(_parseMessageLevel(level), message, source, line);
  29. }
  30. ConsoleMessageLevel _parseMessageLevel(string levelString) {
  31. switch (levelString) {
  32. case "LOG":
  33. return ConsoleMessageLevel.Log;
  34. case "DEBUG":
  35. return ConsoleMessageLevel.Debug;
  36. case "WARNING":
  37. return ConsoleMessageLevel.Warning;
  38. case "ERROR":
  39. return ConsoleMessageLevel.Error;
  40. default:
  41. WebViewLogger.LogError("Unrecognized ConsoleMessageLevel string: " + levelString);
  42. return ConsoleMessageLevel.Log;
  43. }
  44. }
  45. }
  46. }