Giter Site home page Giter Site logo

benjohansen / websockets-in-max Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 205 KB

Example projects showing how to use websockets (Socket.io) to send data back and forth between Max and a website over the internet.

License: MIT License

JavaScript 8.81% Max 88.16% HTML 3.04%
examples javascript max maxmsp n4m nodeformax nodejs socket-io tutorial websockets chat cycling74 html js maxpat

websockets-in-max's Introduction

node for max and socket.io

Websockets in Max (Tutorials)

These example projects show how to use websockets (Socket.io) to send data back and forth between Max and a website over the internet (computers running Max and devices accessing the website can be in different parts of the world). Each project builds upon the last.

Check out the YouTube Tutorial !!!

List of Projects

  1. Bang! ... YouTube - How this Bang Project Works
    • send bangs back and forth between a website and Max
  2. Simple Chat ... YouTube - How this Simple Chat Works
    • send messages back and forth between a website and Max
  3. JS Objects! [dict] ... YouTube - How sending JS Objects Works
    • a more advanced chat
    • send objects (dictionaries) back and forth between a website and Max

 

Installation (Setup)

Setup instructions starts here in the Youtube Video Tutorial.

 

  1. Download this entire repository.

Each project directory has the same directory structure (web-server, web-client, and max-client) with all the files you need for that individual project.

 

web-server Installation

YouTube Setup web-server

The web server simply listens for (receives) messages (named events containing data) each connected client sends and is able to send them out to all connected clients (including Max).

Host these files somewhere that supports full stack apps (not just static sites) and allows for websockets (we'll use a free option = Glitch.com).

  1. start a new blank Glitch project = https://glitch.new/blank
  2. delete all the default files (delete README.md, index.html, script.js, and style.css)
  3. drag into the Glitch project all the files from the web-server folder (web-server.js, package.json, and package-lock.json)
  4. Glitch will automatically install the correct packages for Socket.io as specified in package.json
  5. note the title of the Glitch project
  6. you are done with creating the web server!

 

web-client Installation

YouTube Setup web-client

The web client enables users to send messages from the browser (from any device) to the web server.

Host these files on space you rent on a web server that allows for running static websites (we'll use a free option = W3Schools Spaces, but other places you could host these files include Hostinger, Bluehost, SiteGround, etc.).

  1. create a "Basic" blank space = https://spaces.w3schools.com/createspace
  2. delete all the default files in the W3Schools Space (index.html, README.md, script.js, and style.css)
  3. upload (click "upload to root") all the files in the web-client folder (cycling74.png, index.html, and web-client.js)
  4. edit the web-client.js file with the URL of your server running on Glitch.com
    const serverURL = "wss://YOUR-GLITCH-PROJECT-NAME.glitch.me"; 
  5. note the URL of the space by clicking on the "share" button in the top right of the preview view
  6. you are done with the web client! ... move on installing the

 

max-client Installation

YouTube Setup max-client

Max acts as just another client (just like the web client) able to send and receive messages to/from the web server.

Keep these files on the computer running Max by Cycling '74.

  1. Open the max-client.maxpat file in Max.
  2. double click on the [node.script] object so you can edit the web-client.js file with the URL of your server running on Glitch.com
    const serverURL = "wss://YOUR-GLITCH-PROJECT-NAME.glitch.me"; 
  3. click on the script npm install message within the Max patch to install the socket.io-client library dependencies found in the package.json file (this will create a node_modules folder) ... the next time you open this max patch, you do not need to click the script npm install message.
  4. click on the script start message to run the JavaScript file held by [node.script]

👏👏👏

Now you are ready navigate to the domain where you installed the web-client and send data to Max and get data from Max!

 

JavaScript Objects

I advice you to use js objects within your JavaScript files for the following reasons =

  • within Max: the max-api converts dictionaries sent into [node.script] into js objects
  • Socket.io converts js objects behind the scenes to JSON when they are sent, then converts them back to js objects when received
  • within Max: the max-api converts js objects into dictionaries when sending js objects out [node.script]

 

References

I could not have figured this out without nuggets from the following sources.

 

LICENSE

MIT

Bug reports

Please report bugs on the GitHub issues tracker.

websockets-in-max's People

Contributors

benjohansen avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 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.