{"id":19793547,"url":"https://github.com/darky/backbone.wamp","last_synced_at":"2025-12-12T04:05:11.598Z","repository":{"id":26348048,"uuid":"29796943","full_name":"darky/backbone.wamp","owner":"darky","description":"WAMP protocol for Backbone Models and Collections (WebSocket)","archived":false,"fork":false,"pushed_at":"2015-08-06T18:57:56.000Z","size":785,"stargazers_count":20,"open_issues_count":0,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-25T21:52:18.352Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/darky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-25T00:19:04.000Z","updated_at":"2024-04-24T08:59:12.000Z","dependencies_parsed_at":"2022-08-17T20:40:36.816Z","dependency_job_id":null,"html_url":"https://github.com/darky/backbone.wamp","commit_stats":null,"previous_names":["darrrk/backbone.wamp"],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darky%2Fbackbone.wamp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darky%2Fbackbone.wamp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darky%2Fbackbone.wamp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darky%2Fbackbone.wamp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darky","download_url":"https://codeload.github.com/darky/backbone.wamp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251812261,"owners_count":21647875,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T07:10:18.659Z","updated_at":"2025-12-12T04:05:06.315Z","avatar_url":"https://github.com/darky.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Backbone.WAMP\n\n[![](https://travis-ci.org/darrrk/backbone.wamp.svg?branch=master)](https://travis-ci.org/darrrk/backbone.wamp)\n\nBackbone.WAMP replace your classic **REST** protocol, based on **AJAX**, to modern **WAMP** protocol, based on **WebSockets**.\nYou can read more about \u003ca href=http://wamp.ws target=_blank\u003ehere\u003c/a\u003e.\n\n## Dependencies\n\n*Backbone*\u003cbr\u003e\n*AutobahnJS*\u003cbr\u003e\n\n## Overview example\n\n```javascript\n/************\n   browser\n************/\n\nwindow.WAMP_OTHER_ID = \"nodejs\";\nwindow.WAMP_CONNECTION = new autobahn.Connection({\n  url: \"ws://127.0.0.1:9000/ws\",\n  realm: \"realm1\"\n});\n\nWAMP_CONNECTION.onopen = function () {\n  var Collection = WampCollection.extend({\n    url: \"test_collection\"\n  });\n  var collection = new Collection();\n  collection.fetch(); // call wampRead below\n  collection.create({ // call wampCreate below\n    age: 36,\n    name: \"John\"\n  }, {\n    success: function () {\n      collection.first().destroy(); // call wampDelete below\n    }\n  });\n};\n\nWAMP_CONNECTION.open();\n\n\n\n/**********\n   nodejs\n**********/\n\nglobal.WAMP_MY_ID = \"nodejs\";\nglobal.WAMP_CONNECTION = new autobahn.Connection({\n  url: \"ws://127.0.0.1:9000/ws\",\n  realm: \"realm1\"\n});\n\nWAMP_CONNECTION.onopen = function () {\n  var Collection = WampCollection.extend({\n    url: \"test_collection\",\n    wampRead: function () {\n      // called via fetch\n      // need return data or promise\n    },\n    wampCreate: function (sendOptions) {\n      sendOptions.data.age === 36; // true\n      sendOptions.data.name === \"John\"; // true\n      // need return data or promise\n    },\n    wampDelete: function (sendOptions) {\n      // sendOptions.extra.wampModelId contain id of model\n      // need return data or promise\n    }\n  });\n\n  collection = new Collection();\n};\n\nWAMP_CONNECTION.open();\n```\n\n## API\n\n#### wampConnection / WAMP_CONNECTION\n\nBefore create instances of `WampModel` / `WampCollection`,\nyou need eastablish autobahn connection and link it to global `WAMP_CONNECTION` or\nspecific `wampConnection` for `WampModel` / `WampCollection`.\n\n```javascript\nwindow.WAMP_CONNECTION = new autobahn.Connection({\n  url: \"ws://127.0.0.1:9000/ws\",\n  realm: \"realm1\"\n});\n\nvar wampConnection = new autobahn.Connection({\n  url: \"ws://127.0.0.1:9000/ws\",\n  realm: \"realm2\"\n});\n\nWAMP_CONNECTION.onopen = function () {\n  var Collection = WampCollection.extend({\n    url: \"test_collection\"\n  });\n  var collection = new Collection(); // this collection used WAMP_CONNECTION\n};\n\nwampConnection.onopen = function () {\n  var Collection = WampCollection.extend({\n    url: \"test_collection2\"\n    wampConnection: wampConnection\n  });\n  var collection = new Collection(); // this collection used wampConnection\n}\n\nWAMP_CONNECTION.open();\nwampConnection.open();\n```\n\n#### wampMyId / WAMP_MY_ID\n\nThis unique peer-id of current environment,\nwith which you want interact from other environments.\n\n```javascript\nglobal.WAMP_MY_ID = \"nodejs\";\nglobal.WAMP_CONNECTION = new autobahn.Connection({\n  url: \"ws://127.0.0.1:9000/ws\",\n  realm: \"realm1\"\n});\n\nWAMP_CONNECTION.onopen = function () {\n  var Collection = WampCollection.extend({\n    url: \"test_collection\",\n  });\n\n  var Model = WampModel.extend({\n    urlRoot: \"test_model\"\n    wampMyId: \"nodejs2\"\n  });\n\n  var collection = new Collection(); // this available on \"nodejs\"\n  var model = new Model(); // this available on \"nodejs2\"\n};\n\nWAMP_CONNECTION.open();\n```\n\n#### wampOtherId / WAMP_OTHER_ID\n\nThis means peer-id of environment, with which you want interact from current environment.\n\n```javascript\nwindow.WAMP_OTHER_ID = \"nodejs\";\nwindow.WAMP_CONNECTION = new autobahn.Connection({\n  url: \"ws://127.0.0.1:9000/ws\",\n  realm: \"realm1\"\n});\n\nWAMP_CONNECTION.onopen = function () {\n  var Collection = WampCollection.extend({\n    url: \"test_collection\",\n  });\n\n  var Model = WampModel.extend({\n    urlRoot: \"test_model\"\n    wampOtherId: \"nodejs2\"\n  });\n\n  var collection = new Collection(); // this will interact with \"nodejs\"\n  var model = new Model(); // this will interact with \"nodejs2\"\n};\n\nWAMP_CONNECTION.open();\n```\n\n#### constructor\n\nWhen you create instances of `WampModel` / `WampCollection`, this automatically\nregister listeners, using `wampMyId` / `WAMP_MY_ID` and `urlRoot` / `url`, if it present.\u003cbr\u003e\nFor ignoring this, need pass to `constructor` - `wampNoAttach` option.\u003cbr\u003e\nFor catching each registering need pass to `constructor` - `wampRegister` callback-option.\n\n```javascript\nwindow.WAMP_CONNECTION = new autobahn.Connection({\n  url: \"ws://127.0.0.1:9000/ws\",\n  realm: \"realm1\"\n});\n\nWAMP_CONNECTION.onopen = function () {\n  var Collection = WampCollection.extend({\n    url: \"test_collection\",\n  });\n\n  var Model = WampModel.extend({\n    wampMyId: \"browser\"\n  });\n\n  var Model2 = WampModel.extend({\n    urlRoot: \"model2\",\n    wampMyId: \"browser\"\n  })\n\n  var collection = new Collection(); // no register listeners, wampMyId / WAMP_MY_ID ommited\n  var model = new Model(); // no register listeners, urlRoot ommited\n  var model2 = new Model2({}, {wampNoAttach: true}); // no register listeners, pass specific option\n  model2 = new Model2({}, {wampRegister: function (errOrReg) { // register listeners\n    // calling for registering each action: create | read | update | delete | patch\n  }})\n};\n\nWAMP_CONNECTION.open();\n```\n\n#### wampCreate, wampRead, wampUpdate, wampDelete, wampPatch\n\nThis hooks automatically registers, when create instances of `WampModel` / `WampCollection`,\nif exists `wampMyId` / `WAMP_MY_ID` and `urlRoot` / `url` and not pass `wampNoAttach` option.\n\n###### Received param: `sendOptions`\n\n`sendOptions.data` contains JSON-parsed model for *create*, *update*, *patch* actions.\nOr GET-params for *read* action of model/collection.\u003cbr\u003e\n`sendOptions.extra` contain any extra information, which you can send in `options.wampExtra`\u003cbr\u003e\nBuilt-in options in `sendOptions.extra`:\n\n* `wampModelId` of specific model, if needed\n* `wampMyId` of another environment\n\n###### Return\n\nNeed return data or promise, that resolved to data.\u003cbr\u003e\nFor error need return `new autobahn.Error(...)` or promise, that resolve `new autobahn.Error(...)`\u003cbr\u003e\nFor example, see **Overview example** above.\n\n#### wampGetUri / WAMP_GET_URI\n\nBy default, via methods `save`, `fetch`, e.t.c. generated WebSocket messages as is `peerId.uri.action`\u003cbr\u003e\nExample: \"nodejs.test_collection.create\"\u003cbr\u003e\nYou can overwrite template if needed via `wampGetUri` / `WAMP_GET_URI`, that \n\n###### Received params: peerId, uri, action\n\n###### Return: string of WebSocket message\n\n#### wampAuth / WAMP_AUTH\n\nWhen defined, will be called before **wampCreate, wampRead, wampUpdate, wampDelete, wampPatch**.\u003cbr\u003e\nIf it's return non true value or promise, that resolved to non true,\n**wampCreate, wampRead, wampUpdate, wampDelete, wampPatch** not be called.\n\n###### Received params: uriOptions, sendOptions\n\n`uriOptions` contain peerId, uri, action\n\nmore about `sendOptions`in **wampCreate, wampRead, ...** partition\n\n###### Return: true or promise, that resolved to true (if auth passed)\n\n```javascript\nglobal.WAMP_MY_ID = \"nodejs\";\nglobal.WAMP_CONNECTION = new autobahn.Connection({\n  url: \"ws://127.0.0.1:9000/ws\",\n  realm: \"realm1\"\n});\n\nWAMP_CONNECTION.onopen = function () {\n  var Collection = WampCollection.extend({\n    url: \"test_collection\",\n    wampAuth: function (uriOptions, sendOptions) {\n      // it pseudo code with concept\n      return new Promise(function (resolve) {\n        db.find({peer: sendOptions.extra.wampMyId}).then(function (finded) {\n          resolve(finded) // if finded === true, auth passed\n        })\n      });\n    },\n    wampRead: function () {\n      // this called, if wampAuth return promise, that resolved to true\n    }\n  });\n\n  var collection = new Collection();\n};\n\nWAMP_CONNECTION.open();\n```\n\n##### Session\n\nThis can be useful for `wampAuth`.\u003cbr\u003e\nFor session mechanism need dynamically generate `wampMyId`.\u003cbr\u003e\nExample: `browser_0dbee552-46e0-4c7c-aa4e-e1341dc00b18`\u003cbr\u003e\nUse any UUID, GUID, e.t.c. generator, maybe [node-uuid](https://github.com/broofa/node-uuid)\n\n\n#### wampUnregister\n\nCall this method directly on instances of `WampModel` / `WampCollection` for unregistering\n**wampCreate, wampRead, ...** methods.\n\n###### Received params: actions, callback\n\n`actions` it array, for example `[\"read\", \"delete\"]`\u003cbr\u003e\nIf omitted, will unregister all actions\n\n`callback` called per each unregistering action\n\n```javascript\nglobal.WAMP_MY_ID = \"nodejs\";\nglobal.WAMP_CONNECTION = new autobahn.Connection({\n  url: \"ws://127.0.0.1:9000/ws\",\n  realm: \"realm1\"\n});\n\nWAMP_CONNECTION.onopen = function () {\n  var Collection = WampCollection.extend({\n    url: \"test_collection\"\n  });\n\n  var collection = new Collection();\n  collection.wampUnregister(null, function (err, uri) {\n    // called per each unregistering action\n  });\n};\n\nWAMP_CONNECTION.open();\n```\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2015 Vladislav Botvin \u0026lt;darkvlados@gmail.com\u0026gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\n### License of AutobahnJS\n\nCopyright (c) 2011-2014 Tavendo GmbH.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarky%2Fbackbone.wamp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarky%2Fbackbone.wamp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarky%2Fbackbone.wamp/lists"}