2023-11-30 01:08:29 +09:00
|
|
|
/*
|
2024-02-13 15:59:27 +00:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-11-30 01:08:29 +09:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
export const postMessageEventTypes = [
|
|
|
|
|
'misskey:shareForm:shareCompleted',
|
2024-06-02 00:03:46 +09:00
|
|
|
'misskey:embed:ready',
|
2024-06-01 21:03:39 +09:00
|
|
|
'misskey:embed:changeHeight',
|
2023-11-30 01:08:29 +09:00
|
|
|
] as const;
|
|
|
|
|
|
|
|
|
|
export type PostMessageEventType = typeof postMessageEventTypes[number];
|
|
|
|
|
|
|
|
|
|
export type MiPostMessageEvent = {
|
|
|
|
|
type: PostMessageEventType;
|
2024-06-02 00:03:46 +09:00
|
|
|
iframeId?: string;
|
2023-11-30 01:08:29 +09:00
|
|
|
payload?: any;
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-02 00:03:46 +09:00
|
|
|
let defaultIframeId: string | null = null;
|
|
|
|
|
|
|
|
|
|
export function setIframeId(id: string): void {
|
|
|
|
|
if (_DEV_) console.log('setIframeId', id);
|
|
|
|
|
defaultIframeId = id;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-30 01:08:29 +09:00
|
|
|
/**
|
|
|
|
|
* 親フレームにイベントを送信
|
|
|
|
|
*/
|
2024-06-02 00:03:46 +09:00
|
|
|
export function postMessageToParentWindow(type: PostMessageEventType, payload?: any, iframeId: string | null = null): void {
|
|
|
|
|
let _iframeId = iframeId;
|
|
|
|
|
if (_iframeId == null) {
|
|
|
|
|
_iframeId = defaultIframeId;
|
|
|
|
|
}
|
|
|
|
|
if (_DEV_) console.log('postMessageToParentWindow', type, _iframeId, payload);
|
2024-06-01 21:03:39 +09:00
|
|
|
window.parent.postMessage({
|
2023-11-30 01:08:29 +09:00
|
|
|
type,
|
2024-06-02 00:03:46 +09:00
|
|
|
iframeId: _iframeId,
|
2023-11-30 01:08:29 +09:00
|
|
|
payload,
|
|
|
|
|
}, '*');
|
|
|
|
|
}
|