Skip to content

Commit

Permalink
better like this
Browse files Browse the repository at this point in the history
  • Loading branch information
folkvir committed Oct 19, 2018
1 parent 1690ea0 commit d3ace40
Show file tree
Hide file tree
Showing 12 changed files with 237 additions and 1,189 deletions.
54 changes: 54 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages


# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

# Examples, tutorials, docs and tests should not be released
example/
examples/
tutorials/
tutorial/
guide/
guides/
tests/
doc/
docs/

# Additional material to exclude
*.yml
configs/
assets/
33 changes: 17 additions & 16 deletions bin/n2n-wrtc.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ module.exports = function (peer) {
/*! no static exports found */
/***/ (function(module, exports) {

const events = {
module.exports = {
socket: {
RECEIVE_OFFER: 'socket-ro',
EMIT_OFFER: 'socket-eo'
Expand All @@ -499,8 +499,6 @@ const events = {
}
}

module.exports = events


/***/ }),

Expand Down Expand Up @@ -566,16 +564,21 @@ class N2N extends AbstractN2N {
this.view.on('receive', (id, message) => {
this._receive(id, message)
})
this.view.on('in', (id, outview) => {
this.emit('connect', id, outview)
this.view.on('in', (id) => {
this.emit('connect', id, false)
this.emit('in', id)
})
this.view.on('out', (id, outview) => {
this.emit('connect', id, outview)
this.view.on('out', (id) => {
this.emit('connect', id, true)
this.emit('out', id)
})
this.view.on('close', id => {
this.emit('close', id)
this.view.on('close_in', id => {
this.emit('close', id, false)
this.emit('close_in', id)
})
this.view.on('close_out', id => {
this.emit('close', id, true)
this.emit('close_out', id)
})

this.signaling = {
Expand Down Expand Up @@ -622,7 +625,6 @@ class N2N extends AbstractN2N {
})

this.signaling.direct.on(events.signaling.RECEIVE_OFFER, ({ initiator, destination, offerType, offer }) => {
console.log({ initiator, destination, offerType, offer })
if (!initiator || !destination || !offer || !offerType) throw new Error('PLEASE REPORT, Problem with the offline signaling service. provide at least initiator, destination, type a,d the offer as properties in the object received')
// do we have the initiator in our list of connections?
if (!this.view.livingInview.has(initiator) && offerType === 'new') {
Expand Down Expand Up @@ -689,15 +691,12 @@ class N2N extends AbstractN2N {
*/
async connect4u (from = null, to = null) {
if (from && typeof from === 'string' && to && typeof to === 'string') {
console.log('connectBridge: ', from, to)
// bridge: create a connection between from and to if from is in inview and to is in outview
return this.connectBridge(from, to)
} else if (from && typeof from === 'string' && to === null) {
console.log('connectToUs: ', from, to)
// from to to us
return this.connectToUs(from)
} else if (to && typeof to === 'string' && from === null) {
console.log('connectFromUs: ', from, to)
// connection from us to to
if (this.view.livingOutview.has(to)) {
return this.connectFromUs(to)
Expand Down Expand Up @@ -1029,10 +1028,8 @@ class N2N extends AbstractN2N {
} else if (message && message.type && message.response && message.type === events.n2n.RESPONSE) {
this.events.emit(message.jobId, message)
} else if (message && message.type && message.type === events.n2n.DIRECT_TO) {
console.log('direct_to: ', id, message)
this.signaling.direct.receiveOffer(message)
} else if (message && message.type && message.type === events.n2n.DIRECT_BACK) {
console.log('direct_back: ', id, message)
this.signaling.direct.receiveOffer(message)
} else if (message && message.type && message.type === events.n2n.BRIDGE) {
this._bridge(id, message)
Expand Down Expand Up @@ -1604,7 +1601,11 @@ class Neighborhood extends EventEmitter {
* @return {void}
*/
_signalDisconnect (id, outview) {
this.emit('close', id, outview)
if (outview) {
this.emit('close_out', id, outview)
} else {
this.emit('close_in', id, outview)
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion bin/n2n-wrtc.bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bin/n2n-wrtc.bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bin/n2n-wrtc.bundle.min.js.map

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions lib/events.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const events = {
module.exports = {
socket: {
RECEIVE_OFFER: 'socket-ro',
EMIT_OFFER: 'socket-eo'
Expand All @@ -22,5 +22,3 @@ const events = {
RESPONSE: 'r'
}
}

module.exports = events
17 changes: 11 additions & 6 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,21 @@ class N2N extends AbstractN2N {
this.view.on('receive', (id, message) => {
this._receive(id, message)
})
this.view.on('in', (id, outview) => {
this.emit('connect', id, outview)
this.view.on('in', (id) => {
this.emit('connect', id, false)
this.emit('in', id)
})
this.view.on('out', (id, outview) => {
this.emit('connect', id, outview)
this.view.on('out', (id) => {
this.emit('connect', id, true)
this.emit('out', id)
})
this.view.on('close', id => {
this.emit('close', id)
this.view.on('close_in', id => {
this.emit('close', id, false)
this.emit('close_in', id)
})
this.view.on('close_out', id => {
this.emit('close', id, true)
this.emit('close_out', id)
})

this.signaling = {
Expand Down
6 changes: 5 additions & 1 deletion lib/neighborhood/neighborhood.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,11 @@ class Neighborhood extends EventEmitter {
* @return {void}
*/
_signalDisconnect (id, outview) {
this.emit('close', id, outview)
if (outview) {
this.emit('close_out', id, outview)
} else {
this.emit('close_in', id, outview)
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/signaling/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const lfind = require('lodash.find')
*/
const Server = function (config = require('./config.json')) {
console.log('Signaling server config: ', config)
this.app = require('express')()
this.server = require('http').Server(this.app)
this.io = require('socket.io')(this.server)
this.app = config.app || require('express')()
this.server = config.server || require('http').Server(this.app)
this.io = config.io || require('socket.io')(this.server)
this.os = require('os')
this.config = config

Expand Down
Loading

0 comments on commit d3ace40

Please sign in to comment.