Skip to content

sudongyuer/window-channel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

window-channel

A very simple window communication library.

GitHub stars

Get Start!


Install

npm install @haiyaotec/window-channel

Usage/Examples

Client

    import {WindowChannel} from '@haiyaotec/window-channel'
    let client = WindowChannel.newChannelClient(window,iFrame.contentWindow,"*")
    function f() {
        client.request('/hello', '客户端发送的消息', 1000)
            .then((value) => {
                console.log(value)
            })
            .catch((err) => {
                console.log(err)
            })
    }
    setInterval(f,3000)

Server

import {WindowChannel} from '@haiyaotec/window-channel'
let service=WindowChannel.newChannelService(window)

service.listen('/hello',(value)=>{
    console.log(value)
    return '服务端发送的消息'
})

service.observe('/dingyue',()=>{
    console.log('订阅成功')
})

setTimeout(()=>{
    service.broadcast('/dingyue','聊天室广播内容')
},20000)

License

MIT License © 2021-Present YuDong Su

About

🌈 A very simple window communication library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published