Giter Site home page Giter Site logo

ably-labs / collaborative-pixel-drawing Goto Github PK

View Code? Open in Web Editor NEW
1.0 7.0 1.0 530 KB

A collaborative pixelart drawing carnvas to demonstrate pub/sub using Ably or Azure WebPubSub.

Home Page: https://pixel-paint.ably.dev/

License: Apache License 2.0

C# 12.62% JavaScript 47.92% HTML 11.85% CSS 2.20% Dockerfile 5.13% Shell 20.28%
ably demo websocket javascript serverless azure-functions pubsub dotnet

collaborative-pixel-drawing's Introduction

Collaborative pixelart drawing

Screenshot

Description

This repository contains an example how to synchronize state in realtime between many client devices using serverless WebSockets (Ably or Azure Web PubSub). The context of the example is a collaborative drawing canvas that multiple people can use at the same time to draw pixelart. The code in this repo is used in the blog post Cloud pubsub services compared: Azure Web PubSub vs Ably.

This repository contains two implementations of the same project:

This repository also contains a CodeTour for each of these branches, which you can use to navigate the code when you're using VSCode. You will be asked to download the CodeTour extension when you open the folder.

Tech stack

This project uses the following components:

  • p5js; A creative coding library, used for the drawing canvas.
  • Ably; A realtime messaging platform, used as the serverless WebSockets component.
  • Azure Functions; A serverless compute service from Microsoft Azure.
  • Azure Static Web Apps; An Azure service for hosting static websites.

Pubsub with Ably

The src folder contains the front-end files which are based on vanilla JavaScript and p5js.

The api folder contains a .NET 6 based Azure Function App with the following functions:

  • ChangeColorPalette; returns a color palette based on the paletteId that is provided.
  • CreateTokenRequest; provides an authentication token and is triggered when a connection to Ably is made via the front-end.

Building & running locally

Prerequisites

You require the following dependencies to run the solution locally:

  • .NET 6 SDK. The .NET SDK required for the C# Azure Functions.
  • Node 16. The JavaScript runtime required to install Azure Static WebApps CLI.
  • Azure Static Web Apps CLI. This is the command line interface to develop and deploy Azure Static Web Apps. Install this tool globally by running this command in the terminal: npm install -g @azure/static-web-apps-cli.
  • Azure Functions Core Tools. This is part of the Azure Functions extensions for VSCode that should be recommended for installation when this repo is opened in VSCode.
  • Sign up for a free Ably Account, create a new app, and copy the API key.

Building the project

  1. Clone or fork this repo.
  2. Rename the api\local.settings.json.example file to api\local.settings.json.
  3. Copy/paste the Ably API key in the ABLY_APIKEY field in the local.settings.json file.
  4. Run swa start in the root folder.

The local Static Web App should be available at http://localhost:4280.

Contributing

Want to help contributing to this project? Have a look at our contributing guide!

More info


Ably logo

collaborative-pixel-drawing's People

Contributors

dependabot[bot] avatar marcduiker avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

maxwilson

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.