Skip to content

Commit 13b7a1a

Browse files
author
Julia Simplicio
committed
Merge branch 'master' of github.com:maxogden/screencat into ui-improvements
2 parents 1078904 + 59c96ef commit 13b7a1a

File tree

7 files changed

+46
-33
lines changed

7 files changed

+46
-33
lines changed

app.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</p>
2020
</main>
2121
</div>
22-
22+
2323
<div class="viewing-container dn">
2424
<main class="center mw8 phm phl-ns ptl pbxl">
2525
<p class="mono gray lh-copy thin mw7 f4 f3-ns">
@@ -77,7 +77,7 @@ <h2 class="f4 ttu book cl">join</h2>
7777
<div class="code-paste-button tc phs pvs pvm-ns f4 btn w-100 mw-fill">Connect</div>
7878
</div>
7979
</div>
80-
<p>Enter a code to connect to a remote screen.</p>
80+
<p>Enter a code to connect to a remote screen. <span class="code-mdns">Found <a href="javascript:void(0)" class="code-mdns-button"></a> near you</span></p>
8181
</div>
8282

8383
</main>

app.js

+35
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var ipc = require('ipc')
22
var clipboard = require('clipboard')
33
var shell = require('shell')
4+
var mdns = require('multicast-dns')()
45

56
var createPeerConnection = require('./peer.js')
67
var ui = require('./ui.js')
@@ -10,6 +11,24 @@ var peer
1011
var peerConnection = createPeerConnection()
1112
window.pc = peerConnection
1213

14+
mdns.on('query', function (query) {
15+
if (!ui.inputs.copy.value) return
16+
query.questions.forEach(function (q) {
17+
if (q.type === 'TXT' && q.name === 'screencat') {
18+
mdns.respond([{type: 'TXT', name: 'screencat', data: ui.inputs.copy.value}])
19+
}
20+
})
21+
})
22+
23+
mdns.on('response', function (res) {
24+
res.answers.forEach(function (a) {
25+
if (a.type === 'TXT' && a.name === 'screencat') {
26+
ui.buttons.mdns.innerText = a.data
27+
ui.show(ui.containers.mdns)
28+
}
29+
})
30+
})
31+
1332
peerConnection.on('connected', function connected (newPeer, remote) {
1433
peer = newPeer
1534

@@ -63,18 +82,34 @@ ui.buttons.share.addEventListener('click', function (e) {
6382
connect.host(peerConnection, ui)
6483
})
6584

85+
ui.buttons.mdns.addEventListener('click', function (e) {
86+
ui.inputs.paste.value = ui.buttons.mdns.innerText.trim()
87+
ui.buttons.paste.click()
88+
})
89+
6690
ui.buttons.join.addEventListener('click', function (e) {
91+
ui.inputs.copy.value = ''
92+
ui.hide(ui.containers.mdns)
6793
ui.show(ui.containers.join)
6894
ui.hide(ui.containers.choose)
6995
ui.show(ui.buttons.back)
96+
97+
var interval = setInterval(query, 1000)
98+
query()
99+
70100
connect.verifyUserRoom(peerConnection, ui, function (err, room, config) {
101+
clearInterval(interval)
71102
if (err) {
72103
ui.inputs.paste.value = 'Error! ' + err.message
73104
return
74105
}
75106
ui.inputs.paste.value = 'Waiting on other side...'
76107
ipc.send('create-window', {config: config, room: room})
77108
})
109+
110+
function query () {
111+
mdns.query([{type: 'TXT', name: 'screencat'}])
112+
}
78113
})
79114

80115
ui.buttons.back.addEventListener('click', function (e) {

collaborators.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
screencat is only possible due to the excellent work of the following collaborators:
44

55
<table><tbody><tr><th align="left">maxogden</th><td><a href="https://github.com/maxogden">GitHub/maxogden</a></td></tr>
6+
<tr><th align="left">mafintosh</th><td><a href="https://github.com/mafintosh">GitHub/mafintosh</a></td></tr>
67
<tr><th align="left">jsimplicio</th><td><a href="https://github.com/jsimplicio">GitHub/jsimplicio</a></td></tr>
78
</tbody></table>

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "screencat",
3-
"version": "4.1.0",
3+
"version": "4.2.0",
44
"description": "webrtc screensharing with shared mouse and keyboard",
55
"main": "electron.js",
66
"scripts": {
@@ -14,6 +14,7 @@
1414
"license": "BSD-3-Clause",
1515
"dependencies": {
1616
"menubar": "^2.0.4",
17+
"multicast-dns": "^3.0.0",
1718
"nets": "^3.1.0",
1819
"simple-peer": "^5.11.5",
1920
"ssejson": "^1.2.0",

peer.js

+1-17
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,6 @@ module.exports = function create (opts) {
206206
var video
207207

208208
if (remote) {
209-
window.addEventListener('mousemove', mousemoveListener)
210-
window.addEventListener('mousedown', mousedownListener)
211209
window.addEventListener('mouseup', mouseupListener)
212210
window.addEventListener('keydown', keydownListener)
213211
}
@@ -222,24 +220,10 @@ module.exports = function create (opts) {
222220
}
223221

224222
peer.on('close', function cleanup () {
225-
window.removeEventListener('mousedown', mousedownListener)
223+
window.removeEventListener('mouseup', mouseupListener)
226224
window.removeEventListener('keydown', keydownListener)
227225
})
228226

229-
function mousemoveListener (e) {
230-
var data = getMouseData(e)
231-
data.mouseMove = true
232-
console.log('send mousemove', data)
233-
peer.send(data)
234-
}
235-
236-
function mousedownListener (e) {
237-
var data = getMouseData(e)
238-
data.mouseDown = true
239-
console.log('send mousedown', data)
240-
peer.send(data)
241-
}
242-
243227
function mouseupListener (e) {
244228
var data = getMouseData(e)
245229
data.click = true

robot.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,12 @@ window.robot = robot
44
var vkey = require('vkey')
55

66
module.exports = function createEvents (data) {
7-
if (data.mouseDown) {
8-
return robot.mouseToggle("down", "left")
9-
}
10-
11-
if (data.mouseMove) {
12-
var x = scale(data.clientX, 0, data.canvasWidth, 0, screen.width)
13-
var y = scale(data.clientY, 0, data.canvasHeight, 0, screen.height)
14-
robot.moveMouse(x, y)
15-
}
16-
177
if (data.click) {
188
var x = scale(data.clientX, 0, data.canvasWidth, 0, screen.width)
199
var y = scale(data.clientY, 0, data.canvasHeight, 0, screen.height)
2010
var pos = robot.getMousePos() // hosts current x/y
2111
robot.moveMouse(x, y) // move to remotes pos
22-
robot.mouseToggle("up", "left") // set mouse position to up
12+
robot.mouseToggle('up', 'left') // set mouse position to up
2313
robot.mouseClick() // click on remote click spot
2414
robot.moveMouse(pos.x, pos.y) // go back to hosts position
2515
}

ui.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ ui.containers = {
1212
choose: document.querySelector('.choose-container'),
1313
multimedia: document.querySelector('.multimedia-container'),
1414
sharing: document.querySelector('.sharing-container'),
15-
viewing: document.querySelector('.viewing-container')
15+
viewing: document.querySelector('.viewing-container'),
16+
mdns: document.querySelector('.code-mdns')
1617
}
1718

1819
ui.buttons = {
@@ -24,7 +25,8 @@ ui.buttons = {
2425
back: document.querySelector('.back-button'),
2526
destroy: document.querySelector('.sharing-container .destroy-button'),
2627
stopViewing: document.querySelector('.viewing-container .destroy-button'),
27-
show: document.querySelector('.viewing-container .show-button')
28+
show: document.querySelector('.viewing-container .show-button'),
29+
mdns: document.querySelector('.code-mdns-button')
2830
}
2931

3032
ui.inputs = {

0 commit comments

Comments
 (0)