@live-change/dao-message 0.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +50 -0
- package/package.json +44 -0
package/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const rd = require("@live-change/dao")
|
|
2
|
+
const Connection = rd.ReactiveConnection
|
|
3
|
+
const debug = require('debug')('dao:message')
|
|
4
|
+
|
|
5
|
+
class MessageConnection extends Connection {
|
|
6
|
+
|
|
7
|
+
constructor(credentials, url, settings) {
|
|
8
|
+
super(credentials, settings)
|
|
9
|
+
this.url = url
|
|
10
|
+
this.target = settings.target
|
|
11
|
+
this.initialize()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
initialize() {
|
|
15
|
+
this.target.onmessage = event => {
|
|
16
|
+
debug("MSG IN:", data)
|
|
17
|
+
this.handleMessage(event.data)
|
|
18
|
+
}
|
|
19
|
+
this.target.onerror = event => {
|
|
20
|
+
console.error("Worker", this.url, "error", event)
|
|
21
|
+
}
|
|
22
|
+
this.target.onmessageerror = event => {
|
|
23
|
+
console.error("Worker", this.url, "message error", event)
|
|
24
|
+
}
|
|
25
|
+
this.target.onunhandledrejection = event => {
|
|
26
|
+
console.error("Worker", this.url, "unhandled rejection", event)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
send(message) {
|
|
31
|
+
debug("MSG OUT:", data)
|
|
32
|
+
this.target.postMessage(message)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
reconnect() {
|
|
36
|
+
// impossible to reconnect web worker or other message channel
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
dispose() {
|
|
40
|
+
if(this.target.terminate) this.target.terminate()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
closeConnection() {
|
|
44
|
+
// impossible to disconnect running web worker
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = MessageConnection
|
|
50
|
+
module.exports.MessageConnection = MessageConnection
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@live-change/dao-message",
|
|
3
|
+
"version": "0.5.10",
|
|
4
|
+
"author": {
|
|
5
|
+
"email": "m8@em8.pl",
|
|
6
|
+
"name": "Michał Łaszczewski",
|
|
7
|
+
"url": "http://www.viamage.com/"
|
|
8
|
+
},
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/live-change/live-change-dao/issues"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@live-change/dao": "0.5.10",
|
|
14
|
+
"debug": "^4.3.4",
|
|
15
|
+
"supports-color": "^7.2.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"babel-loader": "^6.2.5",
|
|
19
|
+
"babel-plugin-transform-react-jsx": "*",
|
|
20
|
+
"babel-preset-es2015": "*",
|
|
21
|
+
"better-assert": "github:devinrhode2/better-assert-browser",
|
|
22
|
+
"mocha": "^9.0.0"
|
|
23
|
+
},
|
|
24
|
+
"description": "live-change dao sockjs transport",
|
|
25
|
+
"directories": {},
|
|
26
|
+
"homepage": "https://github.com/live-change/live-change-dao",
|
|
27
|
+
"license": "BSD-3-Clause",
|
|
28
|
+
"main": "index.js",
|
|
29
|
+
"module": "index.js",
|
|
30
|
+
"maintainers": [
|
|
31
|
+
{
|
|
32
|
+
"email": "michal@laszczewski.com",
|
|
33
|
+
"name": "Michał Łaszczewski"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"readme": "README.md",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": ""
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"compileTests": "webpack test/*.js tests-bundle.js"
|
|
43
|
+
}
|
|
44
|
+
}
|