Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push-to-Talk Support for Jitsi #7709

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
70e7c63
Jitsi Push-to-Talk
anoadragon453 Nov 15, 2018
3bd8f52
Don't add translation in riot-web
anoadragon453 Nov 21, 2018
726ca5b
Merge branch 'develop' of github.com:vector-im/riot-web into anoa/jit…
anoadragon453 Feb 4, 2019
6e71fa5
Jitsi Push-to-Talk
anoadragon453 Nov 15, 2018
f3fb6f9
Merge branch 'master' of https://github.com/vector-im/riot-web into d…
anoadragon453 Feb 21, 2019
65a501f
Trying to make things work
anoadragon453 Feb 21, 2019
7ea2073
hey it all works
anoadragon453 Feb 21, 2019
8d1854a
Merge branch 'master' of https://github.com/vector-im/riot-web into d…
anoadragon453 Feb 27, 2019
3ee02a7
Merge branch 'develop' into anoa/jitsi_ptt
anoadragon453 Feb 27, 2019
d7b0e15
Update cmake-js runtimeVersion to 4.0.6
anoadragon453 Feb 28, 2019
fa72152
Merge branch 'develop' into anoa/jitsi_ptt
anoadragon453 Mar 3, 2019
012ad9e
Merge branch 'anoa/jitsi_ptt' of github.com:anoadragon453/riot-web in…
anoadragon453 Mar 7, 2019
94b6396
Prevent erroneously setting state outside of settings window
anoadragon453 Mar 7, 2019
8b60fe9
Remove merge markers
anoadragon453 Mar 8, 2019
600b869
Remove more merge markers
anoadragon453 Mar 8, 2019
c3d3034
lint
anoadragon453 Mar 8, 2019
d4984e3
Remove duplicate import
anoadragon453 Mar 8, 2019
dc96f1c
Remove duped code
anoadragon453 Mar 8, 2019
fc23feb
Merge branch 'develop' into anoa/jitsi_ptt
anoadragon453 Mar 20, 2019
12394bf
Fix electron build command
anoadragon453 Mar 20, 2019
5240be6
Update to iohook 0.4.0
anoadragon453 Mar 20, 2019
c8a04cd
Merge branch 'develop' into anoa/jitsi_ptt
anoadragon453 Apr 8, 2019
10d0b72
Update electron version and add compiling docs
anoadragon453 Apr 8, 2019
4156034
Update instructions to ensure downloaded modules
anoadragon453 Apr 8, 2019
cb21410
Switch npm i to yarn
anoadragon453 Apr 9, 2019
8dc95ab
Update docs with build deps
anoadragon453 Apr 9, 2019
b7781ab
Merge branch 'develop' into anoa/jitsi_ptt
anoadragon453 Jul 12, 2019
f4a7f0d
Fix some merge conflicts and up to electron 4.2.6
anoadragon453 Jul 12, 2019
796016a
Fix merge
anoadragon453 Jul 15, 2019
28440af
Add native module build script
anoadragon453 Jul 15, 2019
dc1ff1c
Make build script executable
anoadragon453 Jul 15, 2019
4ec456d
fix case statement
anoadragon453 Jul 15, 2019
51c3558
fix issues
anoadragon453 Jul 15, 2019
98cd405
Set MACHINE_TYPE
anoadragon453 Jul 15, 2019
da69384
Update build script
anoadragon453 Jul 15, 2019
4a75b53
Allow script to output to curr. dir
anoadragon453 Jul 15, 2019
2e5ab3f
Run yarn clean
anoadragon453 Jul 15, 2019
ccb0ce0
Fix options and usage text
anoadragon453 Jul 15, 2019
62cfd3b
Merge branch 'develop' into anoa/jitsi_ptt
anoadragon453 Jul 19, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,14 @@ package for 64 bit Linux:
1. Follow the instructions in 'Building From Source' above
2. `node_modules/.bin/build -l --x64`

All Electron packages go into `electron_app/dist/`
All electron packages go into `electron_app/dist/`.

Electron Specific Features
--------------------------

The electron version of Riot contains some features that are only possible from electron rather than within a browser window. This includes the "Push-to-Talk" feature, which allows you to toggle your microphone during a call even if Riot is not in focus.

This requires the use of a native node module called [iohook](https://github.com/matrix-org/iohook/). Native node modules are written in C, and by default during the build of Riot the compiled binaries will be downloaded from npm. If you would like to build this module from source yourself, please read [Compiling iohook](docs/native_node_modules.md#compiling-iohook).

Many thanks to @aviraldg for the initial work on the Electron integration.

Expand Down
40 changes: 40 additions & 0 deletions docs/native_node_modules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Native Node Modules

Since v???, the electron version of Riot can make use of native node modules.
These allow Riot to integrate with the desktop in ways that a browser cannot.

While handy, these modules must be compiled and are thus downloaded
pre-compiled during build so that a single OS can compile Riot for all
platforms. If you would like to compile the native node modules from source,
as is done for Riot releases, instead of trusting binaries hosted on npm,
then please read on.

Do note that compiling a module for a particular operating system
(Linux/Mac/Windows) and will need to be done on that operating system.

## Compiling iohook

[iohook](https://github.com/matrix-org/iohook/) is a native node module
written in C/C++ that allows for cross-platform capturing of keystrokes. This
is used for providing Push-to-Talk functionality (pressing a key to toggle
the microphone in a call) and is ONLY enabled during a call and while setting
the keybinding in settings.

If you would like to rebuild the module yourself and replace the downloaded
binaries, then first make sure you have the following dependencies. Then
simply execute `build-native-modules.sh` with the following flags:

```bash
./scripts/build-native-modules.sh -e 4.2.6 -a 69 -i
```

`-e` specifies the electron version, `-a` specifies the electron ABI version,
and `-i` tells the script to build iohook and then install it.

If you'd just like to build the module without installing it, use `-I` instead.

```bash
./scripts/build-native-modules.sh -e 4.2.6 -a 69 -I
```

To then start Electron, use `npx electron .`. To package, use `build -wml -ia32 --x64`.
14 changes: 13 additions & 1 deletion electron_app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@
"auto-launch": "^5.0.1",
"electron-store": "^2.0.0",
"electron-window-state": "^4.1.0",
"iohook": "^0.4.2",
"minimist": "^1.2.0",
"png-to-ico": "^1.0.2"
}
},
"cmake-js": {
"runtime": "electron",
"runtimeVersion": "4.2.6"
},
"supportedTargets": [
[
"electron",
"4.2.6",
"69"
]
]
}
94 changes: 94 additions & 0 deletions electron_app/src/electron-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const argv = require('minimist')(process.argv);
const {app, ipcMain, powerSaveBlocker, BrowserWindow, Menu, autoUpdater, protocol} = require('electron');
const AutoLaunch = require('auto-launch');
const path = require('path');
const ioHook = require('iohook');

const tray = require('./tray');
const vectorMenu = require('./vectormenu');
Expand Down Expand Up @@ -369,6 +370,13 @@ app.on('ready', () => {
return false;
}
});
mainWindow.on('blur', () => {
// Stop recording keypresses if Riot loses focus
// Used for Push-To-Talk, keypress recording only triggered when setting
// a global shortcut in Settings
mainWindow.webContents.send('window-blurred');
stopListeningKeys();
});

if (process.platform === 'win32') {
// Handle forward/backward mouse buttons in Windows
Expand Down Expand Up @@ -411,6 +419,92 @@ app.on('second-instance', (ev, commandLine, workingDirectory) => {
}
});

// Counter for keybindings we have registered
let ioHookTasks = 0;

// Limit for amount of keybindings that can be
// registered at once.
const keybindingRegistrationLimit = 1;

// Fires when a global keybinding is being registered
ipcMain.on('register-keybinding', function(ev, keybinding) {
// Prevent registering more than the defined limit
if (ioHookTasks >= keybindingRegistrationLimit) {
ioHookTasks = keybindingRegistrationLimit;
return;
}

// Start listening for global keyboard shortcuts
if (ioHookTasks <= 0) {
ioHookTasks = 0;
ioHook.start();
}
ioHookTasks++;

ioHook.registerShortcut(keybinding.code, () => {
ev.sender.send('keybinding-pressed', keybinding.name);
}, () => {
ev.sender.send('keybinding-released', keybinding.name);
});
});

// Fires when a global keybinding is being unregistered
ipcMain.on('unregister-keybinding', function(ev, keybindingCode) {
// Stop listening for global keyboard shortcuts if we're
// unregistering the last one
if (ioHookTasks <= 1) {
ioHook.stop();
}
ioHookTasks--;

ioHook.unregisterShortcutByKeys(keybindingCode);
});

// Tell renderer process what key was pressed
// iohook has its own encoding for keys, so we can't just use a
// listener in the renderer process to register iohook shortcuts
let renderProcessID = null;
const reportKeyEvent = function(keyEvent) {
// "this" is the renderer process because we call this method with .bind()
renderProcessID.sender.send('keypress', {
keydown: keyEvent.type == 'keydown',
keycode: keyEvent.keycode,
});
};

// Fires when listening on all keys
// !!Security note: Ensure iohook is only allowed to listen to keybindings
// when the browser window is in focus, else an XSS could lead to keylogging
// Currently, this is achieved by leveraging browserWindow to act on focus loss
ipcMain.on('start-listening-keys', function(ev, keybindingCode) {
// Start recording keypresses
if (ioHookTasks <= 0) {
ioHookTasks = 0;
ioHook.start();
}
ioHookTasks++;

renderProcessID = ev;
ioHook.on('keydown', reportKeyEvent);
ioHook.on('keyup', reportKeyEvent);
});

const stopListeningKeys = () => {
// Stop recording keypresses
ioHook.off('keydown', reportKeyEvent);
ioHook.off('keyup', reportKeyEvent);
};

ipcMain.on('stop-listening-keys', () => {
if (ioHookTasks <= 1) {
ioHookTasks = 1;
ioHook.stop();
}
ioHookTasks--;

stopListeningKeys();
});

// Set the App User Model ID to match what the squirrel
// installer uses for the shortcut icon.
// This makes notifications work on windows 8.1 (and is
Expand Down
Loading