Better Guides
Mazyod opened this issue · 13 comments
I think the library is missing detailed guides to help developers more easily integrate the library with their project. Need to fix that.
@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:
When I attempt to import the source code manually I run into other assembly reference errors:
I believe I've properly set my project to .NET 4.x
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!
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.
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?
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
Here is the build logs from building PhoenixSharp with Rider: (2 warnings but a dll is created)
Let me know if there is any other information I can give that might be helpful.
Thanks again!
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!
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)
@Mazyod Thank you so much for this update!
I was finally able to get a socket open, and I'm so excited!
I really appreciate how fast you implemented the compatibility changes, you are a hero!
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:
- Download the repo
- Put everything into my assets folder on Unity
- Install NUnit, WebSocketSharp and Newtonsoft.Json
- 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
@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.
@Mazyod thank you I had trouble with the tests but now is working just fine with my own server
@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
- Newtonsoft.Json
- Installed via git URL
- Window > Package Manager > Add Package from git URL > com.unity.nuget.newtonsoft-json
- WebSocketSharp
- Added by downloading the latest master branch zip to my Assets directory
- NUnit
- Installed via git URL
- Window > Package Manager > Add Package from git URL > com.unity.ext.nunit@1.0
- PhoenixSharp
- Added by downloading the latest master branch zip to my Assets directory
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:
- Created a new project
- Created a folder "Phoenix" to hold the library files
- Added the *.cs files only to that folder.
- 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.
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
@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.