Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Problem with unity web export

A topic by Kalinarm created Jan 24, 2022 Views: 286 Replies: 7
Viewing posts 1 to 6
Submitted (1 edit)

Hello, Apparently, the web export from a unity project with madora has some problem with websocket and security. Could someone help me resolve that plz ??

Thanks in advance !

Here my browser error : An error occurred running the Unity content on this page. See your browser JavaScript console for more info. The error was: SecurityError: The operation is insecure. _WebSocketConnect@https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.framework.js.gz:2:57613 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[35671]:0xe48e81 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[74779]:0x16473a1 unityFramework/Module.dynCall_iii@https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.framework.js.gz:2:525566 invoke_iii@https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.framework.js.gz:2:346179 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[37662]:0xeb47a0 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[74818]:0x1647972 unityFramework/Module.dynCall_vii@https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.framework.js.gz:2:551335 invoke_vii@https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.framework.js.gz:2:395080 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[43222]:0xf97b30 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[30551]:0xd66ca5 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[30550]:0xd66c94 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[28539]:0xcf45e0 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[74785]:0x164746d unityFramework/Module.dynCall_iiiii@https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.framework.js.gz:2:531531 invoke_iiiii@https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.framework.js.gz:2:357522 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[72827]:0x15eedd5 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[72245]:0x15d4bba @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[4588]:0x1de188 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[4586]:0x1dde58 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[8612]:0x345276 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[8610]:0x344197 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[10706]:0x40cb0b @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[8847]:0x35f3dd @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[11134]:0x43c6b7 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[10807]:0x4165e0 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[10807]:0x4165f5 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[10802]:0x41617a @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[10795]:0x4142d9 @https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.wasm.gz:wasm-function[74802]:0x164775d unityFramework/Module.dynCall_v@https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.framework.js.gz:2:542650 browserIterationFunc@https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.framework.js.gz:2:176536 runIter@https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.framework.js.gz:2:179609 Browser_mainLoop_runner@https://v6p9d9t4.ssl.hwcdn.net/html/5130194-509546/Build/NanoJam_Web.framework.js.gz:2:178071

HostSubmitted

Hi Kalinka, sorry you are running into issues. It's hard to tell what website you are trying to access with the websocket from this error log, can you post that here? My guess is that you are using a ws:// connection, when it needs to be a wss:// connection. ws:// is an insecure websocket connection (akin to http) vs wss:// is a secure websocket connection (similar to https). The browser will stop you from making an insecure websocket connection from a secure (https) connection, which I think is what you are running into here. The fix should be to change ws:// in your websocket url to wss://, unless I've misdiagnosed the issue. 

If that doesn't work, can you please post your code around setting up the websocket to help diagnose the issue?

HostSubmitted

For more immediate assistance, please email us at support@madora.io.

Submitted

Thanks for your answer. Sadly, I can’t connect with the information given on the documentation page.(with or without http/htttps and ws/wss) I have publish the game with tweak of the demo plugin. I can update a version easyly to change that when I find a solution. Sent an email to you with detail.

HostSubmitted

Hi Kalinka,

We have responded to your email, apologies for the issues you are having with connection. If we're unable to resolve the connection issues by the end of the jam that is alright, your game will still be eligible. Hopefully we can resolve this quickly so that we are all able to enjoy your game to the fullest extent.

I had a similar issue, please see my submission page. I submitted regardless, hopefully we can get this figured out.

HostSubmitted(+1)

Hi, we were able to work with Kalinka to resolve this. It seems the Unity plugin doesn't easily support authentication with our servers (we did not develop it, another member of the Nano community did). I will be putting up a pull request later this week to fix this, which will hopefully be accepted! In the meantime however, you will need to make some manual changes to the code in your integration with the plugin. Here are the instructions:

In the Nano Plugin, under Nano > Plugins > Nano there should be a NanoWebsocket.cs file. If you open this up, you will need to add the following lines of code:

Under the using section:

using System.Text;

 In async void Start(), as the first lines in the function:

byte[] bytesToEncode = Encoding.UTF8.GetBytes ("<yourkey>:<yoursecret>");
string auth = "Basic " + Convert.ToBase64String (bytesToEncode);
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("Authorization", auth);
websocket = new WebSocket(url, headers);

The last line there is replacing the existing line of websocket = new WebSocket(url);

In the Nano Plugin under Nano > Plugins > Nano there should be a RPC.cs file. In here, you will need to replace the beginning of the RPC class with the following:

      public class RPC
      {
        public string url;
        private string auth;
        public RPC(string url)
        {
          this.url = url;
          byte[] bytesToEncode = Encoding.UTF8.GetBytes ("<yourkey>:<yoursecret>");
          this.auth = "Basic " + Convert.ToBase64String (bytesToEncode);
        }
        public IEnumerator MakeRequest(UnityWebRequest webRequest, byte[] body, Action<string> callback)
        {
          webRequest.uploadHandler = new UploadHandlerRaw(body);
          webRequest.downloadHandler = new DownloadHandlerBuffer();
          webRequest.SetRequestHeader("Content-Type", "application/json");
          webRequest.SetRequestHeader("Accepts", "application/json");
          webRequest.SetRequestHeader("Authorization", this.auth);

The key additions here are: generating the authorization when the class is initialized, and then adding it in every request made.

ALSO, very important, make sure you replace the instances of <yourkey> and <yoursecret> with a key and secret that you generate on your account on the Madora website.

There may also be some issues with the websocket that I am still investigating (it does not perform keep-alive properly, so it keeps timing out after 1 minute. This should be an easy fix but I haven't had time yet). Let me know if you have any questions, and if there's anything else I can do to help!

HostSubmitted(+1)

Actually, I think we have been able to resolve the websocket issue on our server side. With the code I posted earlier, everything should be there to integrate Nano + Unity + Madora. Please let me know if you run into any other issues!