UNPKG

@lobehub/chat

Version:

Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.

40 lines (31 loc) 948 B
import { headers } from 'next/headers'; import { UAParser } from 'ua-parser-js'; /** * check mobile device in server */ const isMobileDevice = async () => { if (typeof process === 'undefined') { throw new Error('[Server method] you are importing a server-only module outside of server'); } const { get } = await headers(); const ua = get('user-agent'); // console.debug(ua); const device = new UAParser(ua || '').getDevice(); return device.type === 'mobile'; }; /** * check mobile device in server */ export const gerServerDeviceInfo = async () => { if (typeof process === 'undefined') { throw new Error('[Server method] you are importing a server-only module outside of server'); } const { get } = await headers(); const ua = get('user-agent'); const parser = new UAParser(ua || ''); return { browser: parser.getBrowser().name, isMobile: isMobileDevice(), os: parser.getOS().name, }; };