{"__v":7,"_id":"55bb4704a8400c2d00873ded","category":{"__v":2,"_id":"5681681330018c0d006bf7ff","pages":["5683c92f4aecbd0d00a465c2","5683e9ed72bb720d0091f64e"],"project":"559a61d2dbcfd20d00710b39","version":"559a61d2dbcfd20d00710b3c","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-12-28T16:49:23.982Z","from_sync":false,"order":13,"slug":"cordova-api-reference","title":"Cordova / PhoneGap SDK Reference"},"parentDoc":null,"project":"559a61d2dbcfd20d00710b39","user":"559a618bdbcfd20d00710b38","version":{"__v":23,"_id":"559a61d2dbcfd20d00710b3c","project":"559a61d2dbcfd20d00710b39","createdAt":"2015-07-06T11:09:06.510Z","releaseDate":"2015-07-06T11:09:06.510Z","categories":["559a61d3dbcfd20d00710b3d","55a589ddaaf9cf1900114dd0","55a589e30f354f0d00fd0312","55a589ea80c8a30d00b323cc","55a589f6aaf9cf1900114dd1","55a58d4e80c8a30d00b323e6","55a8e7a227a17d21005251a2","55a93098cf45e1390093f351","55afb085f202b12100cd9e83","55afb22e902fd51700f5f8bf","55afb260902fd51700f5f8c2","55afb28ec8a85321007a5462","55afb294f202b12100cd9e95","55afb29b902fd51700f5f8c5","55afb2a1c8a85321007a5463","55afb2a7902fd51700f5f8c7","55afb2ad902fd51700f5f8c8","55afb2b5902fd51700f5f8ca","55b74b2131bccb190081bedc","55bb441b54f9640d006e6cf2","565711085cb2420d00d70071","5681681330018c0d006bf7ff","588f38b5923d610f00c72dad"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"Version 1.0","version_clean":"1.0.0","version":"1"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-07-31T09:59:32.294Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"##Returning objects\n\nEach method can return a `beacon`, a `zone` or a `place`.\n\n####`beacon` object\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n\\t\\\"type\\\": \\\"beacon\\\",\\n\\t\\\"id\\\":\\\"xxx\\\",\\n\\t\\\"uuid\\\":\\\"xxxxxxxxxxxx-xxxx-xxxx-xxxx\\\",\\n\\t\\\"major\\\": xxxxx,\\n  \\\"minor\\\": xxxxx,\\n\\t\\\"name\\\":\\\"beacon_name\\\",\\n  \\\"proximity\\\":\\\"immediate\\\" | \\\"near\\\" | \\\"far\\\" | \\\"unknown\\\",\\n  \\\"timestamp\\\": xxxxxxxx\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n####`zone` object\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n\\t\\\"type\\\":\\\"place\\\",\\n  \\\"id\\\":\\\"xxxx\\\",\\n  \\\"name\\\":\\\"xxxxx\\\",\\n\\t\\\"timestamp\\\": xxxxxxx,\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n####`place` object\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n\\t\\\"type\\\": \\\"place\\\",\\n\\t\\\"id\\\":\\\"xxx\\\",\\n \\t\\\"name\\\":\\\"place_name\\\",\\n\\t\\\"uuid\\\":\\\"xxxxxxxxxxxx-xxxx-xxxx-xxxx\\\",\\n\\tgeofence: {\\n  \\t\\\"lat\\\": xx.xxxxx,\\n\\t\\t\\\"long\\\": xx.xxxx,\\n    \\\"accuracy\\\":xx,\\n  }\\n  \\\"timestamp\\\": xxxxxxxx\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Handle MOCA data ready event\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"  MOCA.addDataReadyListener (function (e) {\\n     // e.detail.beacons -- array of beacon objects. \\n  }); \\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nThis method invoked when a proximity service loaded or updated a registry of beacons from MOCA cloud or from local cache.\n\n###Handle enter beacon range event:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"  MOCA.addEnterBeaconListener (function (e) {\\n     // e.detail -> beacon object\\n  }); \\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Handle exit beacon range event:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"  MOCA.addExitBeaconListener (function (e) {\\n     // e.detail -> beacon object\\n  }); \\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Method triggered when the state of a beacon proximity did changed:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"  MOCA.addBeaconProximityChangeListener (function (e) {\\n     // e.detail  proximity change details (previous proximity\\n    // current proximity, beacon object)\\n  }); \\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Handle enter place event:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"  MOCA.addEnterPlaceListener (function (e) {\\n     // e.detail -> Place object\\n  }); \",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Handle exit place event:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"  MOCA.addExitPlaceListener (function (e) {\\n     // e.detail -> Place object\\n  }); \",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Handle enter zone event:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"  MOCA.addEnterZoneListener (function (e) {\\n     // e.detail -> Zone object\\n  }); \",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Handle exit zone event:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"  MOCA.addExitZoneListener (function (e) {\\n     // e.detail -> Zone object\\n  }); \\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"javascript-api-usage-1","type":"basic","title":"JavaScript Trigger Events"}

JavaScript Trigger Events


##Returning objects Each method can return a `beacon`, a `zone` or a `place`. ####`beacon` object [block:code] { "codes": [ { "code": "{\n\t\"type\": \"beacon\",\n\t\"id\":\"xxx\",\n\t\"uuid\":\"xxxxxxxxxxxx-xxxx-xxxx-xxxx\",\n\t\"major\": xxxxx,\n \"minor\": xxxxx,\n\t\"name\":\"beacon_name\",\n \"proximity\":\"immediate\" | \"near\" | \"far\" | \"unknown\",\n \"timestamp\": xxxxxxxx\n}", "language": "javascript" } ] } [/block] ####`zone` object [block:code] { "codes": [ { "code": "{\n\t\"type\":\"place\",\n \"id\":\"xxxx\",\n \"name\":\"xxxxx\",\n\t\"timestamp\": xxxxxxx,\n}", "language": "javascript" } ] } [/block] ####`place` object [block:code] { "codes": [ { "code": "{\n\t\"type\": \"place\",\n\t\"id\":\"xxx\",\n \t\"name\":\"place_name\",\n\t\"uuid\":\"xxxxxxxxxxxx-xxxx-xxxx-xxxx\",\n\tgeofence: {\n \t\"lat\": xx.xxxxx,\n\t\t\"long\": xx.xxxx,\n \"accuracy\":xx,\n }\n \"timestamp\": xxxxxxxx\n}", "language": "javascript" } ] } [/block] ###Handle MOCA data ready event [block:code] { "codes": [ { "code": " MOCA.addDataReadyListener (function (e) {\n // e.detail.beacons -- array of beacon objects. \n }); \n", "language": "javascript" } ] } [/block] This method invoked when a proximity service loaded or updated a registry of beacons from MOCA cloud or from local cache. ###Handle enter beacon range event: [block:code] { "codes": [ { "code": " MOCA.addEnterBeaconListener (function (e) {\n // e.detail -> beacon object\n }); \n", "language": "javascript" } ] } [/block] ###Handle exit beacon range event: [block:code] { "codes": [ { "code": " MOCA.addExitBeaconListener (function (e) {\n // e.detail -> beacon object\n }); \n", "language": "javascript" } ] } [/block] ###Method triggered when the state of a beacon proximity did changed: [block:code] { "codes": [ { "code": " MOCA.addBeaconProximityChangeListener (function (e) {\n // e.detail proximity change details (previous proximity\n // current proximity, beacon object)\n }); \n", "language": "javascript" } ] } [/block] ###Handle enter place event: [block:code] { "codes": [ { "code": " MOCA.addEnterPlaceListener (function (e) {\n // e.detail -> Place object\n }); ", "language": "javascript" } ] } [/block] ###Handle exit place event: [block:code] { "codes": [ { "code": " MOCA.addExitPlaceListener (function (e) {\n // e.detail -> Place object\n }); ", "language": "javascript" } ] } [/block] ###Handle enter zone event: [block:code] { "codes": [ { "code": " MOCA.addEnterZoneListener (function (e) {\n // e.detail -> Zone object\n }); ", "language": "javascript" } ] } [/block] ###Handle exit zone event: [block:code] { "codes": [ { "code": " MOCA.addExitZoneListener (function (e) {\n // e.detail -> Zone object\n }); \n", "language": "javascript" } ] } [/block]