UNPKG

@socketsupply/socket

Version:

A Cross-Platform, Native Runtime for Desktop and Mobile Apps — Create apps using HTML, CSS, and JavaScript. Written from the ground up to be small and maintainable.

44 lines (36 loc) 906 B
import serialize from './serialize.js' const { BroadcastChannel, MessagePort, postMessage } = globalThis const platform = { BroadcastChannelPostMessage: BroadcastChannel.prototype.postMessage, MessagePortPostMessage: MessagePort.prototype.postMessage, GlobalPostMessage: postMessage } BroadcastChannel.prototype.postMessage = function (message, ...args) { return platform.BroadcastChannelPostMessage.call( this, handlePostMessage(message), ...args ) } MessagePort.prototype.postMessage = function (message, ...args) { return platform.MessagePortPostMessage.call( this, handlePostMessage(message), ...args ) } globalThis.postMessage = function (message, ...args) { return platform.GlobalPostMessage.call( this, handlePostMessage(message), ...args ) } function handlePostMessage (message) { return serialize(message) } export default null