feat: remove deprecated XHR fallback
BREAKING CHANGE: Requires PeerJS >= 1.0
This commit is contained in:
parent
5d882dd0c6
commit
d900145901
1
package-lock.json
generated
1
package-lock.json
generated
@ -9,7 +9,6 @@
|
|||||||
"version": "0.0.0-development",
|
"version": "0.0.0-development",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"body-parser": "^1.19.0",
|
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"ws": "^7.2.3",
|
"ws": "^7.2.3",
|
||||||
|
@ -40,7 +40,6 @@
|
|||||||
"semantic-release": "semantic-release"
|
"semantic-release": "semantic-release"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"body-parser": "^1.19.0",
|
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"ws": "^7.2.3",
|
"ws": "^7.2.3",
|
||||||
|
@ -13,9 +13,3 @@ Endpoints:
|
|||||||
This group of methods uses `:key` option from config:
|
This group of methods uses `:key` option from config:
|
||||||
* GET `/:key/id` - return a new user id. required `:key` from config.
|
* GET `/:key/id` - return a new user id. required `:key` from config.
|
||||||
* GET `/:key/peers` - return an array of all connected users. required `:key` from config. **IMPORTANT:** You should set `allow_discovery` to `true` in config to enable this method. It disabled by default.
|
* GET `/:key/peers` - return an array of all connected users. required `:key` from config. **IMPORTANT:** You should set `allow_discovery` to `true` in config to enable this method. It disabled by default.
|
||||||
|
|
||||||
This group of methods uses `:key` option from config, `:userId` and `:userToken` parameters from user.
|
|
||||||
* POST `/:key/:userId/:userToken/offer`
|
|
||||||
* POST `/:key/:userId/:userToken/candidate`
|
|
||||||
* POST `/:key/:userId/:userToken/answer`
|
|
||||||
* POST `/:key/:userId/:userToken/leave`
|
|
@ -1,25 +1,16 @@
|
|||||||
import bodyParser from "body-parser";
|
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import publicContent from "../../app.json";
|
import publicContent from "../../app.json";
|
||||||
import { IConfig } from "../config";
|
import { IConfig } from "../config";
|
||||||
import { IMessageHandler } from "../messageHandler";
|
|
||||||
import { IRealm } from "../models/realm";
|
import { IRealm } from "../models/realm";
|
||||||
import { AuthMiddleware } from "./middleware/auth";
|
|
||||||
import CallsApi from "./v1/calls";
|
|
||||||
import PublicApi from "./v1/public";
|
import PublicApi from "./v1/public";
|
||||||
|
|
||||||
export const Api = ({ config, realm, messageHandler }: {
|
export const Api = ({ config, realm }: {
|
||||||
config: IConfig;
|
config: IConfig;
|
||||||
realm: IRealm;
|
realm: IRealm;
|
||||||
messageHandler: IMessageHandler;
|
|
||||||
}): express.Router => {
|
}): express.Router => {
|
||||||
const authMiddleware = new AuthMiddleware(config, realm);
|
|
||||||
|
|
||||||
const app = express.Router();
|
const app = express.Router();
|
||||||
|
|
||||||
const jsonParser = bodyParser.json();
|
|
||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
||||||
app.get("/", (_, res) => {
|
app.get("/", (_, res) => {
|
||||||
@ -27,7 +18,6 @@ export const Api = ({ config, realm, messageHandler }: {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.use("/:key", PublicApi({ config, realm }));
|
app.use("/:key", PublicApi({ config, realm }));
|
||||||
app.use("/:key/:id/:token", authMiddleware.handle, jsonParser, CallsApi({ realm, messageHandler }));
|
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
};
|
};
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
import express from "express";
|
|
||||||
import { IConfig } from "../../../config";
|
|
||||||
import { Errors } from "../../../enums";
|
|
||||||
import { IRealm } from "../../../models/realm";
|
|
||||||
import { IMiddleware } from "../middleware";
|
|
||||||
|
|
||||||
export class AuthMiddleware implements IMiddleware {
|
|
||||||
|
|
||||||
constructor(private readonly config: IConfig, private readonly realm: IRealm) { }
|
|
||||||
|
|
||||||
public handle = (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
||||||
const { id, token, key } = req.params;
|
|
||||||
|
|
||||||
if (key !== this.config.key) {
|
|
||||||
return res.status(401).send(Errors.INVALID_KEY);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!id) {
|
|
||||||
return res.sendStatus(401);
|
|
||||||
}
|
|
||||||
|
|
||||||
const client = this.realm.getClientById(id);
|
|
||||||
|
|
||||||
if (!client) {
|
|
||||||
return res.sendStatus(401);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (client.getToken() && token !== client.getToken()) {
|
|
||||||
return res.status(401).send(Errors.INVALID_TOKEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
next();
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
import express from "express";
|
|
||||||
|
|
||||||
export interface IMiddleware {
|
|
||||||
handle(req: express.Request, res: express.Response, next: express.NextFunction): any;
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
import express from "express";
|
|
||||||
import { IMessageHandler } from "../../../messageHandler";
|
|
||||||
import { IMessage } from "../../../models/message";
|
|
||||||
import { IRealm } from "../../../models/realm";
|
|
||||||
|
|
||||||
export default ({ realm, messageHandler }: { realm: IRealm; messageHandler: IMessageHandler; }): express.Router => {
|
|
||||||
const app = express.Router();
|
|
||||||
|
|
||||||
const handle = (req: express.Request, res: express.Response, next: express.NextFunction): any => {
|
|
||||||
const { id } = req.params;
|
|
||||||
|
|
||||||
if (!id) return next();
|
|
||||||
|
|
||||||
const client = realm.getClientById(id);
|
|
||||||
|
|
||||||
if (!client) {
|
|
||||||
throw new Error(`client not found:${id}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { type, dst, payload } = req.body;
|
|
||||||
|
|
||||||
const message: IMessage = {
|
|
||||||
type,
|
|
||||||
src: id,
|
|
||||||
dst,
|
|
||||||
payload
|
|
||||||
};
|
|
||||||
|
|
||||||
messageHandler.handle(client, message);
|
|
||||||
|
|
||||||
res.sendStatus(200);
|
|
||||||
};
|
|
||||||
|
|
||||||
app.post("/offer", handle);
|
|
||||||
app.post("/candidate", handle);
|
|
||||||
app.post("/answer", handle);
|
|
||||||
app.post("/leave", handle);
|
|
||||||
|
|
||||||
return app;
|
|
||||||
};
|
|
@ -21,7 +21,7 @@ export const createInstance = ({ app, server, options }: {
|
|||||||
const realm: IRealm = new Realm();
|
const realm: IRealm = new Realm();
|
||||||
const messageHandler = new MessageHandler(realm);
|
const messageHandler = new MessageHandler(realm);
|
||||||
|
|
||||||
const api = Api({ config, realm, messageHandler });
|
const api = Api({ config, realm });
|
||||||
const messagesExpire: IMessagesExpire = new MessagesExpire({ realm, config, messageHandler });
|
const messagesExpire: IMessagesExpire = new MessagesExpire({ realm, config, messageHandler });
|
||||||
const checkBrokenConnections = new CheckBrokenConnections({
|
const checkBrokenConnections = new CheckBrokenConnections({
|
||||||
realm,
|
realm,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user