@xcall/sdk 1.0.0 → 1.0.1
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/README.md +180 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# @xcall/sdk
|
|
2
|
+
|
|
3
|
+
Embed video calls in any website with a single JavaScript class.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @xcall/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## How it works
|
|
12
|
+
|
|
13
|
+
1. Your backend generates a JWT token using the xCall API
|
|
14
|
+
2. You pass that token to the SDK
|
|
15
|
+
3. The SDK mounts a secure video call inside any HTML element
|
|
16
|
+
|
|
17
|
+
The token carries all configuration: room, user, branding, permissions. Your secret keys never reach the frontend.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### React
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { useEffect, useRef } from 'react'
|
|
27
|
+
import { XCall } from '@xcall/sdk'
|
|
28
|
+
|
|
29
|
+
export function VideoCall({ token }: { token: string }) {
|
|
30
|
+
const containerRef = useRef<HTMLDivElement>(null)
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (!containerRef.current) return
|
|
34
|
+
|
|
35
|
+
const call = new XCall({
|
|
36
|
+
container: containerRef.current,
|
|
37
|
+
token,
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
call.on('joined', ({ roomId }) => console.log('joined', roomId))
|
|
41
|
+
call.on('left', ({ roomId }) => console.log('left', roomId))
|
|
42
|
+
call.on('error', ({ message }) => console.error(message))
|
|
43
|
+
|
|
44
|
+
return () => call.destroy()
|
|
45
|
+
}, [token])
|
|
46
|
+
|
|
47
|
+
return <div ref={containerRef} style={{ width: '100%', height: '600px' }} />
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
### Vue
|
|
54
|
+
|
|
55
|
+
```vue
|
|
56
|
+
<template>
|
|
57
|
+
<div ref="callContainer" style="width:100%;height:600px" />
|
|
58
|
+
</template>
|
|
59
|
+
|
|
60
|
+
<script setup>
|
|
61
|
+
import { XCall } from '@xcall/sdk'
|
|
62
|
+
import { ref, onMounted, onUnmounted } from 'vue'
|
|
63
|
+
|
|
64
|
+
const props = defineProps(['token'])
|
|
65
|
+
const callContainer = ref(null)
|
|
66
|
+
let call
|
|
67
|
+
|
|
68
|
+
onMounted(() => {
|
|
69
|
+
call = new XCall({ container: callContainer.value, token: props.token })
|
|
70
|
+
call.on('left', () => console.log('left'))
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
onUnmounted(() => call?.destroy())
|
|
74
|
+
</script>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
### Angular
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { Component, ElementRef, ViewChild, Input, OnDestroy, AfterViewInit } from '@angular/core'
|
|
83
|
+
import { XCall } from '@xcall/sdk'
|
|
84
|
+
|
|
85
|
+
@Component({
|
|
86
|
+
selector: 'app-call',
|
|
87
|
+
template: '<div #container style="width:100%;height:600px"></div>',
|
|
88
|
+
})
|
|
89
|
+
export class CallComponent implements AfterViewInit, OnDestroy {
|
|
90
|
+
@ViewChild('container') container!: ElementRef
|
|
91
|
+
@Input() token!: string
|
|
92
|
+
private call!: XCall
|
|
93
|
+
|
|
94
|
+
ngAfterViewInit() {
|
|
95
|
+
this.call = new XCall({ container: this.container.nativeElement, token: this.token })
|
|
96
|
+
this.call.on('left', () => console.log('left'))
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
ngOnDestroy() {
|
|
100
|
+
this.call?.destroy()
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
### HTML / CDN
|
|
108
|
+
|
|
109
|
+
```html
|
|
110
|
+
<div id="call" style="width:100%;height:600px"></div>
|
|
111
|
+
|
|
112
|
+
<script src="https://cdn.jsdelivr.net/npm/@xcall/sdk/dist/xcall.min.js"></script>
|
|
113
|
+
<script>
|
|
114
|
+
const call = new XCallSDK.XCall({
|
|
115
|
+
container: '#call',
|
|
116
|
+
token: 'YOUR_TOKEN_HERE',
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
call.on('left', () => console.log('left'))
|
|
120
|
+
</script>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## API
|
|
126
|
+
|
|
127
|
+
### `new XCall(options)`
|
|
128
|
+
|
|
129
|
+
| Option | Type | Required | Description |
|
|
130
|
+
|---|---|---|---|
|
|
131
|
+
| `container` | `HTMLElement \| string` | ✅ | Element or CSS selector where the call will mount |
|
|
132
|
+
| `token` | `string` | ✅ | JWT token generated by your backend |
|
|
133
|
+
| `roomUrl` | `string` | — | Custom xCall-room URL (default: `https://room.xcall.com.br`) |
|
|
134
|
+
| `iframeStyle` | `object` | — | Extra CSS styles applied to the iframe |
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
### Events
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
call.on('ready', () => void)
|
|
142
|
+
call.on('joined', ({ roomId, userId }) => void)
|
|
143
|
+
call.on('left', ({ roomId, reason? }) => void)
|
|
144
|
+
call.on('participant_joined',({ userId, displayName? }) => void)
|
|
145
|
+
call.on('participant_left', ({ userId }) => void)
|
|
146
|
+
call.on('error', ({ code, message }) => void)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
### Methods
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
call.muteAudio(true) // mute / unmute microphone
|
|
155
|
+
call.muteVideo(false) // mute / unmute camera
|
|
156
|
+
call.leave() // end the call programmatically
|
|
157
|
+
call.destroy() // remove iframe and listeners (use on component unmount)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Token generation
|
|
163
|
+
|
|
164
|
+
Tokens must be generated server-side. Never expose your API secret on the frontend.
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
// Example: Node.js backend
|
|
168
|
+
const res = await fetch('https://api.xcall.com.br/session', {
|
|
169
|
+
method: 'POST',
|
|
170
|
+
headers: { 'x-api-key': process.env.XCALL_SECRET },
|
|
171
|
+
body: JSON.stringify({ room: 'my-room', user: { display_name: 'John' } }),
|
|
172
|
+
})
|
|
173
|
+
const { token } = await res.json()
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
MIT
|