@cascateer/core 2.2.5 → 2.2.7

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/multicast.ts +24 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cascateer/core",
3
- "version": "2.2.5",
3
+ "version": "2.2.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cascateer/core.git"
package/src/multicast.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { compact } from "lodash";
1
2
  import {
2
3
  combineLatest,
3
4
  groupBy,
@@ -6,6 +7,7 @@ import {
6
7
  mergeMap,
7
8
  Observable,
8
9
  partition,
10
+ startWith,
9
11
  } from "rxjs";
10
12
  import { v4 } from "uuid";
11
13
  import { nonNullable } from "./lib";
@@ -29,7 +31,9 @@ declare global {
29
31
  }
30
32
 
31
33
  const actions = proxyReplaySubject<
32
- Observable<[MulticastConnectMessage<any>, MulticastActionMessage<any>]>,
34
+ Observable<
35
+ [MulticastConnectMessage<any>, MulticastActionMessage<any> | null]
36
+ >,
33
37
  {
34
38
  ports: MessagePort[];
35
39
  action: MulticastActionMessage<any>;
@@ -41,18 +45,20 @@ const actions = proxyReplaySubject<
41
45
  mergeMap((group) =>
42
46
  group.pipe(
43
47
  flatMap(([connect, action], index) =>
44
- index
45
- ? action
46
- : [
47
- {
48
- id: v4(),
49
- type: "seedAction" as const,
50
- data: {
51
- seed: connect.data.seed,
48
+ compact(
49
+ index
50
+ ? [action]
51
+ : [
52
+ {
53
+ id: v4(),
54
+ type: "seedAction" as const,
55
+ data: {
56
+ seed: connect.data.seed,
57
+ },
52
58
  },
53
- },
54
- action,
55
- ],
59
+ action,
60
+ ],
61
+ ),
56
62
  ),
57
63
  concatLeft(),
58
64
  flatMap((actions) =>
@@ -73,7 +79,8 @@ self.addEventListener("connect", ({ ports }) => {
73
79
  actions.next(
74
80
  actions.pipe(
75
81
  flatMap(({ ports, action: { origin, ...message } }) =>
76
- ports.includes(port) && (!message.sameOrigin || origin === port)
82
+ (message.type === "seedAction" || ports.includes(port)) &&
83
+ (!message.sameOrigin || origin === port)
77
84
  ? message
78
85
  : [],
79
86
  ),
@@ -89,7 +96,10 @@ self.addEventListener("connect", ({ ports }) => {
89
96
  map((event) => ({ ...event, origin: port })),
90
97
  (messages) =>
91
98
  combineLatest(
92
- partition(messages, (message) => message.type === "connect"),
99
+ partition(
100
+ messages.pipe(startWith(null)),
101
+ (message) => message?.type === "connect",
102
+ ),
93
103
  ),
94
104
  ),
95
105
  );