Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Guides #21

Open
Mazyod opened this issue Apr 13, 2022 · 13 comments
Open

Better Guides #21

Mazyod opened this issue Apr 13, 2022 · 13 comments
Labels

Comments

@Mazyod
Copy link
Owner

Mazyod commented Apr 13, 2022

I think the library is missing detailed guides to help developers more easily integrate the library with their project. Need to fix that.

@Mazyod Mazyod added the is:docs label Apr 13, 2022
@ekrenzin
Copy link

@Mazyod I'm attempting to integrate the library and running into some trouble figuring it out. Is there any way you could help me resolve some of the issues I'm having with integrating this into my Unity project?

I attempted to build a dll, but I get an assembly error:
image

When I attempt to import the source code manually I run into other assembly reference errors:
image

I believe I've properly set my project to .NET 4.x
image

I'm assuming there is some small but essential point that I missed during the setup. I was able to successfully run the unit tests.

Thanks in advance @Mazyod I really appreciate the work you have done on this repo!

@Mazyod
Copy link
Owner Author

Mazyod commented Apr 20, 2022

Hey @ekrenzin 👋,
Sure, I'd be happy to help!

I'm going to try importing the code into a fresh project with the settings you've shared. Meanwhile, could you please share the Unity version you're using? Perhaps also the Target platform would be helpful, although I'm guessing it's macOS.

@ekrenzin
Copy link

Hey @ekrenzin 👋, Sure, I'd be happy to help!

I'm going to try importing the code into a fresh project with the settings you've shared. Meanwhile, could you please share the Unity version you're using? Perhaps also the Target platform would be helpful, although I'm guessing it's macOS.

@Mazyod Thanks for the fast response! I'm building a VR application, so the target platform is windows & android. I created a fresh 3d project to test/confirm that I hadn't accidentally changed a setting, but I ended up with the same results. To be transparent, I'm quite new to unity and c#. It's not unlikely that there is a basic essential concept that I am unaware of.

I'm working on a windows 11 machine - but I could switch to either windows 10 or a m1 mac if that would make a difference.
I'm using Rider as an IDE.

For importing the source code, the most confusing error to me is GetValueOrDefault not recognized. However the same code GetValueOrDefault is recognized when opening & building PhoenixSharp separately from my unity projects. Is it possible that I'm missing a unity setting beyond changing to NET 4.x?

Similarly, when adding the dll as a plugin it almost seems like System.Runtime.CompilerServices.TaskAwaiter is missing?
image

Error Message:
An exception has occurred during the OnClose event.
UnityEngine.Debug:Log (object)
PhoenixTests.WebSocketImpl.WebsocketSharpAdapter:OnWebsocketError (object,WebSocketSharp.ErrorEventArgs) (at Assets/Scripts/WebSocketSharp.cs:66)
WebSocketSharp.Ext:Emit<WebSocketSharp.ErrorEventArgs> (System.EventHandler1<WebSocketSharp.ErrorEventArgs>,object,WebSocketSharp.ErrorEventArgs)
Error Exception: 
System.TypeLoadException: Could not resolve type with token 0100001c (from typeref, class/assembly System.Runtime.CompilerServices.TaskAwaiter, System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
  at Phoenix.Scheduler.ScheduleTimeout () [0x00039] in <76c0f2e7127d47e58aa61f16f390a4ca>:0 
  at Phoenix.Socket.OnConnClose (Phoenix.IWebsocket websocket, System.UInt16 code, System.String reason) [0x00069] in <76c0f2e7127d47e58aa61f16f390a4ca>:0 
  at PhoenixTests.WebSocketImpl.WebsocketSharpAdapter.OnWebsocketClose (System.Object sender, WebSocketSharp.CloseEventArgs args) [0x00000] in

Plugins:
image

Here is the build logs from building PhoenixSharp with Rider: (2 warnings but a dll is created)
image
image

Target Platform: (windows)
image

Editor Version: (2020.3.33f1)
image

Let me know if there is any other information I can give that might be helpful.

Thanks again!

@Mazyod
Copy link
Owner Author

Mazyod commented Apr 20, 2022

I should’ve guessed Windows from the file paths 😅 .. It’s great that you are willing to share your experience! With so much details too.

I’ve created this issue about docs specifically because others had trouble integrating the library, but only mentioned it on social media without details.

So .. Regarding the issue, I will have time later today. I will look into the stuff you shared in detail, and prepare a windows environment from my side. You definitely shouldn’t have to switch OSs, as this library’s main goal is portability!

@Mazyod
Copy link
Owner Author

Mazyod commented Apr 21, 2022

Hey @ekrenzin, I pushed an update that I hope will solve your issue. I didn't have time to test it, just confirmed it compiles in the following environment:

  • Unity 2020.x
  • Windows Platform Target
  • Mono Scripting Backends
  • .NET Standard 2.0.

Let me know how it goes, and if there is anything else that needs attention. I plan to test it more once I get the time.

What Changed?

I've been testing the library with Unity 2022.x, which reached LTS status just weeks back, and it has better support for the latest C# features and API compatibility. It is not reasonable to ask users to upgrade in order to use the library, so using higher compatibility API (lower standard version) was the way to go.

The project now is based on the .NET Standard 2.0, which should be highly compatible with the largest number of platforms and Unity versions. All APIs have been accommodated to that standard level.

What about .NET 4.x?

According to the Unity docs, .NET 4.x should be even more compatible than .NET Standard 2.0, however, I couldn't get it to work locally. I believe it has to do with the csc.rsp file to link additional assemblies used in the code.

I didn't bother research it in detail, because users should use .NET Standard 2.0 when possible, and if they needed .NET 4.x, it means they would probably know how to link the additional assemblies. (This is just an assumption from my side)

@ekrenzin
Copy link

@Mazyod Thank you so much for this update!

I was finally able to get a socket open, and I'm so excited!
image

I really appreciate how fast you implemented the compatibility changes, you are a hero!

@Rotcline
Copy link

Rotcline commented Sep 9, 2023

Hi Mazyod, I want to implement your library on my Unity project but I don't know how in the past days I tried to do it by following the readme but I think I am missing something. I have worked previously with Phoenix Channels on a React Project but right now I don't know what I am doing.
I am following this steps:

  1. Download the repo
  2. Put everything into my assets folder on Unity
  3. Install NUnit, WebSocketSharp and Newtonsoft.Json
  4. Try to connect to my socket
    Would you help me by telling me what step I am missing?
    I am working on a Mac M1 with Mono .Net 2.1 in Rider

Edit:
I can connect to the socket now but this test of the integration tests file is not passing
imagen

@Mazyod
Copy link
Owner Author

Mazyod commented Sep 13, 2023

@Rotcline Hey 👋 Sorry for the late reply. The server for integration tests was down, but now it's up again. I suspect that's the reason for the test failure.

@Rotcline
Copy link

@Mazyod thank you I had trouble with the tests but now is working just fine with my own server

@ChristopherKRad
Copy link

@Mazyod Hello! I'm having some difficulty installing the repo into a blank Unity project.
I'm a complete newbie when it comes to Unity but have some experience with Elixir and Phoenix Live View.
As @Rotcline outlined the steps earlier, I'm a bit unclear as to how to install the dependencies and have been getting a ton of different errors when trying to install the project and haven't yet got to implement my own IWebsocketFactory.

Below is the version of Unity and the approach I have used to install the deps:

Version of Unity 2020.3.15f2

  1. Newtonsoft.Json
  • Installed via git URL
  • Window > Package Manager > Add Package from git URL > com.unity.nuget.newtonsoft-json
  1. WebSocketSharp
  • Added by downloading the latest master branch zip to my Assets directory
  1. NUnit
  • Installed via git URL
  • Window > Package Manager > Add Package from git URL > com.unity.ext.nunit@1.0
  1. PhoenixSharp
  • Added by downloading the latest master branch zip to my Assets directory

@Mazyod
Copy link
Owner Author

Mazyod commented Nov 11, 2023

Sorry about the suboptimal experience with integrating the library, @ChristopherKRad. Happy to help you through this.

I might guess that the error dump you're seeing is probably due to a misconfiguration and/or unnecessary files included in the project. Can you please share a few errors for me to assess?

Otherwise, here is what I did to get the project working on the Unity 2020.3.47 release:

  1. Created a new project
  2. Created a folder "Phoenix" to hold the library files
  3. Added the *.cs files only to that folder.
  4. Added NewtonSoft.json package only using the same approach you did.

Although, I noticed NUnit being there in the project, without me adding it explicitly somehow.

image

@ChristopherKRad
Copy link

I appreciate the swift response @Mazyod :) It's not suboptimal, it's likely due to my lack of familiarity with Unity.

I have a phoenix live view project which is printing "{url: www.example.com}" every 5 seconds and is deployed via fly.io

I've created a sample repo to show what my Assets directory looks like (assume I have the Newtonsoft dependency loaded via the package manager, and am using the example WebSocketSharp and JsonMessageSerializer provided).

Based on my limited understanding, the message should print in the unity console when I hit play, but maybe there's something missing?

I'd appreciate you taking a look at the repo I've created below, and letting me know if there's something I need to change on PhoenixLiveViewConnector.cs

https://github.com/ChristopherKRad/examplePhoenixSharp

@Mazyod
Copy link
Owner Author

Mazyod commented Nov 13, 2023

@ChristopherKRad Also, make sure that you rename the main MonoBehavior script to WebSocketClient.cs then add the script to a game object in the scene (e.g. Main Camera). This will make the script actually run.

I did that then was seeing error logs popup in the console. The errors were related to the set up and communicating with Phoenix LiveView perhaps, so you might have better luck there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants