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

Rewrite 2022 #20

Merged
merged 90 commits into from
Apr 18, 2022
Merged

Rewrite 2022 #20

merged 90 commits into from
Apr 18, 2022

Conversation

Mazyod
Copy link
Owner

@Mazyod Mazyod commented Mar 23, 2022

Attempt to rewrite to match new PhoenixJS implementation.

Fixes #1
Fixes #4
Fixes #19

TODO

  • Implement Presence
  • Add Presence tests
  • Consider async/await API
  • Check automatic error recovery functionality (!closeWasClean && code != 1_000)
  • Test on actual Unity project
  • Add more helpers / utils (cp script, BestHTTP adapter, Delayed Executor, …)
  • Update readme and migration process (vsn 2.0.0 serialization)

Background

This library was initially written back in 2017 or something, when I had a lot more free time on my hands. I had refactored a lot of bits and written them differently than how they were implemented on Phoenix JS.

Now in 2022, Phoenix JS is much more mature and stable implementation, and using it as a reference implementation will help support the maintainability of this project (I hope!). This also unlocks benefits of new Phoenix JS features to be easily migrated almost line by line.

As much as any developer out there, I dislike breaking changes. However, after 5 years, this library is due for one big rewrite to restructure the internals better, and upgrade the syntax for a new C# language version as supported by Unity. Not to mention, I think I learned a thing or two in those five years, so the code should be of higher quality and performance, generally speaking. Finally, it should also be .NET Core compatible for portability and CI support for tests and coverage.

Regardless, I haven't seen what other developers in the OSS community out there have put out during this time. So if anyone know of a better library that solves the problem this project hopes to address, please share.

when migrating from PhoenixJS, I only added the unsubscribe code but didn't remove channel from socket channels array
when joining a new channel, I need to make sure to filter duplicates from socket based on the state as per PhoenixJS
@Mazyod
Copy link
Owner Author

Mazyod commented Mar 24, 2022

This PR is failing the integration tests at the very last step...
Once that is also hopefully resolved, will migrate tests from PhoenixJS as well to make sure this rewrite doesn't cause more problems than it solves.

@Mazyod
Copy link
Owner Author

Mazyod commented Mar 26, 2022

🟢

@Mazyod
Copy link
Owner Author

Mazyod commented Mar 28, 2022

Fixes #19

This was referenced Mar 28, 2022
instead of shoe horning the onMessage callbacks into Message object, I should introduce a generic approach. Perhaps it's just an object, it can even be a string not necessarily an object, which can then be parsed into an arbitrary type.
@Mazyod
Copy link
Owner Author

Mazyod commented Apr 12, 2022

Finally tested and working on an actual unity project 🎉

@arne-schroppe
Copy link

Finally tested and working on an actual unity project 🎉

Nice! 🥳 I'll try this updated version in our project when I find the time, but it could take a few days

Just grab them from NuGet
Also, forces us not to use ToString, which is much less performant than a simple switch with static strings
Also, switch from TimerDelayedExecutor to TaskDelayedExecutor

1. DelayedExecutor now returns an interface IDelayedExecution.
This allows custom implementations of IDelayedExecutor to roll out their own DelayedExecution context

2. TimerDelayedExecutor is replaced with TaskDelayedExecutor.
Using Tasks fits the use case better and paves the way for async/await APIs and synchronizationContext approach to leverage directly with unity as well.
- Reformat the whole project to be based on C# standards (as per Rider)
- increase test coverage and cleanup test assertions
This weird trick makes the callback on the same thread in Unity
@Mazyod
Copy link
Owner Author

Mazyod commented Apr 18, 2022

I think this PR dragged on for long enough 😅 .. Will merge it in order to get it into as many users hands as possible. The feedback will hopefully help us reach v1.0 faster.

@Mazyod Mazyod merged commit 91ae8e5 into master Apr 18, 2022
@Mazyod Mazyod deleted the feature/rewrite-2022 branch April 19, 2022 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants