maze
  • Introduction
  • Getting Started
    • Quick Start
  • Guides
    • Overview
    • Installation
    • Create New App
    • Directory Structure
    • Configuration
    • Docker
    • Controllers
      • Sessions
      • Request & Response Objects
      • Halt!
      • Respond With
      • Params Validation
      • Cookies
      • Filters
      • Flash
      • Redirection
    • Views
      • View Helpers
    • Models
      • Granite
        • Granite's README
        • Migrations
        • Validations
        • Callbacks
        • Associations
        • Querying
        • Bulk Insertions
      • Crecto
        • Crecto's README
      • Jennifer
        • Jennifer Docs
        • Migrations
        • Models
    • Routing
      • Pipelines
      • Routes
    • Websockets
      • Channels
      • Sockets
      • JavaScript Client
    • Mailers
      • Deliver a new Email
  • Testing
    • System Tests
  • Deployment
    • Digital Ocean
    • Heroku
  • CLI
    • New
    • Recipes
    • Generate
    • Database
    • Watch
    • Routes
    • Exec
    • Encrypt
    • Deploy
  • Examples
    • Maze Auth
    • Crystal Debug
    • Minimal Configuration
  • Troubleshooting
  • Contributing
  • Code of Conduct
  • HAVE A QUESTION?
    • Ask on Gitter
    • Ask on StackOverflow
    • Follow on Twitter
    • Submit an issue
Powered by GitBook
On this page
  • Example Usage
  • Create a single connection to the server
  • Join a channel
  • Subscribe to events / messages
  • Send events / messages
  1. Guides
  2. Websockets

JavaScript Client

Example Usage

For use with web based applications, a JavaScript library (maze.js) is included.

Create a single connection to the server

let socket = new Maze.Socket('/chat')
socket.connect() # returns a promise
  .then(() => {})

Join a channel

let channel = socket.channel('chat_room:123')
channel.join()

Subscribe to events / messages

channel.on('message_new', (message) => {
  // handle new message here
})

channel.on('user_join', (message) => {})

Send events / messages

channel.push('message_new', { message: 'maze websockets is the bomb diggity!' })
PreviousSocketsNextMailers

Last updated 6 years ago