LoginSignup
9
10

More than 5 years have passed since last update.

Milkcocoaの送信テスト用JSサンプル

Posted at

https://mlkcca.com/ の接続テスト用アプリでよく作るやつのメモ。
es6な感じです。

app.js
'use strict'

import MilkCocoa from 'milkcocoa';
const milkcocoa = new MilkCocoa("your-app-id.mlkcca.com");
const ds = milkcocoa.dataStore('message');

setInterval(()=>{
  ds.send({v:1}, (err, sended) => {
    console.log('送信:', sended);
  });
},2000);

ds.on('send', (sended) => {
  console.log('受信:',sended);
});

実行すると2秒ごとに送受信が行われます。

$ babel-node app.js
送信: { id: undefined, value: { v: 1 }, timestamp: undefined }
受信: { path: 'message', value: { v: 1 } }
送信: { id: undefined, value: { v: 1 }, timestamp: undefined }
受信: { path: 'message', value: { v: 1 } }
送信: { id: undefined, value: { v: 1 }, timestamp: undefined }
受信: { path: 'message', value: { v: 1 } }
9
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
10