Author Topic: Web socket  (Read 1638 times)

0 Members and 1 Guest are viewing this topic.

clout

  • Guest
Thanks @xeroc. Thats really helpful.

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
In order to subscribe, you need to:
1) login
2) get an instance id for "database"
3) before you can subscribe to any object change:

Maybe this helps for the "object id" stuff:
Code: [Select]
    def object_id(self, name, instance=0) :
        objects = {
            "NULL"                           :  "1.0.%d",
            "BASE"                           :  "1.1.%d",
            "ACCOUNT"                        :  "1.2.%d",
            "FORCE_SETTLEMENT"               :  "1.3.%d",
            "ASSET"                          :  "1.4.%d",
            "DELEGATE"                       :  "1.5.%d",
            "WITNESS"                        :  "1.6.%d",
            "LIMIT_ORDER"                    :  "1.7.%d",
            "CALL_ORDER"                     :  "1.8.%d",
            "CUSTOM"                         :  "1.9.%d",
            "PROPOSAL"                       :  "1.10.%d",
            "OPERATION_HISTORY"              :  "1.11.%d",
            "WITHDRAW_PERMISSION"            :  "1.12.%d",
            "VESTING_BALANCE"                :  "1.13.%d",
            "WORKER"                         :  "1.14.%d",
            "BALANCE"                        :  "1.15.%d",
            "GLOBAL_PROPERTY"                :  "2.0.%d",
            "DYNAMIC_GLOBAL_PROPERTY"        :  "2.1.%d",
            "INDEX_META"                     :  "2.2.%d",
            "ASSET_DYNAMIC_DATA"             :  "2.3.%d",
            "ASSET_BITASSET_DATA"            :  "2.4.%d",
            "DELEGATE_FEEDS"                 :  "2.5.%d",
            "ACCOUNT_BALANCE"                :  "2.6.%d",
            "ACCOUNT_STATISTICS"             :  "2.7.%d",
            "ACCOUNT_DEBT"                   :  "2.8.%d",
            "TRANSACTION"                    :  "2.9.%d",
            "BLOCK_SUMMARY"                  :  "2.10.%d",
            "ACCOUNT_TRANSACTION_HISTORY"    :  "2.11.%d",
            "WITNESS_SCHEDULE"               :  "2.12.%d",
        }
        return objects[name]%instance

IDs starting with "1." are blockchain state stuff .. and those with "2." indicated implementation/higher layer abstraction

clout

  • Guest
That documentation is really confusing. I can obviously execute the example given there, but I don't know how to extend the process to subscribing to different database api's. I don't even really understand the format of params.

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Nvm I had to stringify the message. I'm dumb.
:)

Take a look at these:
https://github.com/cryptonomex/graphene/wiki/websocket-rpc-howto
or a simple  (plain javascript) example:
http://tmp.xeroc.org/.ws/index.html

//edit: It seems during my latest "changes" there were some lines of code dropped ... Need to rewrite the "connection.onOpen" again .. .. fixed it
« Last Edit: August 01, 2015, 11:34:46 am by xeroc »

clout

  • Guest
Nvm I had to stringify the message. I'm dumb.

clout

  • Guest
Whats the format of sending and receiving messages with node.js. Why do I get this error:

Code: [Select]
3382681ms th_a       api.cpp:39                    database_api         ] creating database api 140234194959320
3382687ms th_a       websocket_api.cpp:115         on_message           ] e.to_detail_string(): 11 eof_exception: End Of File
stringstream
    {}
    th_a  sstream.cpp:109 peek

    {"str":""}
    th_a  json.cpp:478 from_string


 with the following code?:

Code: [Select]
var WebSocket = require('ws')
  , ws = new WebSocket('ws://127.0.0.1:8090')

ws.on('open', function () {
  var msg = {"id":1,
    "method":"call",
    "params":[0,"get_accounts",[["1.2.0"]]]
  }
  ws.send(msg)
})

ws.on('message', function(msg) {
  console.log(msg)
})