-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (38 loc) · 1.25 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict'
const Foglet = require('foglet').Foglet
const app = new Foglet({
verbose: true, // activate logs. Put false to disable them in production!
rps: {
type: 'spray-wrtc',
options: {
protocol: 'foglet-hello-world', // name of the protocol run by your app
webrtc: { // WebRTC options
trickle: true, // enable trickle (divide offers in multiple small offers sent by pieces)
iceServers : [] // iceServers, we lkeave it empty for now
},
timeout: 2 * 60 * 1000, // WebRTC connections timeout
delta: 10 * 1000, // spray-wrtc shuffle interval
signaling: { //
address: 'http://localhost:3000/',
room: 'foglet-hello-world-room' // room to join
}
}
}
})
// connect to the signaling server
app.share()
// connect our app to the fog
app.connection()
.then(() => {
console.log('application connected!')
// listen for incoming broadcast
app.onBroadcast((id, msg) => {
console.log('I have received a message from peer', id, ':', msg)
})
// send our message each time we hit the button
const btn = document.getElementById("send-message")
btn.addEventListener("click", () => {
app.sendBroadcast('hello World!')
}, false)
})
.catch(console.error) // catch connection errors