coupeeeez 0.0.2 → 0.0.3
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/package.json +2 -1
- package/stream-api/Message.d.ts +7 -0
- package/stream-api/Message.d.ts.map +1 -0
- package/stream-api/Message.js +1 -0
- package/stream-api/SSEInjected.d.ts +3 -0
- package/stream-api/SSEInjected.d.ts.map +1 -0
- package/stream-api/SSEInjected.js +2 -0
- package/stream-api/SSEServer.d.ts +9 -0
- package/stream-api/SSEServer.d.ts.map +1 -0
- package/stream-api/SSEServer.js +28 -0
- package/stream-api/SSEServers.d.ts +12 -0
- package/stream-api/SSEServers.d.ts.map +1 -0
- package/stream-api/SSEServers.js +27 -0
- package/stream-api/StreamApi.d.ts +2 -0
- package/stream-api/StreamApi.d.ts.map +1 -0
- package/stream-api/StreamApi.js +33 -0
- package/stream-api/app.d.ts +2 -0
- package/stream-api/app.d.ts.map +1 -0
- package/stream-api/app.js +9 -0
- package/stream-api/index.d.ts +2 -0
- package/stream-api/index.d.ts.map +1 -0
- package/stream-api/index.js +1 -0
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coupeeeez",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Anthony REY",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
|
+
"prepack": "tsc",
|
|
9
10
|
"start": "node app.ts",
|
|
10
11
|
"build": "npm run stream:build",
|
|
11
12
|
"test:component": "start-server-and-test stream-api:dev \"http://localhost:3005\" stream:dev:component \"http://localhost:3042\" cypress:open",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Message.d.ts","sourceRoot":"","sources":["Message.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CAChB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SSEInjected.d.ts","sourceRoot":"","sources":["SSEInjected.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAE3C,eAAO,MAAM,OAAO,YAAmB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Response } from 'express';
|
|
2
|
+
import type { Message } from "./Message.ts";
|
|
3
|
+
export declare class SSEServer {
|
|
4
|
+
private res;
|
|
5
|
+
private constructor();
|
|
6
|
+
static start(res: Response): SSEServer;
|
|
7
|
+
send<T>(message: Message): void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=SSEServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SSEServer.d.ts","sourceRoot":"","sources":["SSEServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AACtC,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AAE1C,qBAAa,SAAS;IAClB,OAAO,CAAC,GAAG,CAAW;IAEtB,OAAO;IAWP,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,QAAQ;IAI1B,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO;CAe3B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export class SSEServer {
|
|
2
|
+
res;
|
|
3
|
+
constructor(res) {
|
|
4
|
+
this.res = res;
|
|
5
|
+
const headers = {
|
|
6
|
+
'Content-Type': 'text/event-stream',
|
|
7
|
+
Connection: 'keep-alive',
|
|
8
|
+
'Cache-Control': 'no-cache'
|
|
9
|
+
};
|
|
10
|
+
this.res.writeHead(200, headers);
|
|
11
|
+
}
|
|
12
|
+
static start(res) {
|
|
13
|
+
return new SSEServer(res);
|
|
14
|
+
}
|
|
15
|
+
send(message) {
|
|
16
|
+
const { id, type = 'message', retry, data } = message;
|
|
17
|
+
if (id) {
|
|
18
|
+
this.res.write(`id: ${id}\n`);
|
|
19
|
+
}
|
|
20
|
+
if (type) {
|
|
21
|
+
this.res.write(`event: ${type}\n`);
|
|
22
|
+
}
|
|
23
|
+
if (retry) {
|
|
24
|
+
this.res.write(`retry: ${retry}\n`);
|
|
25
|
+
}
|
|
26
|
+
this.res.write(`data: ${JSON.stringify(data)}\n\n`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Response } from 'express';
|
|
2
|
+
import type { Message } from "./Message.ts";
|
|
3
|
+
export declare class SSEServers {
|
|
4
|
+
private readonly servers;
|
|
5
|
+
constructor();
|
|
6
|
+
open(clientId: string, res: Response): void;
|
|
7
|
+
delete(clientId: string): void;
|
|
8
|
+
deleteAll(): void;
|
|
9
|
+
broadcast(message: Message): void;
|
|
10
|
+
private unicast;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=SSEServers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SSEServers.d.ts","sourceRoot":"","sources":["SSEServers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AACtC,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AAE1C,qBAAa,UAAU;IACnB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;;IAKjD,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ;IAIpC,MAAM,CAAC,QAAQ,EAAE,MAAM;IAIvB,SAAS;IAKT,SAAS,CAAC,OAAO,EAAE,OAAO;IAM1B,OAAO,CAAC,OAAO;CAMlB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SSEServer } from "./SSEServer.js";
|
|
2
|
+
export class SSEServers {
|
|
3
|
+
servers;
|
|
4
|
+
constructor() {
|
|
5
|
+
this.servers = new Map();
|
|
6
|
+
}
|
|
7
|
+
open(clientId, res) {
|
|
8
|
+
this.servers.set(clientId, SSEServer.start(res));
|
|
9
|
+
}
|
|
10
|
+
delete(clientId) {
|
|
11
|
+
this.servers.delete(clientId);
|
|
12
|
+
}
|
|
13
|
+
deleteAll() {
|
|
14
|
+
this.servers.clear();
|
|
15
|
+
}
|
|
16
|
+
broadcast(message) {
|
|
17
|
+
for (const [id] of this.servers) {
|
|
18
|
+
this.unicast(id, message);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
unicast(clientId, message) {
|
|
22
|
+
if (!this.servers.has(clientId)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
this.servers.get(clientId).send(message);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StreamApi.d.ts","sourceRoot":"","sources":["StreamApi.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,SAAS,kDAkCrB,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import { servers } from "./SSEInjected.js";
|
|
3
|
+
import short from "short-uuid";
|
|
4
|
+
export const streamApi = () => {
|
|
5
|
+
const router = express.Router();
|
|
6
|
+
router.use(express.json());
|
|
7
|
+
router.post('/api/movie', (req, res) => {
|
|
8
|
+
servers.broadcast({
|
|
9
|
+
type: 'movie.open',
|
|
10
|
+
data: {
|
|
11
|
+
name: req.body.name,
|
|
12
|
+
image: req.body.image,
|
|
13
|
+
year: req.body.year
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
res.send('Opened');
|
|
17
|
+
});
|
|
18
|
+
router.get('/api/movie', (req, res) => {
|
|
19
|
+
const uuid = short.generate();
|
|
20
|
+
servers.open(uuid, res);
|
|
21
|
+
req.on('close', () => {
|
|
22
|
+
servers.delete(uuid);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
router.delete('/api/movie', (req, res) => {
|
|
26
|
+
servers.broadcast({
|
|
27
|
+
type: 'movie.close',
|
|
28
|
+
data: { status: "closed" }
|
|
29
|
+
});
|
|
30
|
+
res.send('Closed');
|
|
31
|
+
});
|
|
32
|
+
return router;
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["app.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { streamApi } from "./StreamApi.js";
|
|
3
|
+
const app = express();
|
|
4
|
+
const port = 3005;
|
|
5
|
+
app.get('/', (_, res) => res.send('Stream API'));
|
|
6
|
+
app.use(streamApi());
|
|
7
|
+
app.listen(port, () => {
|
|
8
|
+
console.log(`Example app listening on port ${port}`);
|
|
9
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { streamApi } from "./StreamApi.js";
|