@livestore/devtools-web-common 0.3.0-dev.37 → 0.3.0-dev.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/web-channel/index.d.ts +35 -37
- package/dist/web-channel/index.d.ts.map +1 -1
- package/dist/web-channel/index.js +33 -19
- package/dist/web-channel/index.js.map +1 -1
- package/dist/worker/mod.js +1 -1
- package/dist/worker/mod.js.map +1 -1
- package/package.json +4 -4
- package/src/web-channel/index.ts +43 -58
- package/src/worker/mod.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UnexpectedError } from '@livestore/common';
|
|
1
|
+
import { Devtools, UnexpectedError } from '@livestore/common';
|
|
2
2
|
import type { Scope, Worker } from '@livestore/utils/effect';
|
|
3
3
|
import { Effect, Schema, WebChannel } from '@livestore/utils/effect';
|
|
4
4
|
import type { MeshNode } from '@livestore/webmesh';
|
|
@@ -7,46 +7,44 @@ export * as WorkerSchema from '../worker/schema.js';
|
|
|
7
7
|
declare global {
|
|
8
8
|
var __debugWebmeshNode: any;
|
|
9
9
|
}
|
|
10
|
-
export declare const
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
readonly _tag: "SessionInfo";
|
|
22
|
-
readonly storeId: string;
|
|
23
|
-
readonly clientId: string;
|
|
24
|
-
readonly sessionId: string;
|
|
25
|
-
readonly schemaAlias: string;
|
|
26
|
-
}, never>, never, Scope.Scope>;
|
|
27
|
-
export declare const ClientSessionRequestContentscriptMain: Schema.TaggedStruct<"ClientSessionRequestContentscriptMain", {
|
|
10
|
+
export declare const makeSessionInfoBroadcastChannel: Effect.Effect<WebChannel.WebChannel<Devtools.SessionInfo.Message, Devtools.SessionInfo.Message>, UnexpectedError, Scope.Scope>;
|
|
11
|
+
export declare const makeNodeName: {
|
|
12
|
+
sharedWorker: ({ storeId }: {
|
|
13
|
+
storeId: string;
|
|
14
|
+
}) => string;
|
|
15
|
+
browserExtension: {
|
|
16
|
+
contentscriptMain: (tabId: number) => string;
|
|
17
|
+
contentscriptIframe: (tabId: number) => string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export declare const ClientSessionContentscriptMainReq: Schema.TaggedStruct<"ClientSessionContentscriptMainReq", {
|
|
28
21
|
storeId: typeof Schema.String;
|
|
29
22
|
clientId: typeof Schema.String;
|
|
30
23
|
sessionId: typeof Schema.String;
|
|
31
24
|
}>;
|
|
32
|
-
export
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
25
|
+
export declare const ClientSessionContentscriptMainRes: Schema.TaggedStruct<"ClientSessionContentscriptMainRes", {
|
|
26
|
+
tabId: typeof Schema.Number;
|
|
27
|
+
}>;
|
|
28
|
+
export declare const makeStaticClientSessionChannel: {
|
|
29
|
+
contentscriptMain: Effect.Effect<WebChannel.WebChannel<{
|
|
30
|
+
readonly _tag: "ClientSessionContentscriptMainReq";
|
|
31
|
+
readonly storeId: string;
|
|
32
|
+
readonly clientId: string;
|
|
33
|
+
readonly sessionId: string;
|
|
34
|
+
}, {
|
|
35
|
+
readonly _tag: "ClientSessionContentscriptMainRes";
|
|
36
|
+
readonly tabId: number;
|
|
37
|
+
}, never>, never, Scope.Scope>;
|
|
38
|
+
clientSession: Effect.Effect<WebChannel.WebChannel<{
|
|
39
|
+
readonly _tag: "ClientSessionContentscriptMainRes";
|
|
40
|
+
readonly tabId: number;
|
|
41
|
+
}, {
|
|
42
|
+
readonly _tag: "ClientSessionContentscriptMainReq";
|
|
43
|
+
readonly storeId: string;
|
|
44
|
+
readonly clientId: string;
|
|
45
|
+
readonly sessionId: string;
|
|
46
|
+
}, never>, never, Scope.Scope>;
|
|
47
|
+
};
|
|
50
48
|
export declare const connectViaWorker: ({ node, target, worker, }: {
|
|
51
49
|
node: MeshNode;
|
|
52
50
|
target: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/web-channel/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/web-channel/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAE7D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAY,MAAM,EAAE,MAAM,EAAU,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACtF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAGlD,OAAO,KAAK,YAAY,MAAM,qBAAqB,CAAA;AAEnD,OAAO,KAAK,YAAY,MAAM,qBAAqB,CAAA;AAEnD,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,kBAAkB,EAAE,GAAG,CAAA;CAC5B;AAED,eAAO,MAAM,+BAA+B,EAAE,MAAM,CAAC,MAAM,CACzD,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,EACjF,eAAe,EACf,KAAK,CAAC,KAAK,CAIX,CAAA;AAEF,eAAO,MAAM,YAAY;gCACK;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE;;mCAIlB,MAAM;qCACJ,MAAM;;CAEtC,CAAA;AAED,eAAO,MAAM,iCAAiC;;;;EAI5C,CAAA;AAEF,eAAO,MAAM,iCAAiC;;EAE5C,CAAA;AAGF,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;CAqB1C,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,2BAI9B;IACD,IAAI,EAAE,QAAQ,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAC,oBAAoB,CAAC,OAAO,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;CACtE,sDA+B8C,CAAA"}
|
|
@@ -1,35 +1,49 @@
|
|
|
1
1
|
import { Devtools, UnexpectedError } from '@livestore/common';
|
|
2
2
|
import { LS_DEV } from '@livestore/utils';
|
|
3
3
|
import { Deferred, Effect, Schema, Stream, WebChannel } from '@livestore/utils/effect';
|
|
4
|
-
import {
|
|
4
|
+
import { WebmeshSchema } from '@livestore/webmesh';
|
|
5
5
|
import * as WorkerSchema from '../worker/schema.js';
|
|
6
6
|
export * as WorkerSchema from '../worker/schema.js';
|
|
7
|
-
export const
|
|
7
|
+
export const makeSessionInfoBroadcastChannel = WebChannel.broadcastChannel({
|
|
8
8
|
channelName: 'session-info',
|
|
9
9
|
schema: Devtools.SessionInfo.Message,
|
|
10
10
|
});
|
|
11
|
-
export const
|
|
11
|
+
export const makeNodeName = {
|
|
12
|
+
sharedWorker: ({ storeId }) => `shared-worker-${storeId}`,
|
|
13
|
+
// TODO refactor shared-worker setup so there's only a single shared-worker per origin
|
|
14
|
+
// sharedWorker: () => `shared-worker`,
|
|
15
|
+
browserExtension: {
|
|
16
|
+
contentscriptMain: (tabId) => `contentscript-main-${tabId}`,
|
|
17
|
+
contentscriptIframe: (tabId) => `contentscript-iframe-${tabId}`,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
export const ClientSessionContentscriptMainReq = Schema.TaggedStruct('ClientSessionContentscriptMainReq', {
|
|
12
21
|
storeId: Schema.String,
|
|
13
22
|
clientId: Schema.String,
|
|
14
23
|
sessionId: Schema.String,
|
|
15
24
|
});
|
|
16
|
-
export const
|
|
17
|
-
|
|
18
|
-
yield* connectViaWorker({ node, target, worker });
|
|
19
|
-
return node;
|
|
25
|
+
export const ClientSessionContentscriptMainRes = Schema.TaggedStruct('ClientSessionContentscriptMainRes', {
|
|
26
|
+
tabId: Schema.Number,
|
|
20
27
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
// Effect.suspend is needed since `window` is not available in the shared worker
|
|
29
|
+
export const makeStaticClientSessionChannel = {
|
|
30
|
+
contentscriptMain: Effect.suspend(() => WebChannel.windowChannel({
|
|
31
|
+
// eslint-disable-next-line unicorn/prefer-global-this
|
|
32
|
+
listenWindow: window,
|
|
33
|
+
// eslint-disable-next-line unicorn/prefer-global-this
|
|
34
|
+
sendWindow: window,
|
|
35
|
+
schema: { listen: ClientSessionContentscriptMainReq, send: ClientSessionContentscriptMainRes },
|
|
36
|
+
ids: { own: 'contentscript-main-static', other: 'client-session-static' },
|
|
37
|
+
})),
|
|
38
|
+
clientSession: Effect.suspend(() => WebChannel.windowChannel({
|
|
39
|
+
// eslint-disable-next-line unicorn/prefer-global-this
|
|
40
|
+
listenWindow: window,
|
|
41
|
+
// eslint-disable-next-line unicorn/prefer-global-this
|
|
42
|
+
sendWindow: window,
|
|
43
|
+
schema: { listen: ClientSessionContentscriptMainRes, send: ClientSessionContentscriptMainReq },
|
|
44
|
+
ids: { own: 'client-session-static', other: 'contentscript-main-static' },
|
|
45
|
+
})),
|
|
46
|
+
};
|
|
33
47
|
export const connectViaWorker = ({ node, target, worker, }) => Effect.gen(function* () {
|
|
34
48
|
const mc = new MessageChannel();
|
|
35
49
|
const isConnected = yield* Deferred.make();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/web-channel/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,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EAAE,CAAC;QACX,KAAK,CAAC,CAAC,MAAM,CAAC,eAAe,CAC3B,2DAA2D,IAAI,CAAC,QAAQ,MAAM,MAAM,EAAE,CACvF,CAAA;IACH,CAAC;IAED,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CACrG,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,EACrD,MAAM,CAAC,QAAQ,EACf,MAAM,CAAC,iBAAiB,EACxB,MAAM,CAAC,UAAU,CAClB,CAAA;IAED,KAAK,CAAC,CAAC,WAAW,CAAA;IAElB,MAAM,sBAAsB,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,kBAAkB,CAAC;QAClE,IAAI,EAAE,EAAE,CAAC,KAAK;QACd,MAAM,EAAE,aAAa,CAAC,MAAM;KAC7B,CAAC,CAAA;IAEF,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,sBAAsB,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,CAAA;IAE3F,IAAI,MAAM,EAAE,CAAC;QACX,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,yDAAyD,IAAI,CAAC,QAAQ,MAAM,MAAM,EAAE,CAAC,CAAA;IAC9G,CAAC;AACH,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,CAAA"}
|
package/dist/worker/mod.js
CHANGED
|
@@ -14,7 +14,7 @@ export const CreateConnection = ({ from, port }) => Stream.asyncScoped((emit) =>
|
|
|
14
14
|
const messagePortChannel = yield* WebChannel.messagePortChannel({ port, schema: WebmeshSchema.Packet });
|
|
15
15
|
yield* node.addEdge({ target: from, edgeChannel: messagePortChannel, replaceIfExists: true });
|
|
16
16
|
if (LS_DEV) {
|
|
17
|
-
yield* Effect.logDebug(`@livestore/devtools-web-common: accepted
|
|
17
|
+
yield* Effect.logDebug(`@livestore/devtools-web-common: accepted edge: ${node.nodeName} ← ${from}`);
|
|
18
18
|
}
|
|
19
19
|
emit.single({});
|
|
20
20
|
yield* Effect.spanEvent({ connectedTo: [...node.edgeKeys] });
|
package/dist/worker/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/worker/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEpF,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAIhE,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,MAAM,OAAO,YAAa,SAAQ,OAAO,CAAC,GAAG,CAAC,6CAA6C,CAAC,EAGzF;IACD,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,QAAQ,EAAwB,EAAE,EAAE,CACpD,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAClB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;QAE1C,UAAU,CAAC,kBAAkB,GAAG,IAAI,CAAA;QAEpC,OAAO,EAAE,IAAI,EAAE,CAAA;IACjB,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;;AAGvC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,EAAmD,EAAE,EAAE,CAClG,MAAM,CAAC,WAAW,CAA0B,CAAC,IAAI,EAAE,EAAE,CACnD,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|
|
6
6
|
"exports": {
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@livestore/
|
|
18
|
-
"@livestore/
|
|
19
|
-
"@livestore/
|
|
17
|
+
"@livestore/utils": "0.3.0-dev.38",
|
|
18
|
+
"@livestore/common": "0.3.0-dev.38",
|
|
19
|
+
"@livestore/webmesh": "0.3.0-dev.38"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {},
|
|
22
22
|
"files": [
|
package/src/web-channel/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { LS_DEV } from '@livestore/utils'
|
|
|
3
3
|
import type { Scope, Worker } from '@livestore/utils/effect'
|
|
4
4
|
import { Deferred, Effect, Schema, Stream, WebChannel } from '@livestore/utils/effect'
|
|
5
5
|
import type { MeshNode } from '@livestore/webmesh'
|
|
6
|
-
import {
|
|
6
|
+
import { WebmeshSchema } from '@livestore/webmesh'
|
|
7
7
|
|
|
8
8
|
import * as WorkerSchema from '../worker/schema.js'
|
|
9
9
|
|
|
@@ -14,73 +14,58 @@ declare global {
|
|
|
14
14
|
var __debugWebmeshNode: any
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export const
|
|
17
|
+
export const makeSessionInfoBroadcastChannel: Effect.Effect<
|
|
18
|
+
WebChannel.WebChannel<Devtools.SessionInfo.Message, Devtools.SessionInfo.Message>,
|
|
19
|
+
UnexpectedError,
|
|
20
|
+
Scope.Scope
|
|
21
|
+
> = WebChannel.broadcastChannel({
|
|
18
22
|
channelName: 'session-info',
|
|
19
23
|
schema: Devtools.SessionInfo.Message,
|
|
20
24
|
})
|
|
21
25
|
|
|
22
|
-
export const
|
|
26
|
+
export const makeNodeName = {
|
|
27
|
+
sharedWorker: ({ storeId }: { storeId: string }) => `shared-worker-${storeId}`,
|
|
28
|
+
// TODO refactor shared-worker setup so there's only a single shared-worker per origin
|
|
29
|
+
// sharedWorker: () => `shared-worker`,
|
|
30
|
+
browserExtension: {
|
|
31
|
+
contentscriptMain: (tabId: number) => `contentscript-main-${tabId}`,
|
|
32
|
+
contentscriptIframe: (tabId: number) => `contentscript-iframe-${tabId}`,
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const ClientSessionContentscriptMainReq = Schema.TaggedStruct('ClientSessionContentscriptMainReq', {
|
|
23
37
|
storeId: Schema.String,
|
|
24
38
|
clientId: Schema.String,
|
|
25
39
|
sessionId: Schema.String,
|
|
26
40
|
})
|
|
27
|
-
export type ClientSessionRequestContentscriptMain = typeof ClientSessionRequestContentscriptMain.Type
|
|
28
|
-
|
|
29
|
-
export const makeWebDevtoolsConnectedMeshNode = ({
|
|
30
|
-
nodeName,
|
|
31
|
-
target,
|
|
32
|
-
worker,
|
|
33
|
-
}: {
|
|
34
|
-
nodeName: string
|
|
35
|
-
target: string
|
|
36
|
-
worker: Worker.SerializedWorkerPool<typeof WorkerSchema.Request.Type>
|
|
37
|
-
}) =>
|
|
38
|
-
Effect.gen(function* () {
|
|
39
|
-
const node = yield* makeMeshNode(nodeName)
|
|
40
|
-
|
|
41
|
-
yield* connectViaWorker({ node, target, worker })
|
|
42
|
-
|
|
43
|
-
return node
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
export const makeChannelForConnectedMeshNode = <MsgListen, MsgSend, MsgListenEncoded, MsgSendEncoded>({
|
|
47
|
-
target,
|
|
48
|
-
node,
|
|
49
|
-
schema,
|
|
50
|
-
}: {
|
|
51
|
-
node: MeshNode
|
|
52
|
-
target: string
|
|
53
|
-
schema: WebChannel.InputSchema<MsgListen, MsgSend, MsgListenEncoded, MsgSendEncoded>
|
|
54
|
-
}) =>
|
|
55
|
-
node.makeChannel({
|
|
56
|
-
target,
|
|
57
|
-
channelName: 'devtools(' + [node.nodeName, target].sort().join('↔') + ')',
|
|
58
|
-
schema,
|
|
59
|
-
mode: 'messagechannel',
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
export const makeWebDevtoolsChannel = <MsgListen, MsgSend, MsgListenEncoded, MsgSendEncoded>({
|
|
63
|
-
nodeName,
|
|
64
|
-
target,
|
|
65
|
-
schema,
|
|
66
|
-
worker,
|
|
67
|
-
workerTargetName,
|
|
68
|
-
}: {
|
|
69
|
-
nodeName: string
|
|
70
|
-
target: string
|
|
71
|
-
schema: WebChannel.InputSchema<MsgListen, MsgSend, MsgListenEncoded, MsgSendEncoded>
|
|
72
|
-
worker: Worker.SerializedWorkerPool<typeof WorkerSchema.Request.Type>
|
|
73
|
-
workerTargetName: string
|
|
74
|
-
}): Effect.Effect<WebChannel.WebChannel<MsgListen, MsgSend>, UnexpectedError, Scope.Scope> =>
|
|
75
|
-
Effect.gen(function* () {
|
|
76
|
-
const node = yield* makeWebDevtoolsConnectedMeshNode({ nodeName, target: workerTargetName, worker })
|
|
77
41
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
42
|
+
export const ClientSessionContentscriptMainRes = Schema.TaggedStruct('ClientSessionContentscriptMainRes', {
|
|
43
|
+
tabId: Schema.Number,
|
|
44
|
+
})
|
|
81
45
|
|
|
82
|
-
|
|
83
|
-
|
|
46
|
+
// Effect.suspend is needed since `window` is not available in the shared worker
|
|
47
|
+
export const makeStaticClientSessionChannel = {
|
|
48
|
+
contentscriptMain: Effect.suspend(() =>
|
|
49
|
+
WebChannel.windowChannel({
|
|
50
|
+
// eslint-disable-next-line unicorn/prefer-global-this
|
|
51
|
+
listenWindow: window,
|
|
52
|
+
// eslint-disable-next-line unicorn/prefer-global-this
|
|
53
|
+
sendWindow: window,
|
|
54
|
+
schema: { listen: ClientSessionContentscriptMainReq, send: ClientSessionContentscriptMainRes },
|
|
55
|
+
ids: { own: 'contentscript-main-static', other: 'client-session-static' },
|
|
56
|
+
}),
|
|
57
|
+
),
|
|
58
|
+
clientSession: Effect.suspend(() =>
|
|
59
|
+
WebChannel.windowChannel({
|
|
60
|
+
// eslint-disable-next-line unicorn/prefer-global-this
|
|
61
|
+
listenWindow: window,
|
|
62
|
+
// eslint-disable-next-line unicorn/prefer-global-this
|
|
63
|
+
sendWindow: window,
|
|
64
|
+
schema: { listen: ClientSessionContentscriptMainRes, send: ClientSessionContentscriptMainReq },
|
|
65
|
+
ids: { own: 'client-session-static', other: 'contentscript-main-static' },
|
|
66
|
+
}),
|
|
67
|
+
),
|
|
68
|
+
}
|
|
84
69
|
|
|
85
70
|
export const connectViaWorker = ({
|
|
86
71
|
node,
|
package/src/worker/mod.ts
CHANGED
|
@@ -31,7 +31,7 @@ export const CreateConnection = ({ from, port }: typeof SharedWorkerSchema.Creat
|
|
|
31
31
|
yield* node.addEdge({ target: from, edgeChannel: messagePortChannel, replaceIfExists: true })
|
|
32
32
|
|
|
33
33
|
if (LS_DEV) {
|
|
34
|
-
yield* Effect.logDebug(`@livestore/devtools-web-common: accepted
|
|
34
|
+
yield* Effect.logDebug(`@livestore/devtools-web-common: accepted edge: ${node.nodeName} ← ${from}`)
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
emit.single({})
|