diff --git a/app/index.html b/app/index.html
index 8625e50..8ca7ccc 100644
--- a/app/index.html
+++ b/app/index.html
@@ -14,6 +14,8 @@
+
+
diff --git a/app/index.js b/app/index.js
index c04fc39..77e6a60 100644
--- a/app/index.js
+++ b/app/index.js
@@ -225,6 +225,9 @@ class GlobalBindings {
this.resetClient()
})
+ // Make sure we stay open if we're running as Matrix widget
+ window.matrixWidget.setAlwaysOnScreen(true)
+
// Register all channels, recursively
const registerChannel = channel => {
this._newChannel(channel)
@@ -620,6 +623,9 @@ window.mumbleUi = ui
window.onload = function () {
var queryParams = url.parse(document.location.href, true).query
var useJoinDialog = queryParams.joinDialog
+ if (queryParams.matrix) {
+ useJoinDialog = true
+ }
if (queryParams.address) {
ui.connectDialog.address(queryParams.address)
} else {
diff --git a/app/matrix.js b/app/matrix.js
new file mode 100644
index 0000000..c9cb846
--- /dev/null
+++ b/app/matrix.js
@@ -0,0 +1,60 @@
+// Handle messages coming from [Matrix] client if embedded as a [Widget] in some room.
+// [Matrix]: https://matrix.org/
+// [Widget]: https://docs.google.com/document/d/1uPF7XWY_dXTKVKV7jZQ2KmsI19wn9-kFRgQ1tFQP7wQ/edit
+
+class MatrixWidget {
+ constructor () {
+ this.widgetId = null
+ window.addEventListener('message', this.onMessage.bind(this))
+ }
+
+ onMessage (event) {
+ this.widgetId = this.widgetId || event.data.widgetId
+
+ switch (event.data.api) {
+ case 'fromWidget':
+ break
+ case 'toWidget':
+ switch (event.data.action) {
+ case 'capabilities':
+ this.sendResponse(event, {
+ capabilities: ['m.always_on_screen']
+ })
+ break
+ }
+ break
+ default:
+ break
+ }
+ }
+
+ sendContentLoaded () {
+ this.sendMessage({
+ action: 'content_loaded'
+ })
+ }
+
+ setAlwaysOnScreen (value) {
+ // Extension of main spec, see https://github.com/matrix-org/matrix-doc/issues/1354
+ this.sendMessage({
+ action: 'set_always_on_screen',
+ value: value, // once for spec compliance
+ data: { value: value } // and once for Riot
+ })
+ }
+
+ sendMessage (message) {
+ if (!this.widgetId) return
+ message.api = message.api || 'fromWidget'
+ message.widgetId = message.widgetId || this.widgetId
+ message.requestId = message.requestId || Math.random().toString(36)
+ window.parent.postMessage(message, '*')
+ }
+
+ sendResponse (event, response) {
+ event.data.response = response
+ event.source.postMessage(event.data, event.origin)
+ }
+}
+
+window.matrixWidget = new MatrixWidget()
diff --git a/webpack.config.js b/webpack.config.js
index 2f3c905..e388c77 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -3,12 +3,15 @@ var theme = 'MetroMumbleLight'
var path = require('path')
module.exports = {
- entry: [
- './app/index.js',
- './app/index.html'
- ],
+ entry: {
+ index: [
+ './app/index.js',
+ './app/index.html'
+ ],
+ matrix: './app/matrix.js'
+ },
output: {
- filename: 'index.js',
+ filename: '[name].js',
path: './dist'
},
module: {