Files
gradio-webrtc/frontend/shared/VideoChat/utils.ts
huangbinchao.hbc aefb08150f [feat] update some feature
sync code of  fastrtc,
add text support through datachannel,
fix safari connect problem
support chat without camera or mic
2025-03-25 18:05:10 +08:00

28 lines
692 B
TypeScript

export function click_outside(node: Node, cb: any): any {
const handle_click = (event: MouseEvent): void => {
if (
node &&
!node.contains(event.target as Node) &&
!event.defaultPrevented
) {
cb(event);
}
};
document.addEventListener("click", handle_click, true);
return {
destroy() {
document.removeEventListener("click", handle_click, true);
},
};
}
export function insertStringAt(rawStr: string, insertString: string, index: number) {
if (index < 0 || index > rawStr.length) {
console.error("索引超出范围");
return rawStr;
}
return rawStr.substring(0, index) + insertString + rawStr.substring(index);
}