2021-07-15 11:26:04 +02:00
|
|
|
import type { UserSimplePeerInterface } from "../../WebRtc/SimplePeer";
|
|
|
|
import { STUN_SERVER, TURN_PASSWORD, TURN_SERVER, TURN_USER } from "../../Enum/EnvironmentVariable";
|
|
|
|
|
2021-06-25 18:14:40 +02:00
|
|
|
export function getColorByString(str: string): string | null {
|
2021-06-21 14:07:03 +02:00
|
|
|
let hash = 0;
|
|
|
|
if (str.length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
for (let i = 0; i < str.length; i++) {
|
|
|
|
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
|
|
hash = hash & hash;
|
|
|
|
}
|
2021-06-25 18:14:40 +02:00
|
|
|
let color = "#";
|
2021-06-21 14:07:03 +02:00
|
|
|
for (let i = 0; i < 3; i++) {
|
|
|
|
const value = (hash >> (i * 8)) & 255;
|
2021-06-25 18:14:40 +02:00
|
|
|
color += ("00" + value.toString(16)).substr(-2);
|
2021-06-21 14:07:03 +02:00
|
|
|
}
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2021-07-15 11:26:04 +02:00
|
|
|
export function srcObject(node: HTMLVideoElement, stream: MediaStream | null) {
|
2021-06-21 14:07:03 +02:00
|
|
|
node.srcObject = stream;
|
|
|
|
return {
|
|
|
|
update(newStream: MediaStream) {
|
|
|
|
if (node.srcObject != newStream) {
|
2021-06-25 18:14:40 +02:00
|
|
|
node.srcObject = newStream;
|
2021-06-21 14:07:03 +02:00
|
|
|
}
|
2021-06-25 18:14:40 +02:00
|
|
|
},
|
|
|
|
};
|
2021-06-21 14:07:03 +02:00
|
|
|
}
|
2021-07-15 11:26:04 +02:00
|
|
|
|
|
|
|
export function getIceServersConfig(user: UserSimplePeerInterface): RTCIceServer[] {
|
|
|
|
const config: RTCIceServer[] = [
|
|
|
|
{
|
|
|
|
urls: STUN_SERVER.split(","),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
if (TURN_SERVER !== "") {
|
|
|
|
config.push({
|
|
|
|
urls: TURN_SERVER.split(","),
|
|
|
|
username: user.webRtcUser || TURN_USER,
|
|
|
|
credential: user.webRtcPassword || TURN_PASSWORD,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return config;
|
|
|
|
}
|