wechat-adapter
v0.2.0
Published
A adapter for wechat mini game
Readme
wechat-adapter
A WeChat Mini Game adapter that provides web-like APIs for the WeChat Mini Game environment. This adapter helps bridge the gap between web applications and WeChat Mini Games by implementing common web APIs.
Features
- Web API compatibility layer for WeChat Mini Games
- Implements common web interfaces:
- DOM Elements and Events
- XMLHttpRequest and Fetch API
- WebSocket support
- Canvas and multimedia (Audio/Video) support
- LocalStorage
- Performance API
- Navigator API
- Window and Document objects
Installation
npm install wechat-adapterUsage
Import the adapter at the entry point of your WeChat Mini Game:
import 'wechat-adapter';The adapter will automatically inject the necessary APIs into the global scope. It handles both the WeChat DevTools environment and the actual mobile runtime environment appropriately.
API Components
The adapter includes implementations for:
EventTarget- DOM event handlingTouchEvent- Touch interaction eventsWebSocket- WebSocket client implementationXMLHttpRequest- HTTP request APIfetch- Modern HTTP request APIlocalStorage- Data persistencecanvas- Canvas rendering contextaudio/video- Multimedia supportwindow- Global window object with web-like APIsdocument- Document object modelnavigator- Browser-like navigator informationperformance- Performance measurement APIs
Environment Detection
The adapter automatically detects whether it's running in the WeChat DevTools or on a mobile device and adjusts its behavior accordingly to provide the most appropriate implementation.
License
MIT @ Congeer
