Skip to content

Commit 70a49d3

Browse files
committed
(TBR)added 2 new custom plugins for jingle
1 parent 3f975d2 commit 70a49d3

File tree

12 files changed

+99
-63
lines changed

12 files changed

+99
-63
lines changed

docs/source/configuration.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ The core, and by default whitelisted, plugins are::
539539
converse-dragresize
540540
converse-fullscreen
541541
converse-headline
542+
converse-jingle
542543
converse-mam
543544
converse-minimize
544545
converse-muc

docs/source/other_frameworks.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Below is an example code that wraps converse.js as an angular.js service.
6060
"converse-vcard", // XEP-0054 VCard-temp
6161
"converse-register", // XEP-0077 In-band registration
6262
"converse-ping", // XEP-0199 XMPP Ping
63+
"converse-jingle", // XEP-0166 Support for the Jingle Protocol
6364
"converse-notification", // HTML5 Notifications
6465
"converse-minimize", // Allows chatboxes to be minimized
6566
"converse-dragresize", // Allows chatboxes to be resized by dragging them

src/plugins/chatview/templates/chat-head.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { _converse } from '@converse/headless/core';
33
import { getHeadingDropdownItem, getHeadingStandaloneButton } from 'plugins/chatview/utils.js';
44
import { html } from "lit";
55
import { until } from 'lit/directives/until.js';
6-
import { JINGLE_CALL_STATUS } from "../../jingle/constants.js";
76

87

98
async function getStandaloneButtons (promise) {
@@ -44,7 +43,7 @@ export default (o) => {
4443
</div>
4544
</div>
4645
<div>
47-
${(o.model.get('jingle_status') === JINGLE_CALL_STATUS.PENDING) ? html`<button type="button" class="btn btn-success">Calling...</button>` : ''}
46+
<converse-chat-header-call-notification></converse-chat-header-call-notification>
4847
</div>
4948
<div class="chatbox-title__buttons row no-gutters">
5049
${ until(tpl_dropdown_btns(), '') }
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { CustomElement } from 'shared/components/element.js';
2+
import { _converse, api } from "@converse/headless/core";
3+
import { JINGLE_CALL_STATUS } from "./constants.js";
4+
import tpl_header_button from "./templates/header-button.js";
5+
6+
export default class ChatHeaderCallNotification extends CustomElement {
7+
8+
initialize() {
9+
this.model = _converse.chatboxes.get(this.jid);
10+
this.listenTo(this.model, 'change:jingle_status', this.requestUpdate);
11+
}
12+
13+
render() {
14+
return tpl_header_button(this);
15+
}
16+
17+
toggleJingleCallStatus() {
18+
const jingle_status = this.model.get('jingle_status');
19+
if ( jingle_status === JINGLE_CALL_STATUS.PENDING || jingle_status === JINGLE_CALL_STATUS.ACTIVE) {
20+
this.model.save('jingle_status', JINGLE_CALL_STATUS.ENDED);
21+
return;
22+
}
23+
if (!jingle_status || jingle_status === JINGLE_CALL_STATUS.ENDED) {
24+
this.model.save('jingle_status', JINGLE_CALL_STATUS.PENDING);
25+
return;
26+
}
27+
}
28+
}
29+
30+
api.elements.define('converse-chat-header-call-notification', ChatHeaderCallNotification);

src/plugins/jingle/index.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
* @license Mozilla Public License (MPLv2)
55
*/
66

7-
import { _converse, converse } from '@converse/headless/core';
7+
import { _converse, converse } from '@converse/headless/core.js';
88
import 'plugins/modal/index.js';
9-
import { __ } from 'i18n';
9+
import './toolbar-button.js';
1010
import { html } from "lit";
11-
import { startJingleCall } from "./utils.js";
1211

1312

1413
converse.plugins.add('converse-jingle', {
@@ -30,13 +29,10 @@ converse.plugins.add('converse-jingle', {
3029
*/
3130
_converse.api.listen.on('getToolbarButtons', (toolbar_el, buttons) => {
3231
if (!this.is_groupchat) {
33-
const color = '--chat-toolbar-btn-color';
34-
const i18n_start_call = __('Start a call');
3532
buttons.push(html`
36-
<button class="toggle-call" @click=${startJingleCall(toolbar_el.model.get('jid'))} title="${i18n_start_call}">
37-
<converse-icon color="var(${color})" class="fa fa-phone" size="1em"></converse-icon>
38-
</button>`
39-
);
33+
<converse-jingle-toolbar-button jid=${toolbar_el.model.get('jid')}>
34+
</converse-jingle-toolbar-button>
35+
`);
4036
}
4137

4238
return buttons;

src/plugins/jingle/modal/jingle-call-modal.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { html } from 'lit';
2+
import { JINGLE_CALL_STATUS } from '../constants';
3+
4+
export default (el) => {
5+
return html`
6+
<div>
7+
${ (el.model.get('jingle_status')) === JINGLE_CALL_STATUS.PENDING ? html`<span class="badge bg-secondary">Calling...</span>` : html``}
8+
</div>
9+
`;
10+
}

src/plugins/jingle/templates/jingle-call.js

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { html } from 'lit';
2+
import { __ } from "i18n";
3+
import { JINGLE_CALL_STATUS } from '../constants';
4+
5+
export default (el) => {
6+
const call_color = '--chat-toolbar-btn-color';
7+
const end_call_color = '--chat-toolbar-btn-close-color';
8+
const i18n_start_call = __('Start a call');
9+
const jingle_status = el.model.get('jingle_status');
10+
return html`
11+
<button class="toggle-call" @click=${el.toggleJingleCallStatus()} title="${i18n_start_call}">
12+
<converse-icon id="temp" color="var(${( jingle_status ||jingle_status === JINGLE_CALL_STATUS.PENDING || jingle_status === JINGLE_CALL_STATUS.ACTIVE ) ? end_call_color : call_color })" class="fa fa-phone" size="1em"></converse-icon>
13+
</button>`
14+
}

src/plugins/jingle/toolbar-button.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { CustomElement } from 'shared/components/element.js';
2+
import { _converse, api } from "@converse/headless/core";
3+
import { JINGLE_CALL_STATUS } from "./constants.js";
4+
import tpl_toolbar_button from "./templates/toolbar-button.js";
5+
6+
export default class JingleToolbarButton extends CustomElement {
7+
8+
static get properties() {
9+
return {
10+
'jid': { type: String },
11+
}
12+
}
13+
14+
initialize() {
15+
this.model = _converse.chatboxes.get(this.jid);
16+
this.listenTo(this.model, 'change:jingle_status', this.requestUpdate);
17+
}
18+
19+
render() {
20+
return tpl_toolbar_button(this);
21+
}
22+
23+
toggleJingleCallStatus() {
24+
const jingle_status = this.model.get('jingle_status');
25+
if ( jingle_status === JINGLE_CALL_STATUS.PENDING || jingle_status === JINGLE_CALL_STATUS.ACTIVE) {
26+
this.model.save('jingle_status', JINGLE_CALL_STATUS.ENDED);
27+
return;
28+
}
29+
if (!jingle_status || jingle_status === JINGLE_CALL_STATUS.ENDED) {
30+
this.model.save('jingle_status', JINGLE_CALL_STATUS.PENDING);
31+
return;
32+
}
33+
}
34+
}
35+
36+
api.elements.define('converse-jingle-toolbar-button', JingleToolbarButton);

0 commit comments

Comments
 (0)