Coder Social home page Coder Social logo

sudhakar-r08 / socket.io-whiteboard Goto Github PK

View Code? Open in Web Editor NEW

This project forked from over-engineer/socket.io-whiteboard

0.0 0.0 0.0 363 KB

🎨 HTML5 canvas real-time drawing using socket.io

Home Page: https://socketio-whiteboard.herokuapp.com/

License: MIT License

JavaScript 100.00%

socket.io-whiteboard's Introduction

Socket.io whiteboard

GitHub GitHub last commit Demo

🎨 HTML5 canvas real-time drawing using socket.io

Table of Contents

πŸ–Œ What is this?

This is a simplified version of the JavaScript code I use for a sketch guessing multiplayer game I'm working on I used to work on. Keep in mind that it's still under development as I'm experimenting with different ways to build this. Still, this could be a nice start for similar projects a very bare-bones version, which is only useful as a starting point for your own projects.

πŸ“¦ Installation

  1. Include Socket.io in your client-side code

    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"
            integrity="sha256-yr4fRk/GU1ehYJPAs8P4JlTgu0Hdsp4ZKrx8bDEDC3I="
            crossorigin="anonymous"></script>
  2. Include this library in your client-side code

    <script src="https://cdn.jsdelivr.net/gh/over-engineer/[email protected]/lib/whiteboard.js"
            integrity="sha384-RceltRoqS8zq7xl4btt0biBpy99d2+11CCTBAmBgfTkXshR6iIr5Lap4tXBA/lnh"
            crossorigin="anonymous"></script>
  3. Create a Whiteboard instance using new Whiteboard(), passing your canvas, your socket and optionally a default color and thickness.

    For example:

    const canvas = document.querySelector('canvas');
    const whiteboard = new Whiteboard(canvas, socket);
  4. For the server-side, check the /demo/backend directory

πŸŽ‰ Demo

Check out the demo (open the console!)

You can also:

Deploy

…or do it yourself:

  1. Make sure you have Node.js installed.

  2. Clone this repository

    $ git clone [email protected]:over-engineer/Socket.io-whiteboard.git
    $ cd ./Socket.io-whiteboard
    
  3. Install the dependencies

    $ npm install
    
  4. Start the server

    $ npm start
    
  5. Go to localhost:3000

πŸ“š Documentation

The demo has the bare minimum functionality to keep it as simple as possible.

In a real-world scenario you would have to customize the color, the thickness of the line, download drawings etc

These are the public methods you'll find in the /lib/whiteboard.js file:

Method Explanation
whiteboard.color = newValue Sets the line color to the given value
whiteboard.color Returns the current color of the line
whiteboard.thickness = newValue Sets the line thickness to the given value
whiteboard.thickness Returns the current thickness of the line
whiteboard.increaseThickness(step) Increases the thickness of the line by the given step
whiteboard.decreaseThickness(step) Decreases the thickness of the line by the given step
whiteboard.download(filename) Exports the canvas drawing as an image file and saves it with the given name
whiteboard.clear() Clears the entire canvas

In the above table whiteboard is an instance of Whiteboard

πŸ—„ Dependencies

πŸ“– License

The MIT License, check the LICENSE file.

socket.io-whiteboard's People

Contributors

over-engineer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.