How to write your own chat dizmo with

This post is a response to the following question that we have been asked in one form or another:

How can a dizmo reach out to connect with 3rd party systems? Or, is there a way that a dizmo can communicate with a server?

The short answer is: Dizmo uses Webkit as its basis to render dizmos. This means it is possible to use Ajax to connect to other systems like you would do in any browser. Webkit is also able to setup Websocket based calls if a more elaborate two way communication is needed to access a service.

For those with a hands on approach or who want to go in depth, we have prepared a tutorial on how to write a chat dizmo with

Our chat dizmo tutorial is based on the one provided by

Server (node.js)

We assume that you have node.js and npm already installed!

First create a package.json manifest file that describes our the project. We recommend that you place it in an empty directory (we will call ours chat-io).

    "version": "0.0.1",
    "description": "my first app",
    "dependencies": {}

In order to easily populate the dependencies with the required objects, we’ll use npm install --save:

$ npm install --save express@4.17.1

Now that express is installed we can create an ‘index.js’ file that will setup our application.

var app = require('express')();
var http = require('http').Server(app);
http.listen(3000, function(){
    console.log('listening on *:3000');

This translates into the following: Express initializes app to be a function handler that you can supply to an HTTP server (as seen in line 2). We make the http server listen on port 3000. Open a new Terminal window and run:

node index.js.

This starts up the node server. You should see the following:

Integrating Socket.IO

$ npm install --save

The command above installs the module and adds the dependency to package.json. This installation process might take a while.

Let’s continue by changing index.js to the following code:

var app = require('express')();
var http = require('http').Server(app);

var io = require('')(http);
io.on('connection', function(socket){
    console.log('a user connected');
    socket.on('disconnect', function(){
        console.log('user disconnected');

http.listen(3000, function(){
    console.log('listening on *:3000');

Notice that we initialize a new instance of by passing the http (the HTTP server) object. Then we listen on the connection event for incoming sockets, and log it to the console. Each socket also fires a special disconnect event.


We create our index.html file and add the and jquery libraries as well as the styles to the head section.

<!DOCTYPE html>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
            <script src=""></script>
            <script src=""></script>
            <script src="application.js"></script>
                * { margin: 0; padding: 0; box-sizing: border-box; }
                body { font: 13px Helvetica, Arial; }
                form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
                form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
                form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
                #messages { list-style-type: none; margin: 0; padding: 0; }
                #messages li { padding: 5px 10px; }
                #messages li:nth-child(odd) { background: #eee; }
        <div id="front">
            <ul id="messages"></ul>
            <form action="">
                <input id="m" autocomplete="off" /><button>Send</button>

        <div id="back">

Our application.js will initialize

function showFront() {

function showBack() {

dizmo.onShowBack(function() {
    // You can add your own code here that will be executed when the back side is shown.

dizmo.onShowFront(function() {
    // You can add your own code here that will be executed when the front side is shown.

document.addEventListener('dizmoready', function() {
    var socket = io('http://localhost:3000');

As our server is running on localhost on port 3000, we need to specify that here.

Lastly, create Info.plist and paste the following content into it:

<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

Now, open the dizmo and you’ll see in the server console that a user has connected.

When you reload the dizmo from the dizmo menu (make sure development mode is enabled) you’ll see the user disconnecting and reconnecting. Also try to open an additional instance of the chat dizmo, and check in the server console that two users are connecting!

Emitting events

The main idea behind Socket.IO is that you can send and receive any events you want, with any data you want. Any javascript objects that can be encoded as JSON will be, and binary data is supported too.

Let’s make it so that when the user types in a message, the server gets it as a chat message event. Add the following code to the function document.addEventListener application.js:

    socket.emit('chat message', $('#m').val());
    return false;


The next goal is for us to emit the event from the server to the rest of the users.

In order to send an event to everyone, Socket.IO gives us the io.emit:

io.emit('some event', { for: 'everyone' });

If you want to send a message to everyone except for a certain socket, we have the broadcast flag:


In this case, for the sake of simplicity we’ll send the message to everyone, including the sender. Add the following code to index.js:

socket.on('chat message', function(msg){
    io.emit('chat message', msg);

Every time we write a text and press the send button, a message is sent to the server, which in turns sends it back to all the connected clients, which will display it using the following code in application.js inside the ‘dizmoready’ eventListener:

socket.on('chat message', function(msg){
    $('#messages').append('<li>' + msg + '<li/>');

Now, you can chat between 2 (or more) dizmos! This completes our chat server and dizmo, in about 50 lines of code!


Here are some ideas to improve the application:

  • Broadcast a message to connected users when someone connects or disconnects
  • Add support for nicknames
  • Don’t send the same message to the user that sent it himself. Instead, append the message directly as soon as he presses enter
  • Add “{user} is typing” functionality
  • Show who’s online
  • Add private messaging
  • Share your improvements!
  • Tell us, what tutorial you want to read

Get the source code

You can find the source code on Github

$ git clone

2 thoughts on “How to write your own chat dizmo with”

  1. the server is connected and detect new users but emit() not working for me, i don’t receive any console.log in the cmd and $(‘#messages’).append($(”).text(msg)); not working too.

    i’am on Windows 7 32bits, is it a technical System error? or what?

Leave a Reply

Your email address will not be published. Required fields are marked *