diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..ff23b07 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,36 @@ +# Javascript Node CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-javascript/ for more details +# +version: 2 +jobs: + build: + docker: + # specify the version you desire here + - image: circleci/node:8.10 + + # Specify service dependencies here if necessary + # CircleCI maintains a library of pre-built images + # documented at https://circleci.com/docs/2.0/circleci-images/ + # - image: circleci/mongo:3.4.4 + + working_directory: ~/repo + + steps: + - checkout + + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "yarn.lock" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + + - run: yarn install + + - save_cache: + paths: + - node_modules + key: v1-dependencies-{{ checksum "yarn.lock" }} + + - run: yarn test \ No newline at end of file diff --git a/.gitignore b/.gitignore index 15dfd69..0144959 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ .DS_Store -server -client node_modules *.log \ No newline at end of file diff --git a/build.sh b/build.sh index 7588baf..30f3b79 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,3 @@ -yarn setup - echo "building client..." cd client yarn --production=false diff --git a/client/.env.example b/client/.env.example new file mode 100644 index 0000000..2695add --- /dev/null +++ b/client/.env.example @@ -0,0 +1,4 @@ +REACT_APP_API_HOST=localhost +REACT_APP_API_PROTOCOL=http +REACT_APP_API_PORT=3001 +REACT_APP_COMMIT_SHA=some_sha \ No newline at end of file diff --git a/client/.gitignore b/client/.gitignore new file mode 100644 index 0000000..e2178dd --- /dev/null +++ b/client/.gitignore @@ -0,0 +1,9 @@ +node_modules +.DS_Store +dist +coverage +*.log +.env* +!.env.example +build/ +*sublime* \ No newline at end of file diff --git a/client/LICENSE b/client/LICENSE new file mode 100644 index 0000000..94da581 --- /dev/null +++ b/client/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016-present darkwire.io + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/client/README.md b/client/README.md new file mode 100644 index 0000000..076caff --- /dev/null +++ b/client/README.md @@ -0,0 +1,3 @@ +# Darkwire Client + +This is the client for [Darkwire](https://github.com/darkwire/darkwire.io). It requires [darkwire-server](../server) in order to run. \ No newline at end of file diff --git a/client/__mocks__/styles.js b/client/__mocks__/styles.js new file mode 100644 index 0000000..f053ebf --- /dev/null +++ b/client/__mocks__/styles.js @@ -0,0 +1 @@ +module.exports = {}; diff --git a/client/jsconfig.json b/client/jsconfig.json new file mode 100644 index 0000000..e9dfe87 --- /dev/null +++ b/client/jsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "baseUrl": "src", + "paths": { + "@/*":["src/*"] + } + } +} \ No newline at end of file diff --git a/client/package.json b/client/package.json new file mode 100644 index 0000000..4d73eb2 --- /dev/null +++ b/client/package.json @@ -0,0 +1,69 @@ +{ + "name": "darkwire-client", + "version": "2.0.0-beta.12", + "main": "index.js", + "contributors": [ + { + "name": "Daniel Seripap" + }, + { + "name": "Alan Friedman" + } + ], + "license": "MIT", + "dependencies": { + "autosize": "^4.0.2", + "bootstrap": "^4.3.1", + "clipboard": "^2.0.4", + "feather-icons": "^4.21.0", + "jquery": "^3.4.1", + "lodash": "^4.17.11", + "moment": "^2.24.0", + "node-sass": "^4.12.0", + "popper.js": "^1.15.0", + "query-string": "^6.5.0", + "randomcolor": "^0.5.4", + "react": "^16.8.6", + "react-dom": "^16.8.6", + "react-feather": "^1.1.6", + "react-linkify": "^0.2.2", + "react-modal": "^3.8.1", + "react-redux": "^7.0.3", + "react-router-dom": "^5.0.0", + "react-scripts": "3.0.0", + "react-simple-dropdown": "^3.2.3", + "redux": "^4.0.1", + "redux-thunk": "^2.3.0", + "sanitize-html": "^1.20.1", + "shortid": "^2.2.14", + "socket.io-client": "^2.2.0", + "tinycon": "^0.6.8", + "webcrypto-shim": "^0.1.4" + }, + "scripts": { + "start": "react-scripts start", + "build": "REACT_APP_COMMIT_SHA=`git rev-parse --short HEAD` react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": "react-app" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + }, + "devDependencies": { + "enzyme": "^3.9.0", + "enzyme-adapter-react-16": "^1.12.1", + "enzyme-to-json": "^3.3.5" + } +} diff --git a/client/public/favicon.ico b/client/public/favicon.ico new file mode 100644 index 0000000..359faae Binary files /dev/null and b/client/public/favicon.ico differ diff --git a/client/public/index.html b/client/public/index.html new file mode 100644 index 0000000..44f94b9 --- /dev/null +++ b/client/public/index.html @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + darkwire.io - instant encrypted web chat + + + +
+ + + diff --git a/client/public/manifest.json b/client/public/manifest.json new file mode 100644 index 0000000..2553b79 --- /dev/null +++ b/client/public/manifest.json @@ -0,0 +1,15 @@ +{ + "short_name": "Darkwire", + "name": "Darkwire.io - encrypted web chat", + "icons": [ + { + "src": "favicon.ico", + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} diff --git a/client/src/actions/app.js b/client/src/actions/app.js new file mode 100644 index 0000000..42e37f5 --- /dev/null +++ b/client/src/actions/app.js @@ -0,0 +1,20 @@ +export const openModal = payload => ({ type: 'OPEN_MODAL', payload }) +export const closeModal = () => ({ type: 'CLOSE_MODAL' }) + +export const setScrolledToBottom = payload => ({ type: 'SET_SCROLLED_TO_BOTTOM', payload }) + +export const showNotice = payload => async (dispatch) => { + dispatch({ type: 'SHOW_NOTICE', payload }) +} + +export const toggleWindowFocus = payload => async (dispatch) => { + dispatch({ type: 'TOGGLE_WINDOW_FOCUS', payload }) +} + +export const toggleSoundEnabled = payload => async (dispatch) => { + dispatch({ type: 'TOGGLE_SOUND_ENABLED', payload }) +} + +export const toggleSocketConnected = payload => async (dispatch) => { + dispatch({ type: 'TOGGLE_SOCKET_CONNECTED', payload }) +} diff --git a/client/src/actions/fetch.js b/client/src/actions/fetch.js new file mode 100644 index 0000000..cfa95c8 --- /dev/null +++ b/client/src/actions/fetch.js @@ -0,0 +1,12 @@ +const methodMap = { + GET: '', + POST: 'CREATE_', + PUT: 'UPDATE_', + DELETE: 'DELETE_', +} + +export const fetchStart = (name, method, resourceId, meta) => ({ type: `FETCH_${methodMap[method]}${name.toUpperCase()}_START`, payload: { resourceId, meta } }) + +export const fetchSuccess = (name, method, response) => ({ type: `FETCH_${methodMap[method]}${name.toUpperCase()}_SUCCESS`, payload: response }) + +export const fetchFailure = (name, method, response) => ({ type: `FETCH_${methodMap[method]}${name.toUpperCase()}_FAILURE`, payload: response }) diff --git a/client/src/actions/index.js b/client/src/actions/index.js new file mode 100644 index 0000000..1297389 --- /dev/null +++ b/client/src/actions/index.js @@ -0,0 +1,4 @@ +export * from './fetch' +export * from './room' +export * from './app' + diff --git a/client/src/actions/room.js b/client/src/actions/room.js new file mode 100644 index 0000000..37b9eff --- /dev/null +++ b/client/src/actions/room.js @@ -0,0 +1,98 @@ +import fetch from 'api' +import isEqual from 'lodash/isEqual' +import { + process as processMessage, + prepare as prepareMessage, +} from 'utils/message' +import { getIO } from 'utils/socket' + +export const createRoom = id => async dispatch => fetch({ + resourceName: 'handshake', + method: 'POST', + body: { + roomId: id, + }, +}, dispatch, 'handshake') + +export const receiveSocketMessage = payload => async (dispatch, getState) => { + const state = getState() + const message = await processMessage(payload, state) + // Pass current state to all HANDLE_SOCKET_MESSAGE reducers for convenience, since each may have different needs + dispatch({ type: `HANDLE_SOCKET_MESSAGE_${message.type}`, payload: { payload: message.payload, state } }) +} + +export const createUser = payload => async (dispatch) => { + dispatch({ type: 'CREATE_USER', payload }) +} + +export const sendUserEnter = payload => async () => { + getIO().emit('USER_ENTER', { + publicKey: payload.publicKey, + }) +} + +export const receiveUserExit = payload => async (dispatch, getState) => { + const state = getState() + const exitingUser = state.room.members.find(m => !payload.map(p => JSON.stringify(p.publicKey)).includes(JSON.stringify(m.publicKey))) + const exitingUserId = exitingUser.id + const exitingUsername = exitingUser.username + + dispatch({ + type: 'USER_EXIT', + payload: { + members: payload, + id: exitingUserId, + username: exitingUsername, + }, + }) +} + +export const receiveUserEnter = payload => async (dispatch) => { + dispatch({ type: 'USER_ENTER', payload }) +} + +export const onFileTransfer = payload => async (dispatch) => { + dispatch({ type: 'PREFLIGHT_FILE_TRANSFER', payload }) +} + +export const sendSocketMessage = payload => async (dispatch, getState) => { + const state = getState() + const msg = await prepareMessage(payload, state) + dispatch({ type: `SEND_SOCKET_MESSAGE_${msg.original.type}`, payload: msg.original.payload }) + getIO().emit('PAYLOAD', msg.toSend) +} + +export const toggleLockRoom = () => async (dispatch, getState) => { + const state = getState() + getIO().emit('TOGGLE_LOCK_ROOM', null, (res) => { + dispatch({ + type: 'TOGGLE_LOCK_ROOM', + payload: { + locked: res.isLocked, + username: state.user.username, + sender: state.user.id, + }, + }) + }) +} + +export const receiveToggleLockRoom = payload => async (dispatch, getState) => { + const state = getState() + + const lockedByUser = state.room.members.find(m => isEqual(m.publicKey, payload.publicKey)) + const lockedByUsername = lockedByUser.username + const lockedByUserId = lockedByUser.id + + dispatch({ + type: 'RECEIVE_TOGGLE_LOCK_ROOM', + payload: { + username: lockedByUsername, + locked: payload.locked, + id: lockedByUserId, + }, + }) +} + +export const clearActivities = () => async (dispatch) => { + dispatch({ type: 'CLEAR_ACTIVITIES' }) +} diff --git a/client/src/api/config.js b/client/src/api/config.js new file mode 100644 index 0000000..30e1c50 --- /dev/null +++ b/client/src/api/config.js @@ -0,0 +1,26 @@ +let host +let protocol +let port + +switch (process.env.NODE_ENV) { + case 'staging': + host = process.env.REACT_APP_API_HOST + protocol = process.env.REACT_APP_API_PROTOCOL || 'https' + port = process.env.REACT_APP_API_PORT || 443 + break + case 'production': + host = process.env.REACT_APP_API_HOST + protocol = process.env.REACT_APP_API_PROTOCOL || 'https' + port = process.env.REACT_APP_API_PORT || 443 + break + default: + host = process.env.REACT_APP_API_HOST || 'localhost' + protocol = process.env.REACT_APP_API_PROTOCOL || 'http' + port = process.env.REACT_APP_API_PORT || 3001 +} + +export default { + host, + port, + protocol, +} diff --git a/client/src/api/generator.js b/client/src/api/generator.js new file mode 100644 index 0000000..9dd44f1 --- /dev/null +++ b/client/src/api/generator.js @@ -0,0 +1,13 @@ +import config from './config' + +export default (resourceName = '') => { + const { port, protocol, host } = config + + const resourcePath = resourceName + + if (!host) { + return `/${resourcePath}`; + } + + return `${protocol}://${host}:${port}/${resourcePath}` +} diff --git a/client/src/api/index.js b/client/src/api/index.js new file mode 100644 index 0000000..b4f627e --- /dev/null +++ b/client/src/api/index.js @@ -0,0 +1,59 @@ +import { + fetchStart, + fetchSuccess, + fetchFailure, +} from 'actions' +import queryString from 'querystring' +import generateUrl from './generator' + +export default (opts, dispatch, name, metaOpts = {}) => { + const method = opts.method || 'GET' + const resourceId = opts.resourceId + let url = generateUrl(opts.resourceName, resourceId) + + const config = { + method, + headers: {}, + type: 'cors', + } + + if (opts.body) { + config.body = JSON.stringify(opts.body) + config.headers['Content-Type'] = 'application/json' + } + + if (opts.query) { + url = `${url}?${queryString.stringify(opts.query)}` + } + + return new Promise((resolve, reject) => { + const meta = { ...metaOpts, timestamp: Date.now() } + dispatch(fetchStart(name, method, resourceId, meta)) + return window.fetch(url, config) + .then(async (response) => { + let json = {} + + try { + json = await response.json() + } catch (e) { + throw new Error(e) + } + + const dispatchOps = { + response, + json, + resourceId, + meta, + } + + if (response.ok) { + dispatch(fetchSuccess(name, method, dispatchOps)) + return resolve(dispatchOps) + } + + dispatch(fetchFailure(name, method, dispatchOps)) + + return reject(dispatchOps) + }) + }) +} diff --git a/client/src/audio/beep.mp3 b/client/src/audio/beep.mp3 new file mode 100644 index 0000000..738c24f Binary files /dev/null and b/client/src/audio/beep.mp3 differ diff --git a/client/src/components/About/index.js b/client/src/components/About/index.js new file mode 100644 index 0000000..1c2c7eb --- /dev/null +++ b/client/src/components/About/index.js @@ -0,0 +1,198 @@ +/* eslint-disable */ +import React, { Component } from 'react' +import PropTypes from 'prop-types' +import apiUrlGenerator from '../../api/generator'; + +class About extends Component { + constructor(props) { + super(props); + this.state = { + roomId: props.roomId, + abuseReported: false + } + } + + handleUpdateRoomId(evt) { + this.setState({ + roomId: evt.target.value, + }) + } + + handleReportAbuse(evt) { + evt.preventDefault(); + fetch(`${apiUrlGenerator('abuse')}/${this.state.roomId}`, { + method: 'POST' + }); + this.setState({ + abuseReported: true, + }) + } + + render() { + return ( +
+

Version

+

Client + Commit SHA: {process.env.REACT_APP_COMMIT_SHA}

+

Server + Commit SHA: {this.props.serverSHA}

+
+ +

Software

+

This software uses the Web Cryptography API to + encrypt data which is transferred using secure WebSockets. + Messages are never stored on a server or sent over the wire in plain-text.

+

We believe in privacy and transparency. +  View the source code and documentation on GitHub.

+
+ +

Report Abuse

+

To report any content that violates our Acceptable Use Policy below, email us at abuse[at]darkwire.io or submit the room ID below to report anonymously.

+
+ {this.state.abuseReported &&
Thank you!
} +
+ + +
+
+
+ +

Acceptable Use Policy

+ +

This Acceptable Use Policy (this “Policy”) describes prohibited uses of the web services offered by Darkwire and its affiliates (the “Services”) and the website located at https://darkwire.io (the “Darkwire Site”). The examples described in this Policy are not exhaustive. We may modify this Policy at any time by posting a revised version on the Darkwire Site. By using the Services or accessing the Darkwire Site, you agree to the latest version of this Policy. If you violate the Policy or authorize or help others to do so, we may suspend or terminate your use of the Services.

+ + No Illegal, Harmful, or Offensive Use or Content +

You may not use, or encourage, promote, facilitate or instruct others to use, the Services or Darkwire Site for any illegal, harmful, fraudulent, infringing or offensive use, or to transmit, store, display, distribute or otherwise make available content that is illegal, harmful, fraudulent, infringing or offensive. Prohibited activities or content include:

+ + + + No Security Violations +
You may not use the Services to violate the security or integrity of any network, computer or communications system, software application, or network or computing device (each, a “System”). Prohibited activities include: + + + + No Network Abuse +
You may not make network connections to any users, hosts, or networks unless you have permission to communicate with them. Prohibited activities include: + + + + No E-Mail or Other Message Abuse +
You will not distribute, publish, send, or facilitate the sending of unsolicited mass e-mail or other messages, promotions, advertising, or solicitations (like “spam”), including commercial advertising and informational announcements. You will not alter or obscure mail headers or assume a sender’s identity without the sender’s explicit permission. You will not collect replies to messages sent from another internet service provider if those messages violate this Policy or the acceptable use policy of that provider. + + Our Monitoring and Enforcement +
We reserve the right, but do not assume the obligation, to investigate any violation of this Policy or misuse of the Services or Darkwire Site. We may: + + + Reporting of Violations of this Policy +
If you become aware of any violation of this Policy, you will immediately notify us and provide us with assistance, as requested, to stop or remedy the violation. To report any violation of this Policy, please follow our abuse reporting process. +
+
+ +

Disclaimer

+

WARNING: Darkwire does not mask IP addresses nor can verify the integrity of parties recieving messages. +  Proceed with caution and always confirm recipients beforre starting a chat session.

+

Please also note that ALL CHATROOMS are public. +  Anyone can guess your room URL. If you need a more-private room, use the lock feature or set the URL manually by entering a room ID after "darkwire.io/". +

+
+ +

Terms of Service ("Terms")

+

Last updated: December 11, 2017

+

Please read these Terms of Service ("Terms", "Terms of Service") carefully before using the https://darkwire.io website (the "Service") operated by Darkwire ("us", "we", or "our").

+

Your access to and use of the Service is conditioned on your acceptance of and compliance with these Terms. These Terms apply to all visitors, users and others who access or use the Service.

+

By accessing or using the Service you agree to be bound by these Terms. If you disagree with any part of the terms then you may not access the Service.

+ Links To Other Web Sites +

Our Service may contain links to third-party web sites or services that are not owned or controlled by Darkwire.

+

Darkwire has no control over, and assumes no responsibility for, the content, privacy policies, or practices of any third party web sites or services. You further acknowledge and agree that Darkwire shall not be responsible or liable, directly or indirectly, for any damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such content, goods or services available on or through any such web sites or services.

+

We strongly advise you to read the terms and conditions and privacy policies of any third-party web sites or services that you visit.

+ Termination +

We may terminate or suspend access to our Service immediately, without prior notice or liability, for any reason whatsoever, including without limitation if you breach the Terms.

+

All provisions of the Terms which by their nature should survive termination shall survive termination, including, without limitation, ownership provisions, + warranty disclaimers, indemnity and limitations of liability.

+ Governing Law +

These Terms shall be governed and construed in accordance with the laws of New York, United States, without regard to its conflict of law provisions.

+

Our failure to enforce any right or provision of these Terms will not be considered a waiver of those rights. If any provision of these Terms is held to be +invalid or unenforceable by a court, the remaining provisions of these Terms will remain in effect. These Terms constitute the entire agreement between us +regarding our Service, and supersede and replace any prior agreements we might have between us regarding the Service.

+ No Warranties; Exclusion of Liability; Indemnification +

OUR WEBSITE IS OPERATED BY Darkwire ON AN "AS IS," "AS AVAILABLE" BASIS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY KIND. TO THE FULLEST EXTENT PERMITTED BY LAW, Darkwire SPECIFICALLY DISCLAIMS ALL WARRANTIES AND CONDITIONS OF ANY KIND, INCLUDING ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NONINFRINGEMENT FOR OUR WEBSITE AND ANY CONTRACTS AND SERVICES YOU PURCHASE THROUGH IT. Darkwire SHALL NOT HAVE ANY LIABILITY OR RESPONSIBILITY FOR ANY ERRORS OR OMISSIONS IN THE CONTENT OF OUR WEBSITE, FOR CONTRACTS OR SERVICES SOLD THROUGH OUR WEBSITE, FOR YOUR ACTION OR INACTION IN CONNECTION WITH OUR WEBSITE OR FOR ANY DAMAGE TO YOUR COMPUTER OR DATA OR ANY OTHER DAMAGE YOU MAY INCUR IN CONNECTION WITH OUR WEBSITE. YOUR USE OF OUR WEBSITE AND ANY CONTRACTS OR SERVICES ARE AT YOUR OWN RISK. IN NO EVENT SHALL EITHER Darkwire OR THEIR AGENTS BE LIABLE FOR ANY DIRECT, INDIRECT, PUNITIVE, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN ANY WAY CONNECTED WITH THE USE OF OUR WEBSITE, CONTRACTS AND SERVICES PURCHASED THROUGH OUR WEBSITE, THE DELAY OR INABILITY TO USE OUR WEBSITE OR OTHERWISE ARISING IN CONNECTION WITH OUR WEBSITE, CONTRACTS OR RELATED SERVICES, WHETHER BASED ON CONTRACT, +TORT, STRICT LIABILITY OR OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF ANY SUCH DAMAGES. IN NO EVENT SHALL Darkwire’s LIABILITY FOR ANY DAMAGE CLAIM EXCEED THE AMOUNT PAID BY YOU TO Darkwire FOR THE TRANSACTION GIVING RISE TO SUCH DAMAGE CLAIM.

+

SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THE ABOVE EXCLUSION MAY NOT APPLY TO YOU.

+

WITHOUT LIMITING THE FOREGOING, Darkwire DO NOT REPRESENT OR WARRANT THAT THE INFORMATION ON THE WEBITE IS ACCURATE, COMPLETE, RELIABLE, USEFUL, TIMELY OR CURRENT OR THAT OUR WEBSITE WILL OPERATE WITHOUT INTERRUPTION OR ERROR.

+

YOU AGREE THAT ALL TIMES, YOU WILL LOOK TO ATTORNEYS FROM WHOM YOU PURCHASE SERVICES FOR ANY CLAIMS OF ANY NATURE, INCLUDING LOSS, DAMAGE, OR WARRANTY. Darkwire AND THEIR RESPECTIVE AFFILIATES MAKE NO REPRESENTATION OR GUARANTEES ABOUT ANY CONTRACTS AND SERVICES OFFERED THROUGH OUR WEBSITE.

+

Darkwire MAKES NO REPRESENTATION THAT CONTENT PROVIDED ON OUR WEBSITE, CONTRACTS, OR RELATED SERVICES ARE APPLICABLE OR APPROPRIATE FOR USE IN ALL +JURISDICTIONS.

+ Indemnification +

You agree to defend, indemnify and hold Darkwire harmless from and against any and all claims, damages, costs and expenses, including attorneys' fees, arising +from or related to your use of our Website or any Contracts or Services you purchase through it.

+ Changes +

We reserve the right, at our sole discretion, to modify or replace these Terms at any time. If a revision is material we will try to provide at least 30 days notice prior to any new terms taking effect. What constitutes a material change will be determined at our sole discretion.

+

By continuing to access or use our Service after those revisions become effective, you agree to be bound by the revised terms. If you do not agree to the new +terms, please stop using the Service.

+ Contact Us +

If you have any questions about these Terms, please contact us at hello[at]darkwire.io.

+
+ +

Contact

+

Questions/comments? Email us at hello[at]darkwire.io

+

Found a bug or want a new feature? Open a ticket on Github.

+
+ +

Donate

+

Darkwire is maintained and hosted by two developers with full-time jobs. If you get some value + from this service we would appreciate any donation you can afford. We use these funds for + server and DNS costs. Thank you! +

+ Bitcoin +

189sPnHGcjP5uteg2UuNgcJ5eoaRAP4Bw4

+ Ethereum +

0xD6e3D881036903999E2c0480fe9d2c20600C1c28

+ Litecoin +

LUViQeSggBBtYoN2qNtXSuxYoRMzRY8CSX

+ PayPal: +
+
+ + + + +
+
+ ) + } +} + +About.propTypes = { + serverSHA: PropTypes.string.isRequired, + roomId: PropTypes.string.isRequired, +} + +export default About diff --git a/client/src/components/Chat/Chat.test.js b/client/src/components/Chat/Chat.test.js new file mode 100644 index 0000000..a33de83 --- /dev/null +++ b/client/src/components/Chat/Chat.test.js @@ -0,0 +1,17 @@ +import React from 'react' +import { mount } from 'enzyme' +import toJson from 'enzyme-to-json' +import { Chat } from './index.js' + +const sendSocketMessage = jest.fn() + +test('Chat Component', () => { + const component = mount( + {}} focusChat={false} userId="foo" username="user" showNotice={() => {}} clearActivities={() => {}} sendSocketMessage={sendSocketMessage} /> + ) + + const componentJSON = toJson(component) + + expect(component).toMatchSnapshot() + expect(componentJSON.children.length).toBe(1) +}) diff --git a/client/src/components/Chat/__snapshots__/Chat.test.js.snap b/client/src/components/Chat/__snapshots__/Chat.test.js.snap new file mode 100644 index 0000000..0627a01 --- /dev/null +++ b/client/src/components/Chat/__snapshots__/Chat.test.js.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Chat Component 1`] = `ReactWrapper {}`; diff --git a/client/src/components/Chat/index.js b/client/src/components/Chat/index.js new file mode 100644 index 0000000..f2ba71d --- /dev/null +++ b/client/src/components/Chat/index.js @@ -0,0 +1,294 @@ +import React, { Component } from 'react' +import PropTypes from 'prop-types' +import sanitizeHtml from 'sanitize-html' +import FileTransfer from 'components/FileTransfer' +import { CornerDownRight } from 'react-feather' +import { connect } from 'react-redux' +import { clearActivities, showNotice } from '../../actions' +import { getSelectedText, hasTouchSupport } from '../../utils/dom' +// Disable for now +// import autosize from 'autosize' + +export class Chat extends Component { + constructor(props) { + super(props) + this.state = { + message: '', + touchSupport: hasTouchSupport, + shiftKeyDown: false, + } + + this.commands = [{ + command: 'nick', + description: 'Changes nickname.', + paramaters: ['{username}'], + usage: '/nick {username}', + scope: 'global', + action: (params) => { // eslint-disable-line + let newUsername = params.join(' ') || '' // eslint-disable-line + + // Remove things that arent digits or chars + newUsername = newUsername.replace(/[^A-Za-z0-9]/g, '-') + + const errors = [] + + if (!newUsername.trim().length) { + errors.push('Username cannot be blank') + } + + if (newUsername.toString().length > 16) { + errors.push('Username cannot be greater than 16 characters') + } + + if (!newUsername.match(/^[A-Z]/i)) { + errors.push('Username must start with a letter') + } + + if (errors.length) { + return this.props.showNotice({ + message: `${errors.join(', ')}`, + level: 'error', + }) + } + + this.props.sendSocketMessage({ + type: 'CHANGE_USERNAME', + payload: { + id: this.props.userId, + newUsername, + currentUsername: this.props.username, + }, + }) + }, + }, { + command: 'help', + description: 'Shows a list of commands.', + paramaters: [], + usage: '/help', + scope: 'local', + action: (params) => { // eslint-disable-line + const validCommands = this.commands.map(command => `/${command.command}`) + this.props.showNotice({ + message: `Valid commands: ${validCommands.sort().join(', ')}`, + level: 'info', + }) + }, + }, { + command: 'me', + description: 'Invoke virtual action', + paramaters: ['{action}'], + usage: '/me {action}', + scope: 'global', + action: (params) => { // eslint-disable-line + const actionMessage = params.join(' ') + if (!actionMessage.trim().length) { + return false + } + + this.props.sendSocketMessage({ + type: 'USER_ACTION', + payload: { + action: actionMessage, + }, + }) + }, + }, { + command: 'clear', + description: 'Clears the chat screen', + paramaters: [], + usage: '/clear', + scope: 'local', + action: (params = null) => { // eslint-disable-line + this.props.clearActivities() + }, + }] + } + + componentDidMount() { + if (!hasTouchSupport) { + // Disable for now due to vary issues: + // Paste not working, shift+enter line breaks + // autosize(this.textInput); + this.textInput.addEventListener('autosize:resized', () => { + this.props.scrollToBottom() + }) + } + } + + componentWillReceiveProps(nextProps) { + if (nextProps.focusChat) { + if (!getSelectedText()) { + // Don't focus for now, evaulate UX benfits + // this.textInput.focus() + } + } + } + + componentDidUpdate(nextProps, nextState) { + if (!nextState.message.trim().length) { + // autosize.update(this.textInput) + } + } + + handleKeyUp(e) { + if (e.key === 'Shift') { + this.setState({ + shiftKeyDown: false, + }) + } + } + + handleKeyPress(e) { + if (e.key === 'Shift') { + this.setState({ + shiftKeyDown: true, + }) + } + // Fix when autosize is enabled - line breaks require shift+enter twice + if (e.key === 'Enter' && !hasTouchSupport && !this.state.shiftKeyDown) { + e.preventDefault() + if (this.canSend()) { + this.sendMessage() + } else { + this.setState({ + message: '', + }) + } + } + } + + executeCommand(command) { + const commandToExecute = this.commands.find(cmnd => cmnd.command === command.command) + + if (commandToExecute) { + const { params } = command + const commandResult = commandToExecute.action(params) + + return commandResult + } + + return null + } + + handleSendClick() { + this.sendMessage.bind(this) + this.textInput.focus() + } + + handleFormSubmit(evt) { + evt.preventDefault() + this.sendMessage() + } + + parseCommand(message) { + const commandTrigger = { + command: null, + params: [], + } + + if (message.charAt(0) === '/') { + const parsedCommand = message.replace('/', '').split(' ') + commandTrigger.command = sanitizeHtml(parsedCommand[0]) || null + // Get params + if (parsedCommand.length >= 2) { + for (let i = 1; i < parsedCommand.length; i++) { + commandTrigger.params.push(parsedCommand[i]) + } + } + + return commandTrigger + } + + return false + } + + sendMessage() { + if (!this.canSend()) { + return + } + + const { message } = this.state + const isCommand = this.parseCommand(message) + + if (isCommand) { + const res = this.executeCommand(isCommand) + if (res === false) { + return + } + } else { + this.props.sendSocketMessage({ + type: 'SEND_MESSAGE', + payload: { + text: message, + timestamp: Date.now(), + }, + }) + } + + this.setState({ + message: '', + }) + } + + handleInputChange(evt) { + this.setState({ + message: evt.target.value, + }) + } + + canSend() { + return this.state.message.trim().length + } + + render() { + const touchSupport = this.state.touchSupport + + return ( +
+