mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
Initial PoC for browser <-> desktop communication
This commit is contained in:
33
src/services/nativeMessaging.service.ts
Normal file
33
src/services/nativeMessaging.service.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import * as ipc from 'node-ipc';
|
||||
|
||||
export class NativeMessagingService {
|
||||
private connected = false;
|
||||
|
||||
listen() {
|
||||
ipc.config.id = 'bitwarden';
|
||||
ipc.config.retry = 1500;
|
||||
|
||||
ipc.serve(() => {
|
||||
ipc.server.on('message', (data: any, socket: any) => {
|
||||
ipc.log('got a message : ', data);
|
||||
ipc.server.emit(socket, 'message', data + ' world!');
|
||||
});
|
||||
|
||||
ipc.server.on('connect', () => {
|
||||
this.connected = true;
|
||||
})
|
||||
|
||||
ipc.server.on(
|
||||
'socket.disconnected',
|
||||
(socket: any, destroyedSocketID: any) => {
|
||||
this.connected = false;
|
||||
ipc.log(
|
||||
'client ' + destroyedSocketID + ' has disconnected!'
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
ipc.server.start();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user