When load embedded PC H5 page, the request and response, subscribe, and publish a mount to the H5 window object.
H5 can communicate with PC directly through subscription and request, including subscription listening and synchronous request response/asynchronous request response
To subscribe to
The subscription is a global subscription and H5 continuously listens for messages coming from the PC.
Parameters:
Service: the service string
Returns:
json:object
const unsubscribePing=subscribe(service, (event, json) => {
console.log(‘ok’,json);
})
unsubscribe
An unsubscribe method is returned when you subscribe. Call this method to unsubscribe
unsubscribePing()
Unsubscribe from specified/all subscriptions
Manually call unsubscribe to unsubscribe
Optional: Cancel all subscriptions if not uploaded
Service: the service string
unsubscribe(service)
release
parameter
Service: the service string
Json: parameter sent to PC
publish(service,json)
The response
parameter
Service: the service string
Json: parameter sent from the PC
The function callback
response(service,(event,json)=>{
console.log(‘ok’, json); })
Two request methods
Synchronize the callback request
parameter
Service: the service string
Data: string | object request parameters
The function callback
request(service, data, (event, json) => {
console.log(‘ok’, json); })
An asynchronous request
parameter
Service: the service string
Data: string | object request parameters
Return to the promise
const result=await request(service, data)
Github:github.com/soymikey/el…
Happy Coding~~