@wireapp/api-client
Advanced tools
Comparing version 0.0.19 to 0.0.21
@@ -62,3 +62,3 @@ "use strict"; | ||
}; | ||
WireAPIClient.prototype.listen = function (clientId) { | ||
WireAPIClient.prototype.connect = function (clientId) { | ||
var _this = this; | ||
@@ -71,5 +71,7 @@ return this.client.ws.connect(clientId) | ||
}; | ||
return socket; | ||
}); | ||
}; | ||
WireAPIClient.prototype.disconnect = function () { | ||
this.client.ws.disconnect(); | ||
}; | ||
return WireAPIClient; | ||
@@ -76,0 +78,0 @@ }(EventEmitter)); |
@@ -9,2 +9,3 @@ "use strict"; | ||
WebSocketClient.prototype.connect = function (clientId) { | ||
var _this = this; | ||
var url = this.baseURL + "/await?access_token=" + this.accessToken | ||
@@ -15,12 +16,21 @@ .access_token; | ||
} | ||
var socket = new WebSocket(url); | ||
socket.binaryType = 'arraybuffer'; | ||
this.socket = new WebSocket(url); | ||
this.socket.binaryType = 'arraybuffer'; | ||
return new Promise(function (resolve) { | ||
socket.onopen = function () { | ||
resolve(socket); | ||
_this.socket.onopen = function () { | ||
resolve(_this.socket); | ||
}; | ||
}); | ||
}; | ||
WebSocketClient.prototype.disconnect = function () { | ||
if (this.socket) { | ||
this.socket.close(); | ||
this.socket = undefined; | ||
} | ||
else { | ||
throw new Error('Attempt for closing non-existent WebSocket.'); | ||
} | ||
}; | ||
return WebSocketClient; | ||
}()); | ||
exports.default = WebSocketClient; |
@@ -27,2 +27,7 @@ import WireAPIClient from "./commonjs"; | ||
const client = new WireAPIClient(urls); | ||
client.on(WireAPIClient.TOPIC.WEB_SOCKET_MESSAGE, function(notification) { | ||
console.log('Received notification via WebSocket', notification); | ||
}); | ||
client.login(login) | ||
@@ -33,2 +38,3 @@ .then((result) => { | ||
submitButton.firstChild.data = "😊"; | ||
return client.connect(); | ||
}) | ||
@@ -35,0 +41,0 @@ .catch((error) => { |
@@ -26,2 +26,3 @@ const argv = require('optimist') | ||
const client = new WireAPIClient(urls); | ||
client.on(WireAPIClient.TOPIC.WEB_SOCKET_MESSAGE, function(notification) { | ||
@@ -28,0 +29,0 @@ console.log('Received notification via WebSocket', notification); |
{ | ||
"author": "Wire", | ||
"browser": { | ||
"ws": "./ws-fallback.js" | ||
"ws": "./browser/ws-fallback.js" | ||
}, | ||
@@ -53,3 +53,3 @@ "dependencies": { | ||
}, | ||
"version": "0.0.19" | ||
"version": "0.0.21" | ||
} |
@@ -52,1 +52,6 @@ ----- | ||
``` | ||
```bash | ||
npm run dist | ||
node dist/index.js --e="name@email.com" --p="password" | ||
``` |
@@ -61,6 +61,5 @@ import * as WebSocket from 'ws'; | ||
public listen(clientId: string): Promise<WebSocket> { | ||
public connect(clientId: string): Promise<void> { | ||
return this.client.ws.connect(clientId) | ||
.then((socket: WebSocket) => { | ||
socket.onmessage = (event: { data: any; type: string; target: WebSocket }) => { | ||
@@ -70,6 +69,8 @@ const notification = JSON.parse(Buffer.from(event.data).toString('utf8')); | ||
}; | ||
return socket; | ||
}); | ||
} | ||
public disconnect(): void { | ||
this.client.ws.disconnect(); | ||
} | ||
} |
@@ -5,2 +5,3 @@ import * as WebSocket from 'ws'; | ||
public accessToken: AccessTokenData; | ||
private socket: WebSocket; | ||
@@ -16,11 +17,20 @@ constructor(public baseURL: string) {} | ||
const socket = new WebSocket(url); | ||
socket.binaryType = 'arraybuffer'; | ||
this.socket = new WebSocket(url); | ||
this.socket.binaryType = 'arraybuffer'; | ||
return new Promise((resolve) => { | ||
socket.onopen = () => { | ||
resolve(socket); | ||
this.socket.onopen = () => { | ||
resolve(this.socket); | ||
}; | ||
}); | ||
} | ||
public disconnect() { | ||
if (this.socket) { | ||
this.socket.close(); | ||
this.socket = undefined; | ||
} else { | ||
throw new Error('Attempt for closing non-existent WebSocket.'); | ||
} | ||
} | ||
} |
@@ -5,2 +5,3 @@ { | ||
"lib": [ | ||
"DOM", | ||
"ES6" | ||
@@ -20,3 +21,2 @@ ], | ||
"exclude": [ | ||
"bower_components", | ||
"dist/commonjs", | ||
@@ -23,0 +23,0 @@ "node_modules" |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
2
57
76174
55
985
1