UNPKG

@microsoft/teams-js

Version:

Microsoft Client SDK for building app for Microsoft hosts

2 lines (1 loc) 2.47 kB
import{__awaiter as n}from"../../../../node_modules/.pnpm/@rollup_plugin-typescript@11.1.6_rollup@4.24.4_tslib@2.6.3_typescript@4.9.5/node_modules/tslib/tslib.es6.js";import{isChildProxyingEnabled as i,getCurrentFeatureFlagsState as o}from"../public/featureFlags.js";import{flushMessageQueue as s,getMessageIdsAsLogString as e}from"./communicationUtils.js";import{callHandler as r}from"./handlers.js";import{deserializeMessageRequest as t,serializeMessageResponse as d}from"./messageObjects.js";import{getLogger as a,getApiVersionTag as u}from"./telemetry.js";const c=a("childProxyingCommunication");class l{}function g(){l.window=null,l.origin=null,l.messageQueue=[]}function m(){return!!i()&&!!l.window}function f(n,o){return!!i()&&(l.window&&!l.window.closed&&n!==l.window||(l.window=n,l.origin=o),l.window&&l.window.closed?(l.window=null,l.origin=null,!1):l.window===n)}function w(i,d,a,c){return n(this,void 0,void 0,(function*(){l.window===d&&(s(l.window,l.origin,l.messageQueue,"child"),function(n,i,s){if(void 0===n.data.id||void 0===n.data.func)return;const d=t(n.data),[a,c]=r(d.func,d.args);if(a&&void 0!==c)return p("Handler called in response to message %s from child. Returning response from handler to child, action: %s.",e(d),d.func),void h(d.id,d.uuid,Array.isArray(c)?c:[c]);p("No handler for message %s from child found; relaying message on to parent, action: %s. Relayed message will have a new id.",e(d),d.func),function(n,i,s){const r=i(u("v2","tasks.startTask"),n.func,n.args,!0,n.teamsJsInstanceId),t=l.origin;s(r.uuid,((...i)=>{if(!l.window)return;if(!o().disableEnforceOriginMatchForChildResponses&&t!==l.origin)return void p("Origin of child window has changed, not sending response back to child window");const s=i.pop();p("Message from parent being relayed to child, id: %s",e(n)),h(n.id,n.uuid,i,s)}))}(d,i,s)}(i,a,c))}))}l.messageQueue=[];const p=c.extend("handleIncomingMessageFromChild");function h(n,i,o,s){const r=l.window,t=function(n,i,o,s){return{id:n,uuid:i,args:o||[],isPartialResponse:s}}(n,i,o,s),a=d(t),u=l.origin;r&&u&&(p("Sending message %s to %s via postMessage, args = %o",e(a),"child",a.args),r.postMessage(a,u))}function v(n,i){const o=l.window,s=function(n,i){return{func:n,args:i||[]}}(n,i),e=l.origin;o&&e?o.postMessage(s,e):l.messageQueue.push(s)}export{w as handleIncomingMessageFromChild,v as sendMessageEventToChild,m as shouldEventBeRelayedToChild,f as shouldProcessChildMessage,g as uninitializeChildCommunication};