Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Random Stream Key Generator (#2690)

Jambaldorj Ochirpurev9d35be4651c0
diff --git a/web/components/admin/config/server/StreamKeys.tsx b/web/components/admin/config/server/StreamKeys.tsx
index 9b62096f00..24685c7770 100644
--- a/web/components/admin/config/server/StreamKeys.tsx
+++ b/web/components/admin/config/server/StreamKeys.tsx
@@ -35,6 +35,24 @@ const saveKeys = async (keys, setError) => {
}
};
+const generateRndKey = () => {
+ let defaultKey = '';
+ let isValidStreamKey = false;
+ const streamKeyRegex = /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#$%^&*]).{8,192}$/;
+ const s = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*';
+
+ while (!isValidStreamKey) {
+ const temp = Array.apply(20, Array(30))
+ .map(() => s.charAt(Math.floor(Math.random() * s.length)))
+ .join('');
+ if (streamKeyRegex.test(temp)) {
+ isValidStreamKey = true;
+ defaultKey = temp;
+ }
+ }
+ return defaultKey;
+};
+
const AddKeyForm = ({ setShowAddKeyForm, setFieldInConfigState, streamKeys, setError }) => {
const handleAddKey = (newkey: any) => {
const updatedKeys = [...streamKeys, newkey];
@@ -50,10 +68,7 @@ const AddKeyForm = ({ setShowAddKeyForm, setFieldInConfigState, streamKeys, setE
};
// Default auto-generated key
- let defaultKey = '';
- for (let i = 0; i < 3; i += 1) {
- defaultKey += Math.random().toString(36).substring(2);
- }
+ const defaultKey = generateRndKey();
return (
<Form layout="inline" autoComplete="off" onFinish={handleAddKey}>