@conectar/conectar-ws
Advanced tools
Comparing version 0.0.20 to 0.0.21
17
index.js
@@ -0,5 +1,6 @@ | ||
/* eslint-disable no-tabs */ | ||
import Wire from './lib/wire'; | ||
const globalConfigObject = { | ||
httpHeaders: {} | ||
httpHeaders: {}, | ||
}; | ||
@@ -19,9 +20,10 @@ | ||
export const setConfig = (config = {}) => { | ||
Object.keys(config).forEach(option => { | ||
Object.keys(config).forEach((option) => { | ||
const globalOption = globalConfigObject[option]; | ||
if (!globalOption) { | ||
console.error( | ||
// eslint-disable-next-line | ||
console.error( | ||
`WIRE: Unknown option ${option}. Available options are ${Object.keys( | ||
globalConfigObject | ||
).join(', ')}` | ||
globalConfigObject, | ||
).join(', ')}`, | ||
); | ||
@@ -31,5 +33,6 @@ return; | ||
if (typeof globalOption !== typeof config[option]) { | ||
// eslint-disable-next-lines | ||
console.error( | ||
`WIRE: Expected ${option} to be of type ${typeof globalOption} instead` + | ||
` found ${typeof config[option]}` | ||
`WIRE: Expected ${option} to be of type ${typeof globalOption} instead` | ||
+ ` found ${typeof config[option]}`, | ||
); | ||
@@ -36,0 +39,0 @@ return; |
202
lib/wire.js
@@ -12,4 +12,4 @@ export default class Wire { | ||
{ | ||
urls: 'stun:stun.l.google.com:19302' | ||
} | ||
urls: 'stun:stun.l.google.com:19302', | ||
}, | ||
]; | ||
@@ -23,6 +23,3 @@ this.listeners = {}; | ||
if ( | ||
window.location.hostname === 'localhost' || | ||
window.location.hostname === '127.0.0.1' | ||
) { | ||
if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') { | ||
this.host = 'localhost:8081'; | ||
@@ -36,3 +33,3 @@ } else { | ||
ws: 'ws:', | ||
http: 'http:' | ||
http: 'http:', | ||
}; | ||
@@ -42,3 +39,3 @@ } else { | ||
ws: 'wss:', | ||
http: 'https:' | ||
http: 'https:', | ||
}; | ||
@@ -50,3 +47,3 @@ } | ||
if (this.listeners[event]) { | ||
this.listeners[event].forEach(listener => { | ||
this.listeners[event].forEach((listener) => { | ||
listener(...params); | ||
@@ -77,5 +74,3 @@ }); | ||
this.connection = new WebSocket( | ||
`${this.protocols.ws}//${this.host}${url}` | ||
); | ||
this.connection = new WebSocket(`${this.protocols.ws}//${this.host}${url}`); | ||
this.connection.onopen = () => { | ||
@@ -87,3 +82,4 @@ this.wait_to_reconnect = 1; | ||
this.connection.onclose = () => { | ||
console.error('WIRE: websocket connection closed, reconnecting...'); | ||
// eslint-disable-next-line | ||
console.error('WIRE: websocket connection closed, reconnecting...'); | ||
setTimeout(() => { | ||
@@ -93,3 +89,3 @@ this.connect(); | ||
}; | ||
this.connection.onmessage = event => { | ||
this.connection.onmessage = (event) => { | ||
const data = JSON.parse(event.data); | ||
@@ -107,7 +103,5 @@ switch (data.action) { | ||
delete this.peers[data.user_id]; | ||
Object.entries(this.peer_connections[data.user_id]).forEach( | ||
([tag, pc]) => { | ||
pc.close(); | ||
} | ||
); | ||
Object.entries(this.peer_connections[data.user_id]).forEach(([tag, pc]) => { | ||
pc.close(); | ||
}); | ||
delete this.peer_connections[data.user_id]; | ||
@@ -135,3 +129,4 @@ this.run_listeners('left', this.prepare_time(data)); | ||
default: | ||
console.error(`unknown wrtc type ${data.type}`); | ||
// eslint-disable-next-line | ||
console.error(`unknown wrtc type ${data.type}`); | ||
} | ||
@@ -150,4 +145,4 @@ break; | ||
action, | ||
...data | ||
}) | ||
...data, | ||
}), | ||
); | ||
@@ -159,3 +154,3 @@ } | ||
recipient, | ||
text | ||
text, | ||
}); | ||
@@ -167,3 +162,3 @@ } | ||
payload: 'voice_call_request', | ||
recipient | ||
recipient, | ||
}); | ||
@@ -175,3 +170,3 @@ } | ||
payload: 'voice_call_accept', | ||
recipient | ||
recipient, | ||
}); | ||
@@ -183,3 +178,3 @@ } | ||
payload: 'video_call_request', | ||
recipient | ||
recipient, | ||
}); | ||
@@ -191,3 +186,3 @@ } | ||
payload: 'video_call_accept', | ||
recipient | ||
recipient, | ||
}); | ||
@@ -200,3 +195,3 @@ } | ||
whiteboard_id, | ||
whiteboard_name | ||
whiteboard_name, | ||
}); | ||
@@ -209,3 +204,3 @@ } | ||
whiteboard_id, | ||
whiteboard_name | ||
whiteboard_name, | ||
}); | ||
@@ -218,3 +213,3 @@ } | ||
whiteboard_id, | ||
whiteboard_meta | ||
whiteboard_meta, | ||
}); | ||
@@ -226,3 +221,3 @@ } | ||
action: 'update_room_meta', | ||
meta | ||
meta, | ||
}); | ||
@@ -234,3 +229,3 @@ } | ||
action: 'remove_whiteboard', | ||
whiteboard_id | ||
whiteboard_id, | ||
}); | ||
@@ -244,3 +239,3 @@ } | ||
object_id, | ||
object | ||
object, | ||
}); | ||
@@ -253,3 +248,3 @@ } | ||
whiteboard_id, | ||
object_id | ||
object_id, | ||
}); | ||
@@ -262,3 +257,3 @@ } | ||
payload: 'call_decline', | ||
recipient | ||
recipient, | ||
}; | ||
@@ -271,3 +266,3 @@ this.connection.send(JSON.stringify(payload)); | ||
.fetch(`${this.protocols.http}//${this.host}/${roomId}/whiteboards/`, { | ||
headers: this.options.httpHeaders | ||
headers: this.options.httpHeaders, | ||
}) | ||
@@ -281,3 +276,3 @@ .then(res => res.json()); | ||
headers: this.options.httpHeaders, | ||
credentials: 'include' | ||
credentials: 'include', | ||
}) | ||
@@ -295,4 +290,4 @@ .then(res => res.json()); | ||
headers: this.options.httpHeaders, | ||
credentials: 'include' | ||
} | ||
credentials: 'include', | ||
}, | ||
) | ||
@@ -306,3 +301,3 @@ .then(res => res.json()); | ||
headers: this.options.httpHeaders, | ||
credentials: 'include' | ||
credentials: 'include', | ||
}) | ||
@@ -314,14 +309,7 @@ .then(res => res.json()); | ||
return window | ||
.fetch( | ||
`${this.protocols.http}//${ | ||
this.host | ||
}/conversations/${user_id}/messages/`, | ||
{ | ||
credentials: 'include', | ||
headers: this.options.httpHeaders | ||
} | ||
) | ||
.then(response => { | ||
return response.json() || response; | ||
}); | ||
.fetch(`${this.protocols.http}//${this.host}/conversations/${user_id}/messages/`, { | ||
credentials: 'include', | ||
headers: this.options.httpHeaders, | ||
}) | ||
.then(response => response.json() || response); | ||
} | ||
@@ -333,7 +321,5 @@ | ||
credentials: 'include', | ||
headers: this.options.httpHeaders | ||
headers: this.options.httpHeaders, | ||
}) | ||
.then(response => { | ||
return response.json() || response; | ||
}); | ||
.then(response => response.json() || response); | ||
} | ||
@@ -346,10 +332,10 @@ | ||
credentials: 'include', | ||
headers: this.options.httpHeaders | ||
headers: this.options.httpHeaders, | ||
}) | ||
.then(response => { | ||
return response.json() || response; | ||
}); | ||
.then(response => response.json() || response); | ||
} | ||
handle_remote_offer({ sender, media, direction, payload }) { | ||
handle_remote_offer({ | ||
sender, media, direction, payload, | ||
}) { | ||
const pc = this.get_peerconnection(sender, media, direction); | ||
@@ -359,3 +345,3 @@ | ||
type: 'offer', | ||
sdp: payload | ||
sdp: payload, | ||
}); | ||
@@ -372,3 +358,3 @@ | ||
direction, | ||
payload: pc.localDescription.sdp | ||
payload: pc.localDescription.sdp, | ||
}); | ||
@@ -385,3 +371,3 @@ }); | ||
direction, | ||
payload: JSON.stringify(event.candidate.toJSON()) | ||
payload: JSON.stringify(event.candidate.toJSON()), | ||
}); | ||
@@ -391,6 +377,9 @@ } | ||
handle_remote_candidate({ sender, media, direction, payload }) { | ||
handle_remote_candidate({ | ||
sender, media, direction, payload, | ||
}) { | ||
const candidate = new RTCIceCandidate(JSON.parse(payload)); | ||
const pc = this.get_peerconnection(sender, media, direction); | ||
pc.addIceCandidate(candidate).catch(console.error); | ||
// eslint-disable-next-line | ||
pc.addIceCandidate(candidate).catch(console.error); | ||
} | ||
@@ -409,3 +398,3 @@ | ||
direction, | ||
payload: pc.localDescription.sdp | ||
payload: pc.localDescription.sdp, | ||
}); | ||
@@ -415,7 +404,9 @@ }); | ||
handle_remote_answer({ sender, media, direction, payload }) { | ||
handle_remote_answer({ | ||
sender, media, direction, payload, | ||
}) { | ||
const pc = this.get_peerconnection(sender, media, direction); | ||
const desc = new RTCSessionDescription({ | ||
type: 'answer', | ||
sdp: payload | ||
sdp: payload, | ||
}); | ||
@@ -435,5 +426,4 @@ pc.setRemoteDescription(desc); | ||
case 'failed': | ||
console.error( | ||
`Peer connection ${user_id} ${media}_${direction} failed` | ||
); | ||
// eslint-disable-next-line | ||
console.error(`Peer connection ${user_id} ${media}_${direction} failed`); | ||
break; | ||
@@ -445,3 +435,3 @@ case 'disconnected': | ||
media, | ||
direction | ||
direction, | ||
}); | ||
@@ -458,6 +448,3 @@ break; | ||
get_peerconnection(user_id, media, direction) { | ||
if ( | ||
this.peer_connections[user_id] && | ||
this.peer_connections[user_id][`${media}_${direction}`] | ||
) { | ||
if (this.peer_connections[user_id] && this.peer_connections[user_id][`${media}_${direction}`]) { | ||
return this.peer_connections[user_id][`${media}_${direction}`]; | ||
@@ -469,9 +456,9 @@ } | ||
const pc = new RTCPeerConnection({ | ||
iceServers: this.iceServers | ||
iceServers: this.iceServers, | ||
}); | ||
this.peer_connections[user_id][`${media}_${direction}`] = pc; | ||
pc.addEventListener('icecandidate', event => { | ||
pc.addEventListener('icecandidate', (event) => { | ||
this.handle_local_candidate(user_id, media, direction, event); | ||
}); | ||
pc.addEventListener('track', event => { | ||
pc.addEventListener('track', (event) => { | ||
this.handle_remote_track(user_id, media, event); | ||
@@ -482,6 +469,6 @@ }); | ||
}); | ||
pc.addEventListener('removetrack', event => { | ||
pc.addEventListener('removetrack', (event) => { | ||
this.handle_remove_track(user_id, media, event); | ||
}); | ||
pc.addEventListener('iceconnectionstatechange', event => { | ||
pc.addEventListener('iceconnectionstatechange', (event) => { | ||
this.handle_ice_connection_state_change(user_id, media, direction, event); | ||
@@ -530,3 +517,3 @@ }); | ||
if (!this.local_streams.mic) { | ||
this.start_mic().then(stream => { | ||
this.start_mic().then((stream) => { | ||
this.add_stream(stream, 'mic', peer_id); | ||
@@ -541,3 +528,3 @@ }); | ||
if (!this.local_streams.mic) { | ||
this.start_mic().then(stream => { | ||
this.start_mic().then((stream) => { | ||
this.add_stream(stream, 'mic', peer_id); | ||
@@ -549,3 +536,3 @@ }); | ||
if (!this.local_streams.camera) { | ||
this.start_camera().then(stream => { | ||
this.start_camera().then((stream) => { | ||
this.add_stream(stream, 'camera', peer_id); | ||
@@ -561,5 +548,5 @@ }); | ||
.getUserMedia({ | ||
video: true | ||
video: true, | ||
}) | ||
.then(stream => { | ||
.then((stream) => { | ||
this.local_streams.camera = stream; | ||
@@ -576,5 +563,5 @@ return stream; | ||
.getUserMedia({ | ||
audio: true | ||
audio: true, | ||
}) | ||
.then(stream => { | ||
.then((stream) => { | ||
this.local_streams.mic = stream; | ||
@@ -591,3 +578,3 @@ return stream; | ||
this.start_screensharing() | ||
.then(stream => { | ||
.then((stream) => { | ||
this.add_stream(stream, 'screen', peer_id); | ||
@@ -599,3 +586,3 @@ }) | ||
this.start_mic() | ||
.then(stream => { | ||
.then((stream) => { | ||
this.add_stream(stream, 'mic', peer_id); | ||
@@ -635,3 +622,3 @@ resolve(); | ||
payload: 'hang_up', | ||
recipient | ||
recipient, | ||
}); | ||
@@ -654,13 +641,10 @@ this.end_mic(); | ||
direction: 'p2e', | ||
...message | ||
...message, | ||
}, | ||
window.origin | ||
window.origin, | ||
); | ||
}; | ||
window.addEventListener('message', event => { | ||
if ( | ||
event.data.extension_tag === extension_tag && | ||
event.data.direction === 'e2p' | ||
) { | ||
window.addEventListener('message', (event) => { | ||
if (event.data.extension_tag === extension_tag && event.data.direction === 'e2p') { | ||
switch (event.data.type) { | ||
@@ -679,7 +663,7 @@ case 'helo': | ||
maxHeight: 1080, | ||
chromeMediaSourceId: event.data.streamId | ||
} | ||
} | ||
chromeMediaSourceId: event.data.streamId, | ||
}, | ||
}, | ||
}) | ||
.then(stream => { | ||
.then((stream) => { | ||
resolve(stream); | ||
@@ -694,3 +678,3 @@ }); | ||
send_ext({ | ||
type: 'ehlo' | ||
type: 'ehlo', | ||
}); | ||
@@ -702,3 +686,3 @@ setTimeout(() => { | ||
send_ext({ | ||
type: 'chooseDesktopMedia' | ||
type: 'chooseDesktopMedia', | ||
}); | ||
@@ -711,6 +695,6 @@ } | ||
video: { | ||
mediaSource: 'screen' | ||
} | ||
mediaSource: 'screen', | ||
}, | ||
}) | ||
.then(stream => { | ||
.then((stream) => { | ||
resolve(stream); | ||
@@ -725,5 +709,5 @@ }); | ||
timestamp: new Date(timestamp * 1000), | ||
...rest | ||
...rest, | ||
}; | ||
} | ||
} |
{ | ||
"name": "@conectar/conectar-ws", | ||
"version": "0.0.20", | ||
"description": "Conectar WS connections", | ||
"main": "dist/wire.js", | ||
"scripts": { | ||
"test": "jest", | ||
"build": "npx webpack --config webpack.config.js", | ||
"cypress": "npx cypress open" | ||
}, | ||
"keywords": [ | ||
"websocket", | ||
"conectar", | ||
"rtc", | ||
"webrtc", | ||
"real-time communication" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mayordwells/conectar-ws.git" | ||
}, | ||
"author": "Ashinze Ekene", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"babel": "^6.23.0", | ||
"babel-core": "^6.26.3", | ||
"babel-env": "^2.4.1", | ||
"babel-jest": "^23.6.0", | ||
"cypress": "^3.1.4", | ||
"eslint": "^5.11.1", | ||
"eslint-config-airbnb-base": "^13.1.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"regenerator-runtime": "^0.13.1", | ||
"webpack": "^4.28.3", | ||
"webpack-cli": "^3.1.2" | ||
} | ||
"name": "@conectar/conectar-ws", | ||
"version": "0.0.21", | ||
"description": "Conectar WS connections", | ||
"main": "dist/wire.js", | ||
"scripts": { | ||
"test": "jest", | ||
"build": "npx webpack --config webpack.config.js", | ||
"cypress": "npx cypress open" | ||
}, | ||
"keywords": [ | ||
"websocket", | ||
"conectar", | ||
"rtc", | ||
"webrtc", | ||
"real-time communication" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mayordwells/conectar-ws.git" | ||
}, | ||
"author": "Ashinze Ekene", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@babel/core": "^7.4.3", | ||
"@babel/preset-env": "^7.4.3", | ||
"babel-cli": "^6.26.0", | ||
"cypress": "^3.1.4", | ||
"eslint": "^5.11.1", | ||
"eslint-config-airbnb-base": "^13.1.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"webpack": "^4.28.3", | ||
"webpack-cli": "^3.1.2" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9
46170
741
1