mirror of
https://github.com/HumanAIGC-Engineering/gradio-webrtc.git
synced 2026-02-04 17:39:23 +08:00
sync code of fastrtc, add text support through datachannel, fix safari connect problem support chat without camera or mic
28 lines
692 B
TypeScript
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);
|
|
} |