@xcall/sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/xcall.min.d.mts +102 -0
- package/dist/xcall.min.d.ts +102 -0
- package/dist/xcall.min.esm.js +2 -0
- package/dist/xcall.min.esm.js.map +1 -0
- package/dist/xcall.min.js +2 -0
- package/dist/xcall.min.js.map +1 -0
- package/package.json +28 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
interface XCallOptions {
|
|
2
|
+
/** Elemento HTML onde o iframe será montado */
|
|
3
|
+
container: HTMLElement | string;
|
|
4
|
+
/**
|
|
5
|
+
* Token JWT gerado pelo seu backend (via Cure-Api ou xCall-accounts).
|
|
6
|
+
* Contém room_id, user_id, branding, share_url, etc.
|
|
7
|
+
*/
|
|
8
|
+
token: string;
|
|
9
|
+
/**
|
|
10
|
+
* URL base do xCall-room.
|
|
11
|
+
* @default "https://room.xcall.com.br"
|
|
12
|
+
*/
|
|
13
|
+
roomUrl?: string;
|
|
14
|
+
/** Estilos extras aplicados ao iframe */
|
|
15
|
+
iframeStyle?: Partial<CSSStyleDeclaration>;
|
|
16
|
+
}
|
|
17
|
+
type XCallEventMap = {
|
|
18
|
+
/** iframe carregou e xCall-room está pronto */
|
|
19
|
+
ready: void;
|
|
20
|
+
/** Usuário local entrou na sala */
|
|
21
|
+
joined: {
|
|
22
|
+
roomId: string;
|
|
23
|
+
userId: string;
|
|
24
|
+
};
|
|
25
|
+
/** Usuário local saiu da sala (ou foi removido) */
|
|
26
|
+
left: {
|
|
27
|
+
roomId: string;
|
|
28
|
+
reason?: string;
|
|
29
|
+
};
|
|
30
|
+
/** Outro participante entrou */
|
|
31
|
+
participant_joined: {
|
|
32
|
+
userId: string;
|
|
33
|
+
displayName?: string;
|
|
34
|
+
};
|
|
35
|
+
/** Outro participante saiu */
|
|
36
|
+
participant_left: {
|
|
37
|
+
userId: string;
|
|
38
|
+
};
|
|
39
|
+
/** Erro genérico emitido pelo xCall-room */
|
|
40
|
+
error: {
|
|
41
|
+
code: string;
|
|
42
|
+
message: string;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
type XCallEventName = keyof XCallEventMap;
|
|
46
|
+
type XCallEventCallback<K extends XCallEventName> = (data: XCallEventMap[K]) => void;
|
|
47
|
+
type XCallCommand = {
|
|
48
|
+
type: 'xcall:mute_audio';
|
|
49
|
+
muted: boolean;
|
|
50
|
+
} | {
|
|
51
|
+
type: 'xcall:mute_video';
|
|
52
|
+
muted: boolean;
|
|
53
|
+
} | {
|
|
54
|
+
type: 'xcall:leave';
|
|
55
|
+
} | {
|
|
56
|
+
type: 'xcall:token';
|
|
57
|
+
token: string;
|
|
58
|
+
};
|
|
59
|
+
type XCallIncomingMessage = {
|
|
60
|
+
type: 'xcall:ready';
|
|
61
|
+
} | {
|
|
62
|
+
type: 'xcall:joined';
|
|
63
|
+
roomId: string;
|
|
64
|
+
userId: string;
|
|
65
|
+
} | {
|
|
66
|
+
type: 'xcall:left';
|
|
67
|
+
roomId: string;
|
|
68
|
+
reason?: string;
|
|
69
|
+
} | {
|
|
70
|
+
type: 'xcall:participant_joined';
|
|
71
|
+
userId: string;
|
|
72
|
+
displayName?: string;
|
|
73
|
+
} | {
|
|
74
|
+
type: 'xcall:participant_left';
|
|
75
|
+
userId: string;
|
|
76
|
+
} | {
|
|
77
|
+
type: 'xcall:error';
|
|
78
|
+
code: string;
|
|
79
|
+
message: string;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
declare class XCall {
|
|
83
|
+
private iframe;
|
|
84
|
+
private origin;
|
|
85
|
+
private listeners;
|
|
86
|
+
private messageHandler;
|
|
87
|
+
constructor(options: XCallOptions);
|
|
88
|
+
private _createIframe;
|
|
89
|
+
private _applyStyles;
|
|
90
|
+
private _handleMessage;
|
|
91
|
+
on<K extends XCallEventName>(event: K, cb: XCallEventCallback<K>): this;
|
|
92
|
+
off<K extends XCallEventName>(event: K, cb: XCallEventCallback<K>): this;
|
|
93
|
+
muteAudio(muted: boolean): void;
|
|
94
|
+
muteVideo(muted: boolean): void;
|
|
95
|
+
leave(): void;
|
|
96
|
+
/** Remove o iframe e os listeners. Chame quando destruir o componente. */
|
|
97
|
+
destroy(): void;
|
|
98
|
+
private _send;
|
|
99
|
+
private _emit;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { XCall, type XCallCommand, type XCallEventCallback, type XCallEventMap, type XCallEventName, type XCallIncomingMessage, type XCallOptions };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
interface XCallOptions {
|
|
2
|
+
/** Elemento HTML onde o iframe será montado */
|
|
3
|
+
container: HTMLElement | string;
|
|
4
|
+
/**
|
|
5
|
+
* Token JWT gerado pelo seu backend (via Cure-Api ou xCall-accounts).
|
|
6
|
+
* Contém room_id, user_id, branding, share_url, etc.
|
|
7
|
+
*/
|
|
8
|
+
token: string;
|
|
9
|
+
/**
|
|
10
|
+
* URL base do xCall-room.
|
|
11
|
+
* @default "https://room.xcall.com.br"
|
|
12
|
+
*/
|
|
13
|
+
roomUrl?: string;
|
|
14
|
+
/** Estilos extras aplicados ao iframe */
|
|
15
|
+
iframeStyle?: Partial<CSSStyleDeclaration>;
|
|
16
|
+
}
|
|
17
|
+
type XCallEventMap = {
|
|
18
|
+
/** iframe carregou e xCall-room está pronto */
|
|
19
|
+
ready: void;
|
|
20
|
+
/** Usuário local entrou na sala */
|
|
21
|
+
joined: {
|
|
22
|
+
roomId: string;
|
|
23
|
+
userId: string;
|
|
24
|
+
};
|
|
25
|
+
/** Usuário local saiu da sala (ou foi removido) */
|
|
26
|
+
left: {
|
|
27
|
+
roomId: string;
|
|
28
|
+
reason?: string;
|
|
29
|
+
};
|
|
30
|
+
/** Outro participante entrou */
|
|
31
|
+
participant_joined: {
|
|
32
|
+
userId: string;
|
|
33
|
+
displayName?: string;
|
|
34
|
+
};
|
|
35
|
+
/** Outro participante saiu */
|
|
36
|
+
participant_left: {
|
|
37
|
+
userId: string;
|
|
38
|
+
};
|
|
39
|
+
/** Erro genérico emitido pelo xCall-room */
|
|
40
|
+
error: {
|
|
41
|
+
code: string;
|
|
42
|
+
message: string;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
type XCallEventName = keyof XCallEventMap;
|
|
46
|
+
type XCallEventCallback<K extends XCallEventName> = (data: XCallEventMap[K]) => void;
|
|
47
|
+
type XCallCommand = {
|
|
48
|
+
type: 'xcall:mute_audio';
|
|
49
|
+
muted: boolean;
|
|
50
|
+
} | {
|
|
51
|
+
type: 'xcall:mute_video';
|
|
52
|
+
muted: boolean;
|
|
53
|
+
} | {
|
|
54
|
+
type: 'xcall:leave';
|
|
55
|
+
} | {
|
|
56
|
+
type: 'xcall:token';
|
|
57
|
+
token: string;
|
|
58
|
+
};
|
|
59
|
+
type XCallIncomingMessage = {
|
|
60
|
+
type: 'xcall:ready';
|
|
61
|
+
} | {
|
|
62
|
+
type: 'xcall:joined';
|
|
63
|
+
roomId: string;
|
|
64
|
+
userId: string;
|
|
65
|
+
} | {
|
|
66
|
+
type: 'xcall:left';
|
|
67
|
+
roomId: string;
|
|
68
|
+
reason?: string;
|
|
69
|
+
} | {
|
|
70
|
+
type: 'xcall:participant_joined';
|
|
71
|
+
userId: string;
|
|
72
|
+
displayName?: string;
|
|
73
|
+
} | {
|
|
74
|
+
type: 'xcall:participant_left';
|
|
75
|
+
userId: string;
|
|
76
|
+
} | {
|
|
77
|
+
type: 'xcall:error';
|
|
78
|
+
code: string;
|
|
79
|
+
message: string;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
declare class XCall {
|
|
83
|
+
private iframe;
|
|
84
|
+
private origin;
|
|
85
|
+
private listeners;
|
|
86
|
+
private messageHandler;
|
|
87
|
+
constructor(options: XCallOptions);
|
|
88
|
+
private _createIframe;
|
|
89
|
+
private _applyStyles;
|
|
90
|
+
private _handleMessage;
|
|
91
|
+
on<K extends XCallEventName>(event: K, cb: XCallEventCallback<K>): this;
|
|
92
|
+
off<K extends XCallEventName>(event: K, cb: XCallEventCallback<K>): this;
|
|
93
|
+
muteAudio(muted: boolean): void;
|
|
94
|
+
muteVideo(muted: boolean): void;
|
|
95
|
+
leave(): void;
|
|
96
|
+
/** Remove o iframe e os listeners. Chame quando destruir o componente. */
|
|
97
|
+
destroy(): void;
|
|
98
|
+
private _send;
|
|
99
|
+
private _emit;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { XCall, type XCallCommand, type XCallEventCallback, type XCallEventMap, type XCallEventName, type XCallIncomingMessage, type XCallOptions };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var s="https://room.xcall.com.br",r=class{constructor(e){this.listeners={};var l;let t=typeof e.container=="string"?document.querySelector(e.container):e.container;if(!t)throw new Error("[xCall] container not found");let a=(l=e.roomUrl)!=null?l:s;this.origin=new URL(a).origin,this.iframe=this._createIframe(a,e),this._applyStyles(this.iframe,e.iframeStyle),t.appendChild(this.iframe),this.messageHandler=i=>{i.origin===this.origin&&this._handleMessage(i.data,e.token)},window.addEventListener("message",this.messageHandler)}_createIframe(e,t){let a=document.createElement("iframe");return a.src=e.replace(/\/$/,""),a.allow="camera; microphone; display-capture; autoplay; clipboard-write; fullscreen",a.style.border="none",a.style.width="100%",a.style.height="100%",a}_applyStyles(e,t){if(t)for(let[a,l]of Object.entries(t))e.style[a]=l}_handleMessage(e,t){switch(e.type){case"xcall:ready":this._send({type:"xcall:token",token:t}),this._emit("ready",void 0);break;case"xcall:joined":this._emit("joined",{roomId:e.roomId,userId:e.userId});break;case"xcall:left":this._emit("left",{roomId:e.roomId,reason:e.reason});break;case"xcall:participant_joined":this._emit("participant_joined",{userId:e.userId,displayName:e.displayName});break;case"xcall:participant_left":this._emit("participant_left",{userId:e.userId});break;case"xcall:error":this._emit("error",{code:e.code,message:e.message});break}}on(e,t){return this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(t),this}off(e,t){var a;return(a=this.listeners[e])==null||a.delete(t),this}muteAudio(e){this._send({type:"xcall:mute_audio",muted:e})}muteVideo(e){this._send({type:"xcall:mute_video",muted:e})}leave(){this._send({type:"xcall:leave"})}destroy(){window.removeEventListener("message",this.messageHandler),this.iframe.remove()}_send(e){var t;(t=this.iframe.contentWindow)==null||t.postMessage(e,this.origin)}_emit(e,t){let a=this.listeners[e];a==null||a.forEach(l=>l(t))}};export{r as XCall};
|
|
2
|
+
//# sourceMappingURL=xcall.min.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n XCallOptions,\n XCallEventName,\n XCallEventCallback,\n XCallEventMap,\n XCallCommand,\n XCallIncomingMessage,\n} from './types'\n\nexport * from './types'\n\nconst DEFAULT_ROOM_URL = 'https://room.xcall.com.br'\n\nexport class XCall {\n private iframe: HTMLIFrameElement\n private origin: string\n private listeners: Partial<{\n [K in XCallEventName]: Set<XCallEventCallback<K>>\n }> = {}\n private messageHandler: (e: MessageEvent) => void\n\n constructor(options: XCallOptions) {\n const container =\n typeof options.container === 'string'\n ? (document.querySelector(options.container) as HTMLElement | null)\n : options.container\n\n if (!container) throw new Error('[xCall] container not found')\n\n const base = options.roomUrl ?? DEFAULT_ROOM_URL\n // Remove trailing slash para evitar URL duplo\n this.origin = new URL(base).origin\n\n this.iframe = this._createIframe(base, options)\n this._applyStyles(this.iframe, options.iframeStyle)\n\n container.appendChild(this.iframe)\n\n // ── Listener global de mensagens ──────────────────────────────────────\n this.messageHandler = (e: MessageEvent) => {\n if (e.origin !== this.origin) return\n this._handleMessage(e.data as XCallIncomingMessage, options.token)\n }\n window.addEventListener('message', this.messageHandler)\n }\n\n // ── Criar iframe limpo (sem token na URL) ─────────────────────────────────\n private _createIframe(\n base: string,\n options: XCallOptions\n ): HTMLIFrameElement {\n const el = document.createElement('iframe')\n // Sem ?token= na URL — o token é enviado via postMessage após xcall:ready\n el.src = base.replace(/\\/$/, '')\n el.allow =\n 'camera; microphone; display-capture; autoplay; clipboard-write; fullscreen'\n el.style.border = 'none'\n el.style.width = '100%'\n el.style.height = '100%'\n return el\n }\n\n private _applyStyles(\n iframe: HTMLIFrameElement,\n style?: Partial<CSSStyleDeclaration>\n ) {\n if (!style) return\n for (const [key, value] of Object.entries(style)) {\n ;(iframe.style as unknown as Record<string, string>)[key] = value as string\n }\n }\n\n // ── Roteador de mensagens recebidas ──────────────────────────────────────\n private _handleMessage(msg: XCallIncomingMessage, token: string) {\n switch (msg.type) {\n case 'xcall:ready':\n // Envia o token de forma segura via postMessage\n this._send({ type: 'xcall:token', token })\n this._emit('ready', undefined as void)\n break\n case 'xcall:joined':\n this._emit('joined', { roomId: msg.roomId, userId: msg.userId })\n break\n case 'xcall:left':\n this._emit('left', { roomId: msg.roomId, reason: msg.reason })\n break\n case 'xcall:participant_joined':\n this._emit('participant_joined', {\n userId: msg.userId,\n displayName: msg.displayName,\n })\n break\n case 'xcall:participant_left':\n this._emit('participant_left', { userId: msg.userId })\n break\n case 'xcall:error':\n this._emit('error', { code: msg.code, message: msg.message })\n break\n }\n }\n\n // ── API pública ──────────────────────────────────────────────────────────\n\n on<K extends XCallEventName>(event: K, cb: XCallEventCallback<K>): this {\n if (!this.listeners[event]) {\n this.listeners[event] = new Set() as never\n }\n ;(this.listeners[event] as Set<XCallEventCallback<K>>).add(cb)\n return this\n }\n\n off<K extends XCallEventName>(event: K, cb: XCallEventCallback<K>): this {\n ;(this.listeners[event] as Set<XCallEventCallback<K>> | undefined)?.delete(cb)\n return this\n }\n\n muteAudio(muted: boolean) {\n this._send({ type: 'xcall:mute_audio', muted })\n }\n\n muteVideo(muted: boolean) {\n this._send({ type: 'xcall:mute_video', muted })\n }\n\n leave() {\n this._send({ type: 'xcall:leave' })\n }\n\n /** Remove o iframe e os listeners. Chame quando destruir o componente. */\n destroy() {\n window.removeEventListener('message', this.messageHandler)\n this.iframe.remove()\n }\n\n // ── Helpers privados ─────────────────────────────────────────────────────\n\n private _send(cmd: XCallCommand) {\n this.iframe.contentWindow?.postMessage(cmd, this.origin)\n }\n\n private _emit<K extends XCallEventName>(event: K, data: XCallEventMap[K]) {\n const handlers = this.listeners[event] as\n | Set<XCallEventCallback<K>>\n | undefined\n handlers?.forEach((cb) => cb(data))\n }\n}\n"],"mappings":"AAWA,IAAMA,EAAmB,4BAEZC,EAAN,KAAY,CAQjB,YAAYC,EAAuB,CALnC,KAAQ,UAEH,CAAC,EAlBR,IAAAC,EAsBI,IAAMC,EACJ,OAAOF,EAAQ,WAAc,SACxB,SAAS,cAAcA,EAAQ,SAAS,EACzCA,EAAQ,UAEd,GAAI,CAACE,EAAW,MAAM,IAAI,MAAM,6BAA6B,EAE7D,IAAMC,GAAOF,EAAAD,EAAQ,UAAR,KAAAC,EAAmBH,EAEhC,KAAK,OAAS,IAAI,IAAIK,CAAI,EAAE,OAE5B,KAAK,OAAS,KAAK,cAAcA,EAAMH,CAAO,EAC9C,KAAK,aAAa,KAAK,OAAQA,EAAQ,WAAW,EAElDE,EAAU,YAAY,KAAK,MAAM,EAGjC,KAAK,eAAkBE,GAAoB,CACrCA,EAAE,SAAW,KAAK,QACtB,KAAK,eAAeA,EAAE,KAA8BJ,EAAQ,KAAK,CACnE,EACA,OAAO,iBAAiB,UAAW,KAAK,cAAc,CACxD,CAGQ,cACNG,EACAH,EACmB,CACnB,IAAMK,EAAK,SAAS,cAAc,QAAQ,EAE1C,OAAAA,EAAG,IAAMF,EAAK,QAAQ,MAAO,EAAE,EAC/BE,EAAG,MACD,6EACFA,EAAG,MAAM,OAAS,OAClBA,EAAG,MAAM,MAAQ,OACjBA,EAAG,MAAM,OAAS,OACXA,CACT,CAEQ,aACNC,EACAC,EACA,CACA,GAAKA,EACL,OAAW,CAACC,EAAKC,CAAK,IAAK,OAAO,QAAQF,CAAK,EAC3CD,EAAO,MAA4CE,CAAG,EAAIC,CAEhE,CAGQ,eAAeC,EAA2BC,EAAe,CAC/D,OAAQD,EAAI,KAAM,CAChB,IAAK,cAEH,KAAK,MAAM,CAAE,KAAM,cA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AUI,EAAwB,CACxE,IAAMC,EAAW,KAAK,UAAUL,CAAK,EAGrCK,GAAA,MAAAA,EAAU,QAASJ,GAAOA,EAAGG,CAAI,EACnC,CACF","names":["DEFAULT_ROOM_URL","XCall","options","_a","container","base","e","el","iframe","style","key","value","msg","token","event","cb","muted","cmd","data","handlers"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var r=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var m=(i,e)=>{for(var a in e)r(i,a,{get:e[a],enumerable:!0})},p=(i,e,a,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of c(e))!d.call(i,l)&&l!==a&&r(i,l,{get:()=>e[l],enumerable:!(t=o(e,l))||t.enumerable});return i};var h=i=>p(r({},"__esModule",{value:!0}),i);var C={};m(C,{XCall:()=>s});module.exports=h(C);var v="https://room.xcall.com.br",s=class{constructor(e){this.listeners={};var l;let a=typeof e.container=="string"?document.querySelector(e.container):e.container;if(!a)throw new Error("[xCall] container not found");let t=(l=e.roomUrl)!=null?l:v;this.origin=new URL(t).origin,this.iframe=this._createIframe(t,e),this._applyStyles(this.iframe,e.iframeStyle),a.appendChild(this.iframe),this.messageHandler=n=>{n.origin===this.origin&&this._handleMessage(n.data,e.token)},window.addEventListener("message",this.messageHandler)}_createIframe(e,a){let t=document.createElement("iframe");return t.src=e.replace(/\/$/,""),t.allow="camera; microphone; display-capture; autoplay; clipboard-write; fullscreen",t.style.border="none",t.style.width="100%",t.style.height="100%",t}_applyStyles(e,a){if(a)for(let[t,l]of Object.entries(a))e.style[t]=l}_handleMessage(e,a){switch(e.type){case"xcall:ready":this._send({type:"xcall:token",token:a}),this._emit("ready",void 0);break;case"xcall:joined":this._emit("joined",{roomId:e.roomId,userId:e.userId});break;case"xcall:left":this._emit("left",{roomId:e.roomId,reason:e.reason});break;case"xcall:participant_joined":this._emit("participant_joined",{userId:e.userId,displayName:e.displayName});break;case"xcall:participant_left":this._emit("participant_left",{userId:e.userId});break;case"xcall:error":this._emit("error",{code:e.code,message:e.message});break}}on(e,a){return this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(a),this}off(e,a){var t;return(t=this.listeners[e])==null||t.delete(a),this}muteAudio(e){this._send({type:"xcall:mute_audio",muted:e})}muteVideo(e){this._send({type:"xcall:mute_video",muted:e})}leave(){this._send({type:"xcall:leave"})}destroy(){window.removeEventListener("message",this.messageHandler),this.iframe.remove()}_send(e){var a;(a=this.iframe.contentWindow)==null||a.postMessage(e,this.origin)}_emit(e,a){let t=this.listeners[e];t==null||t.forEach(l=>l(a))}};0&&(module.exports={XCall});
|
|
2
|
+
//# sourceMappingURL=xcall.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n XCallOptions,\n XCallEventName,\n XCallEventCallback,\n XCallEventMap,\n XCallCommand,\n XCallIncomingMessage,\n} from './types'\n\nexport * from './types'\n\nconst DEFAULT_ROOM_URL = 'https://room.xcall.com.br'\n\nexport class XCall {\n private iframe: HTMLIFrameElement\n private origin: string\n private listeners: Partial<{\n [K in XCallEventName]: Set<XCallEventCallback<K>>\n }> = {}\n private messageHandler: (e: MessageEvent) => void\n\n constructor(options: XCallOptions) {\n const container =\n typeof options.container === 'string'\n ? (document.querySelector(options.container) as HTMLElement | null)\n : options.container\n\n if (!container) throw new Error('[xCall] container not found')\n\n const base = options.roomUrl ?? DEFAULT_ROOM_URL\n // Remove trailing slash para evitar URL duplo\n this.origin = new URL(base).origin\n\n this.iframe = this._createIframe(base, options)\n this._applyStyles(this.iframe, options.iframeStyle)\n\n container.appendChild(this.iframe)\n\n // ── Listener global de mensagens ──────────────────────────────────────\n this.messageHandler = (e: MessageEvent) => {\n if (e.origin !== this.origin) return\n this._handleMessage(e.data as XCallIncomingMessage, options.token)\n }\n window.addEventListener('message', this.messageHandler)\n }\n\n // ── Criar iframe limpo (sem token na URL) ─────────────────────────────────\n private _createIframe(\n base: string,\n options: XCallOptions\n ): HTMLIFrameElement {\n const el = document.createElement('iframe')\n // Sem ?token= na URL — o token é enviado via postMessage após xcall:ready\n el.src = base.replace(/\\/$/, '')\n el.allow =\n 'camera; microphone; display-capture; autoplay; clipboard-write; fullscreen'\n el.style.border = 'none'\n el.style.width = '100%'\n el.style.height = '100%'\n return el\n }\n\n private _applyStyles(\n iframe: HTMLIFrameElement,\n style?: Partial<CSSStyleDeclaration>\n ) {\n if (!style) return\n for (const [key, value] of Object.entries(style)) {\n ;(iframe.style as unknown as Record<string, string>)[key] = value as string\n }\n }\n\n // ── Roteador de mensagens recebidas ──────────────────────────────────────\n private _handleMessage(msg: XCallIncomingMessage, token: string) {\n switch (msg.type) {\n case 'xcall:ready':\n // Envia o token de forma segura via postMessage\n this._send({ type: 'xcall:token', token })\n this._emit('ready', undefined as void)\n break\n case 'xcall:joined':\n this._emit('joined', { roomId: msg.roomId, userId: msg.userId })\n break\n case 'xcall:left':\n this._emit('left', { roomId: msg.roomId, reason: msg.reason })\n break\n case 'xcall:participant_joined':\n this._emit('participant_joined', {\n userId: msg.userId,\n displayName: msg.displayName,\n })\n break\n case 'xcall:participant_left':\n this._emit('participant_left', { userId: msg.userId })\n break\n case 'xcall:error':\n this._emit('error', { code: msg.code, message: msg.message })\n break\n }\n }\n\n // ── API pública ──────────────────────────────────────────────────────────\n\n on<K extends XCallEventName>(event: K, cb: XCallEventCallback<K>): this {\n if (!this.listeners[event]) {\n this.listeners[event] = new Set() as never\n }\n ;(this.listeners[event] as Set<XCallEventCallback<K>>).add(cb)\n return this\n }\n\n off<K extends XCallEventName>(event: K, cb: XCallEventCallback<K>): this {\n ;(this.listeners[event] as Set<XCallEventCallback<K>> | undefined)?.delete(cb)\n return this\n }\n\n muteAudio(muted: boolean) {\n this._send({ type: 'xcall:mute_audio', muted })\n }\n\n muteVideo(muted: boolean) {\n this._send({ type: 'xcall:mute_video', muted })\n }\n\n leave() {\n this._send({ type: 'xcall:leave' })\n }\n\n /** Remove o iframe e os listeners. Chame quando destruir o componente. */\n destroy() {\n window.removeEventListener('message', this.messageHandler)\n this.iframe.remove()\n }\n\n // ── Helpers privados ─────────────────────────────────────────────────────\n\n private _send(cmd: XCallCommand) {\n this.iframe.contentWindow?.postMessage(cmd, this.origin)\n }\n\n private _emit<K extends XCallEventName>(event: K, data: XCallEventMap[K]) {\n const handlers = this.listeners[event] as\n | Set<XCallEventCallback<K>>\n | undefined\n handlers?.forEach((cb) => cb(data))\n }\n}\n"],"mappings":"4bAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,WAAAE,IAWA,IAAMC,EAAmB,4BAEZD,EAAN,KAAY,CAQjB,YAAYE,EAAuB,CALnC,KAAQ,UAEH,CAAC,EAlBR,IAAAC,EAsBI,IAAMC,EACJ,OAAOF,EAAQ,WAAc,SACxB,SAAS,cAAcA,EAAQ,SAAS,EACzCA,EAAQ,UAEd,GAAI,CAACE,EAAW,MAAM,IAAI,MAAM,6BAA6B,EAE7D,IAAMC,GAAOF,EAAAD,EAAQ,UAAR,KAAAC,EAAmBF,EAEhC,KAAK,OAAS,IAAI,IAAII,CAAI,EAAE,OAE5B,KAAK,OAAS,KAAK,cAAcA,EAAMH,CAAO,EAC9C,KAAK,aAAa,KAAK,OAAQA,EAAQ,WAAW,EAElDE,EAAU,YAAY,KAAK,MAAM,EAGjC,KAAK,eAAkBE,GAAoB,CACrCA,EAAE,SAAW,KAAK,QACtB,KAAK,eAAeA,EAAE,KAA8BJ,EAAQ,KAAK,CACnE,EACA,OAAO,iBAAiB,UAAW,KAAK,cAAc,CACxD,CAGQ,cACNG,EACAH,EACmB,CACnB,IAAMK,EAAK,SAAS,cAAc,QAAQ,EAE1C,OAAAA,EAAG,IAAMF,EAAK,QAAQ,MAAO,EAAE,EAC/BE,EAAG,MACD,6EACFA,EAAG,MAAM,OAAS,OAClBA,EAAG,MAAM,MAAQ,OACjBA,EAAG,MAAM,OAAS,OACXA,CACT,CAEQ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AM,aAAc,CAAC,CACpC,CAGA,SAAU,CACR,OAAO,oBAAoB,UAAW,KAAK,cAAc,EACzD,KAAK,OAAO,OAAO,CACrB,CAIQ,MAAMC,EAAmB,CAxInC,IAAAd,GAyIIA,EAAA,KAAK,OAAO,gBAAZ,MAAAA,EAA2B,YAAYc,EAAK,KAAK,OACnD,CAEQ,MAAgCH,EAAUI,EAAwB,CACxE,IAAMC,EAAW,KAAK,UAAUL,CAAK,EAGrCK,GAAA,MAAAA,EAAU,QAASJ,GAAOA,EAAGG,CAAI,EACnC,CACF","names":["src_exports","__export","XCall","DEFAULT_ROOM_URL","options","_a","container","base","e","el","iframe","style","key","value","msg","token","event","cb","muted","cmd","data","handlers"]}muted","cmd","data","handlers"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xcall/sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "xCall SDK — embed video calls in any website",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/xCall-Ecosystem/-xcall-sdk.git"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup",
|
|
20
|
+
"dev": "tsup --watch",
|
|
21
|
+
"release": "tsup && npm publish",
|
|
22
|
+
"deploy:cdn": "tsup && aws s3 cp dist/xcall.min.js s3://SEU_BUCKET/sdk/$(node -p \"require('./package.json').version\")/xcall.min.js --acl public-read && aws s3 cp dist/xcall.min.js s3://SEU_BUCKET/sdk/latest/xcall.min.js --acl public-read"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"tsup": "latest",
|
|
26
|
+
"typescript": "latest"
|
|
27
|
+
}
|
|
28
|
+
}
|