Search Unity

Unity PC build communicates to the WebGL build

Discussion in 'Connected Games' started by powerflame, May 19, 2019.

  1. powerflame

    powerflame

    Joined:
    Oct 1, 2016
    Posts:
    1
    Hi, I'm now working on a project that can implement the online voice recognization with Unity. In order to fulfill the voice recognization, I use the PhraseRecognizationSystem script API. But this API must be based on Windows 10 OS, so can only build into Windows 10 PC .exe software to do the recognization.
    But the same time, the project that user can operate is built into WebGL which be hosted in my VPS. Now the workflow is like this: user open the voice recognization which built into PC software-->user open the URL that host the WebGL build-->user say a word-->PC build recognize the phrase-->PC build send the word string to WebGL build-->WebGL build receive the string, and do the logic, then perform the corresponding action, like switch scene, set any object to active, etc.
    So how to implement this PC build to WebGL communication function? I know that we can call JavaScript function to call the Unity script, but how to communicate PC build with the JavaScript code?
    Thanks~!
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    6,264
    Well, WebGL builds can only open client connections and cannot use anything based on Sockets directly. Generally that leaves http requests and websockets as the only options. Your WebGL build will need to somehow open a client connection to your Win 10 build acting as a server.

    That is a problem because 99.999% of the time a Win 10 box will be on a NAT network, and need either the user to go into their router settings and enable port forwarding and plug the router address into the WebGL build, or you need another server acting as an intermediary. If you went with the extra server option, you.d have the WebGL build open a client connection to this server using websockets, and the Win 10 build does the same thing (though isn't restricted to only using websockets). That's the way I'd go if you were considering distributing this project.