Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xiaodaigh/promisewebsocket
A simple extension of the Websocket object by making the .send method into a Promise
https://github.com/xiaodaigh/promisewebsocket
javascript promise websocket
Last synced: about 1 month ago
JSON representation
A simple extension of the Websocket object by making the .send method into a Promise
- Host: GitHub
- URL: https://github.com/xiaodaigh/promisewebsocket
- Owner: xiaodaigh
- Created: 2017-08-15T22:35:55.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-15T22:48:53.000Z (over 7 years ago)
- Last Synced: 2024-05-01T22:41:58.587Z (7 months ago)
- Topics: javascript, promise, websocket
- Language: JavaScript
- Size: 1000 Bytes
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PromiseWebsocket
A simple extension of the Websocket object by making the .send method into a Promise# Usage
```javascript
var pws = new PromiseWebsocket(url)
pws.onmessage = () => {
console.log('onmessage trigger');
return "something"
}pws.send(something)
.then((success_obj) => {
//this will execute when onmessage gets triggered
// success_obj.msg this is the message sent to onmessage
console.log(success_obj.msg)
// if you have set .onmessage method then it returns the onmessage's returned output
// otherwise it's null
console.log(success_obj.onmessage_return)
})
.catch({
//this will trigger if the .onerror method gets triggered
console.log("onerror was triggered")
})
```