-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathScreenShare.js
92 lines (82 loc) · 2.21 KB
/
ScreenShare.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { html, css, LitElement } from 'lit';
export class ScreenShare extends LitElement {
static get styles() {
return css`
:host {
display: block;
padding: 25px;
color: var(--screen-share-text-color, #000);
}
`;
}
static get properties() {
return {
publisher: {},
session: {},
token: {},
properties: { type: Object },
buttonStartText: { type: String, attribute: 'start-text' },
buttonStopText: { type: String, attribute: 'stop-text' },
isSharing: { type: Boolean }
}
};
constructor() {
super();
this.session = {};
this.token = "";
this.properties = {};
this.buttonStartText = "start screenshare";
this.buttonStopText = "stop screenshare";
this.isSharing = false;
}
updated(changedProperties) {
if(changedProperties.get("session")){
this.session.connect(this.token);
}
}
connectedCallback() {
super.connectedCallback();
}
disconnectedCallback() {
super.disconnectedCallback()
this.publisher.destroy();
}
async __handleStartScreenshare() {
this.properties = { ...this.properties, videoSource: 'screen', insertMode: 'append'};
if (window.OT){
this.publisher = OT.initPublisher(document.querySelector('screen-share'), this.properties, (error) => {
if(error){
console.error("error: ", error)
} else {
this.session.publish(this.publisher, (pubError) => {
if(pubError){
console.error("session error: ", pubError.message);
} else {
this.isSharing = true;
}
});
}
});
} else {
console.error("Please load Vonage Video library.");
}
}
async __handleStopScreenshare() {
this.publisher.destroy();
this.isSharing = false;
}
displayButton() {
if (this.isSharing) {
return html`<button part="button" @click=${this.__handleStopScreenshare}>${this.buttonStopText}</button>`;
} else {
return html`<button part="button" @click=${this.__handleStartScreenshare}>${this.buttonStartText}</button>`;
}
}
render() {
return html`
${this.displayButton()}
<br/>
<slot></slot>
`;
}
}