This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
@@ -0,0 +1,95 @@
import { InitParams, ShareTargetPickerResult } from './def';
/**
* ShareTargetPicker
* (Singleton Class)
*/
export default class ShareTargetPicker {
private static instance;
private liffId;
private allowPostMessageOrigin;
private payloadToShareTargetPicker;
private ott;
private popupWindow;
private timeoutIDForHealthCheck;
private abortController;
private internalError;
private doesWaitForSubwindowResult;
private constructor();
/**
* return Singleton instance
*/
static getInstance(): ShareTargetPicker;
/**
* initialize
* @param params
*/
init(params: InitParams): Promise<ShareTargetPickerResult | void>;
private resetAllVariables;
/**
* reset instance
*/
private reset;
/**
* called whenever the process is finished
*/
private finalize;
/**
* create payload data in accordance with the relevant format
* So far, the format of `PayloadToShareTargetPicker` is same as `InitParams`
* @param params
*/
private buildPayloadToShareTargetPicker;
/**
* return string like "https://example.com" (not includes last `/`)
* @param url
*/
private initAllowPostMessageOrigin;
private initOtt;
/**
* get a reference to the new window
*/
private prepareAnotherWindow;
/**
* emit corresponding events
*/
private openAnotherWindow;
/**
* start to listen corresponding events
*/
private initListener;
/**
* this function will be called every second
*/
private healthCheck;
/**
* called after receiving the event named "receivedHealthCheck" . this function is called except on LIFF
*/
private onReceivedHealthcheck;
/**
* post share result (only for external browser)
*/
private onCanceled;
/**
* Fetch Get Share Result
*/
private getShareResult;
/**
* check if elapsed max duration of polling
*
* @static
* @param {number} startTime
* @param {number} endTime
* @returns {boolean}
* @memberof ShareTargetPicker
*/
static isPollingTimeOut(startTime: number, endTime: number): boolean;
/**
* Polling server side API to get result from shareTargetPicker screen,
* which has an access to access.line.me, via server API.
*
* @private
* @returns {(Promise<ShareTargetPickerResult|void>)}
* @memberof ShareTargetPicker
*/
private pollingShareResult;
}
+10
View File
@@ -0,0 +1,10 @@
import { PayloadToShareTargetPicker } from './def';
/**
* open another window for shareTargetPicker
* @param liffId
*/
export declare function openAnotherWindow(popupWindow: Window, liffId: string, ott: string): void;
export declare function initListener(cb: Function, allowPostMessageOrigin: string): void;
export declare function healthCheck(popupWindow: Window, allowPostMessageOrigin: string): void;
export declare function finalize(timeoutIDForHealthCheck: number | null, popupWindow: Window | null): void;
export declare function onReceivedHealthcheck(popupWindow: Window, payloadToShareTargetPicker: PayloadToShareTargetPicker, allowPostMessageOrigin: string): void;
+8
View File
@@ -0,0 +1,8 @@
import { PayloadToShareTargetPicker } from './def';
/**
* call LINE Scheme to let client receive infos to open another window for shareTargetPicker
* @param liffId
* @param ott
* @param message
*/
export declare function openAnotherWindow(liffId: string, ott: string, data: PayloadToShareTargetPicker): void;
+58
View File
@@ -0,0 +1,58 @@
import { SendMessagesParams } from './../sendMessages';
import { TellEvent } from '../../util/dom';
export declare const CLOSE_SHARETARGETPICKER_FAIL = 0;
export declare const CLOSE_SHARETARGETPICKER_SUCCEED = 1;
/**
* the format to send data to another window
*/
export interface PayloadToShareTargetPicker {
messages: SendMessagesParams;
referrer: {
liffId: string;
url: string;
};
}
/**
* the format in common with each closed event called when lfw/sub window closed
*/
export interface ClosedBody {
status?: number;
res?: {
message?: string;
};
callbackId: string;
}
/**
* the event called when lfw is closed
*/
export interface ClosedWebview extends CustomEvent {
detail: ClosedBody;
}
/**
* the event called when popup window is closed
*/
export interface ClosedPopupWindow extends TellEvent {
data: {
name: string;
body: ClosedBody;
};
}
/**
* the format of parameters for init is same as the format of payload to send to another screen so far.
* but the way to use is different. So I defined 2 types
*/
export interface InitParams extends PayloadToShareTargetPicker {
options?: {
waitForSubwindowResult: boolean;
};
}
export interface RetrievedOtt {
ott: string;
}
export interface RetrievedShareResult {
result?: 'SUCCESS' | 'FAILURE' | 'CANCEL';
resultDescription: string;
}
export interface ShareTargetPickerResult {
status: 'success';
}
+10
View File
@@ -0,0 +1,10 @@
import { SendMessagesParams } from '../sendMessages';
import { ShareTargetPickerResult } from './def';
/**
* Displays the target picker and sends the message created by the developer to the selected target.
* This message appears to your group or friends as if you had sent it
* @export
* @param {string} routerMode
* @returns {Promise<string|null>}
*/
export default function shareTargetPicker(messages: SendMessagesParams): Promise<ShareTargetPickerResult | void>;