Skip to content

Commit

Permalink
Improved stability cookie-ids when doing page transition.
Browse files Browse the repository at this point in the history
  • Loading branch information
kekyo committed May 23, 2024
1 parent f64ebfe commit 4acec2f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 2 additions & 3 deletions DupeNukem.Core/Messenger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public class Messenger : IMessenger, IDisposable
private readonly TimeSpan timeoutDuration;
private readonly Timer timeoutTimer;
private readonly FinalizationRegistry peerClosureRegistry;
private volatile int id;

[EditorBrowsable(EditorBrowsableState.Never)]
public NamingStrategy MemberAccessNamingStrategy { get; }
Expand Down Expand Up @@ -213,7 +212,7 @@ public string[] RegisteredMethods

internal string RegisterHostClosure(Delegate closure)
{
var name = "closure_$" + Interlocked.Increment(ref this.id);
var name = $"closure_${Guid.NewGuid().ToString("N").ToLowerInvariant()}";
this.RegisterMethod(
name,
new DynamicFunctionDescriptor(closure, this),
Expand Down Expand Up @@ -315,7 +314,7 @@ private void SendInvokeMessageToPeer(
}
}

var id = "host_" + Interlocked.Increment(ref this.id);
var id = $"host_${Guid.NewGuid().ToString("N").ToLowerInvariant()}";

ct.Register(() =>
{
Expand Down
7 changes: 3 additions & 4 deletions DupeNukem/Script.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ var __dupeNukem_Messenger__ =
__dupeNukem_Messenger__ || new (function () {

this.suspendings__ = new Map();
this.id__ = 0;
this.debugLog__ = false;
this.isInitialized__ = false;

Expand Down Expand Up @@ -63,7 +62,7 @@ var __dupeNukem_Messenger__ =

this.constructClosure__ = f => {
if (f.__dupeNukem_id__ === undefined) {
const closureId = "closure_$" + (this.id__++);
const closureId = "closure_$" + crypto.randomUUID().toString().replaceAll("-", "");
f.__dupeNukem_id__ = closureId;
window.__peerClosures__[closureId] = f;
const name = "__peerClosures__." + closureId;
Expand All @@ -83,7 +82,7 @@ var __dupeNukem_Messenger__ =

this.constructAbortSignal__ = signal => {
if (signal.__dupeNukem_id__ === undefined) {
const signalId = "abortSignal_$" + (this.id__++);
const signalId = "abortSignal_$" + crypto.randomUUID().toString().replaceAll("-", "");
signal.__dupeNukem_id__ = signalId;
if (!signal.aborted) {
signal.addEventListener(
Expand Down Expand Up @@ -277,7 +276,7 @@ var __dupeNukem_Messenger__ =
this.invokeHostMethod__ = (name, args) => {
const rargs = args.map(this.normalizeObjects__);
return new Promise((resolve, reject) => {
const id = "client_" + (this.id__++);
const id = "client_$" + crypto.randomUUID().toString().replaceAll("-", "");
try {
const descriptor = { resolve: resolve, reject: reject, };
this.suspendings__.set(id, descriptor);
Expand Down

0 comments on commit 4acec2f

Please sign in to comment.