2021-06-27 01:41:52 +03:00
|
|
|
import express, { Request, Response } from "express";
|
2021-06-27 02:45:40 +03:00
|
|
|
import * as http from 'http';
|
|
|
|
|
import WebSocket from "ws"
|
2021-06-27 19:28:09 +03:00
|
|
|
import { encodeText } from "./rtmt/byte_util";
|
|
|
|
|
import { encode } from "./rtmt/encode_decode_message";
|
|
|
|
|
import { RTMTWS } from "./rtmt/rtmt_websocket";
|
|
|
|
|
import cors from "cors"
|
|
|
|
|
import { generateKey } from "./key_factory";
|
2021-06-27 01:41:52 +03:00
|
|
|
|
|
|
|
|
const app = express();
|
|
|
|
|
|
2021-06-27 19:28:09 +03:00
|
|
|
app.use(cors())
|
2021-06-27 02:45:40 +03:00
|
|
|
|
2021-06-27 19:28:09 +03:00
|
|
|
const server = http.createServer(app);
|
2021-06-27 02:45:40 +03:00
|
|
|
|
2021-06-27 01:41:52 +03:00
|
|
|
app.get("/", (req: Request, res: Response) => {
|
|
|
|
|
res.send("Hello World");
|
|
|
|
|
});
|
|
|
|
|
|
2021-06-27 19:28:09 +03:00
|
|
|
app.get("/register/", (req: Request, res: Response) => {
|
|
|
|
|
res.send(generateKey());
|
|
|
|
|
});
|
|
|
|
|
|
2021-06-27 02:45:40 +03:00
|
|
|
const port = process.env.PORT || 5000
|
|
|
|
|
|
|
|
|
|
server.listen(port, () => {
|
|
|
|
|
console.log(`Server started on port ${port} :)`);
|
|
|
|
|
})
|
2021-06-27 19:28:09 +03:00
|
|
|
|
|
|
|
|
const rtmt = new RTMTWS()
|
|
|
|
|
|
|
|
|
|
rtmt.initWebSocket(server, ()=>{
|
|
|
|
|
|
|
|
|
|
})
|