wirejs-deploy-amplify-basic 0.0.102-realtime → 0.0.104-realtime
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/client/realtime.js
CHANGED
|
@@ -48,9 +48,10 @@ export function subscribe(url, channel, token, authHost, subscriber) {
|
|
|
48
48
|
ws.onmessage = event => {
|
|
49
49
|
const data = JSON.parse(event.data);
|
|
50
50
|
if (data.type === 'data') {
|
|
51
|
+
const eventData = JSON.parse(data.event);
|
|
51
52
|
for (const subscriber of subscribers.get(data.id) || []) {
|
|
52
53
|
try {
|
|
53
|
-
subscriber.onmessage(
|
|
54
|
+
subscriber.onmessage(eventData);
|
|
54
55
|
}
|
|
55
56
|
catch (error) {
|
|
56
57
|
console.error('Error in subscriber onmessage:', error);
|
|
@@ -91,7 +92,7 @@ export function subscribe(url, channel, token, authHost, subscriber) {
|
|
|
91
92
|
authorization
|
|
92
93
|
}));
|
|
93
94
|
channelSubs.set(fullChannelName, subscriptionId);
|
|
94
|
-
subscribers.set(subscriptionId, []);
|
|
95
|
+
subscribers.set(subscriptionId, [subscriber]);
|
|
95
96
|
};
|
|
96
97
|
if (ws.readyState === WebSocket.OPEN) {
|
|
97
98
|
subscribe();
|
|
@@ -100,7 +101,9 @@ export function subscribe(url, channel, token, authHost, subscriber) {
|
|
|
100
101
|
ws.addEventListener('open', subscribe);
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
|
-
|
|
104
|
+
else {
|
|
105
|
+
subscribers.get(fullChannelName).push(subscriber);
|
|
106
|
+
}
|
|
104
107
|
}
|
|
105
108
|
export function unsubscribe(url, channel, subscriber) {
|
|
106
109
|
const fullChannelName = `${url}#${channel}`;
|
|
@@ -86,11 +86,8 @@ export class RealtimeService extends Resource {
|
|
|
86
86
|
'x-amz-date': new Date().toISOString(),
|
|
87
87
|
},
|
|
88
88
|
body: JSON.stringify({
|
|
89
|
-
channel
|
|
90
|
-
events:
|
|
91
|
-
channel: `${this.#namespace}/${channel}`,
|
|
92
|
-
events: events.map(event => JSON.stringify(event))
|
|
93
|
-
},
|
|
89
|
+
channel: `${this.#namespace}/${channel}`,
|
|
90
|
+
events: events.map(event => JSON.stringify(event))
|
|
94
91
|
}),
|
|
95
92
|
});
|
|
96
93
|
const signedRequest = await signer.sign(request);
|
|
@@ -105,17 +102,17 @@ export class RealtimeService extends Resource {
|
|
|
105
102
|
}
|
|
106
103
|
async getStream(channel) {
|
|
107
104
|
this.#validateChannelName(channel);
|
|
108
|
-
const channelString =
|
|
109
|
-
const payload = { channel };
|
|
105
|
+
const channelString = `${this.#namespace}/${channel}`;
|
|
106
|
+
const payload = { channel: `/${channelString}` };
|
|
110
107
|
const jwt = await new jose.SignJWT(payload)
|
|
111
108
|
.setProtectedHeader({ alg: 'HS256' })
|
|
112
109
|
.setIssuedAt()
|
|
113
|
-
.setExpirationTime(`
|
|
110
|
+
.setExpirationTime(`30s`)
|
|
114
111
|
.sign(new TextEncoder().encode(await this.#secret.read()));
|
|
115
112
|
return {
|
|
116
113
|
__wjstype: 'realtime',
|
|
117
114
|
url: this.address,
|
|
118
|
-
channel:
|
|
115
|
+
channel: channelString,
|
|
119
116
|
token: jwt,
|
|
120
117
|
authHost: process.env.REALTIME_HTTP_DOMAIN,
|
|
121
118
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wirejs-deploy-amplify-basic",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.104-realtime",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"recursive-copy": "^2.0.14",
|
|
42
42
|
"rimraf": "^6.0.1",
|
|
43
43
|
"wirejs-dom": "^1.0.41",
|
|
44
|
-
"wirejs-resources": "^0.1.
|
|
44
|
+
"wirejs-resources": "^0.1.72-realtime"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@aws-amplify/backend": "^1.14.0",
|