diff --git a/server/package.json b/server/package.json index 93ada652389..83d1afa4b4d 100644 --- a/server/package.json +++ b/server/package.json @@ -57,6 +57,7 @@ "passport-linkedin": "^1.0.0", "passport-openidconnect": "0.0.1", "qtip2": "^3.0.3", + "quill": "^1.1.5", "redis": "^2.6.2", "reflect-metadata": "^0.1.8", "request": "^2.75.0", diff --git a/server/src/collab/collab.ts b/server/src/collab/collab.ts index 97c1fa1aa1f..d5d0f8a9b1d 100644 --- a/server/src/collab/collab.ts +++ b/server/src/collab/collab.ts @@ -1,3 +1,36 @@ import * as io from 'socket.io-client'; +import * as Quill from 'quill'; +import * as $ from 'jquery'; -let socket = io(); \ No newline at end of file +let socket = io(); + +socket.on('user connect', (msg) => { + $("#console").append('
New user connected
'); +}); + +socket.on('user disconnect', (msg) => { + $("#console").append('
User disconnected
'); +}); + +// Implement and register module +Quill.register('modules/counter', function(quill, options) { + var container = document.querySelector(options.container); + quill.on('text-change', function() { + var text = quill.getText(); + // There are a couple issues with counting words + // this way but we'll fix these later + container.innerHTML = text.split(/\s+/).length; + + socket.emit('chat message', text); + }); +}); + +var editor = new Quill('#editor', { + modules: { + toolbar: '#toolbar', + counter: { + container: '#counter' + } + }, + theme: 'snow' +}); \ No newline at end of file diff --git a/server/src/io.ts b/server/src/io.ts index 7b919418717..e073eaf3e67 100644 --- a/server/src/io.ts +++ b/server/src/io.ts @@ -3,8 +3,15 @@ import socketIo = require('socket.io'); var io = socketIo(); io.on('connection', (socket) => { - console.log('a user connected!'); + socket.on('chat message', (msg) => { + console.log(`message: ` + msg); + }); + + socket.on('disconnect', () => { + socket.broadcast.emit('user disconnect'); + }) + + socket.broadcast.emit('user connect', 'hi'); }); - export default io; \ No newline at end of file diff --git a/server/typings.json b/server/typings.json index 8d3a3c5112f..cd861bf57fb 100644 --- a/server/typings.json +++ b/server/typings.json @@ -9,6 +9,7 @@ "node": "registry:env/node#4.0.0+20160918225031", "passport": "registry:dt/passport#0.2.0+20160720063208", "qtip2": "registry:dt/qtip2#2.2.1+20160317120654", + "quill": "registry:dt/quill#1.1.0+20161025144844", "socket.io": "registry:dt/socket.io#1.4.4+20160909205835", "socket.io-client": "registry:dt/socket.io-client#1.4.4+20160317120654" }, diff --git a/server/views/collab.hjs b/server/views/collab.hjs index d2c7acd6c12..4f210b191e7 100644 --- a/server/views/collab.hjs +++ b/server/views/collab.hjs @@ -16,36 +16,12 @@

Hello World!

-
+
+
{{/content}} {{$scripts}} - - - - - - + + {{/scripts}} {{/layout}} \ No newline at end of file