-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from zudov/new-api
New api
- Loading branch information
Showing
9 changed files
with
537 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
language: node_js | ||
sudo: false | ||
node_js: | ||
- 0.10 | ||
env: | ||
- PATH=$HOME/purescript:$PATH | ||
install: | ||
- TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p') | ||
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz | ||
- tar -xvf $HOME/purescript.tar.gz -C $HOME/ | ||
- chmod a+x $HOME/purescript | ||
- npm install bower pulp -g | ||
- bower install | ||
script: | ||
- pulp build && pulp docs | ||
- bower link | ||
- cd example/ && bower link purescript-websocket-simple && bower install && pulp build | ||
|
||
after_success: | ||
- >- | ||
test $TRAVIS_TAG && | ||
npm run psc-publish \ | ||
| tail -n 1 \ | ||
> output/documentation.json && | ||
curl -X POST http://pursuit.purescript.org/packages \ | ||
-d @output/documentation.json \ | ||
-H 'Accept: application/json' \ | ||
-H "Authorization: token ${GITHUB_TOKEN}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,13 @@ | ||
# Simple Bindings to Websocket API for Purescript | ||
|
||
## Example usage | ||
[![Documentation](http://pursuit.purescript.org/packages/purescript-websocket-simple/badge)](http://pursuit.purescript.org/packages/purescript-websocket-simple) | ||
[![Latest release](http://img.shields.io/bower/v/purescript-websocket-simple.svg)](https://github.com/zudov/purescript-websocket-simple/releases) | ||
[![Build Status](https://travis-ci.org/zudov/purescript-websocket-simple.svg?branch=master)](https://travis-ci.org/zudov/purescript-websocket-simple) | ||
|
||
```haskell | ||
module Main where | ||
## Example usage | ||
|
||
import Prelude | ||
import Control.Monad.Eff.Console | ||
import WebSocket | ||
See `example/src/Main.purs`. | ||
|
||
main = do | ||
ws <- mkWebSocket "ws://echo.websocket.org" | ||
onMessage ws log | ||
onOpen ws $ do | ||
send ws "hello" | ||
send ws "world" | ||
``` | ||
## Documentation | ||
|
||
[Docs are on Pursuit](http://pursuit.purescript.org/packages/purescript-websocket-simple) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "example", | ||
"version": "1.0.0", | ||
"moduleType": [ | ||
"node" | ||
], | ||
"ignore": [ | ||
"**/.*", | ||
"node_modules", | ||
"bower_components", | ||
"output" | ||
], | ||
"dependencies": { | ||
"purescript-console": "^0.1.0", | ||
"purescript-websocket-simple": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<script src="output/script.js"></script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module Main where | ||
|
||
import Prelude | ||
|
||
import Control.Bind ((=<<)) | ||
import Control.Monad (when) | ||
import Control.Monad.Eff.Var (($=), get) | ||
import Control.Monad.Eff.Console (log) | ||
import Control.Monad.Eff.Console.Unsafe (logAny) | ||
import Data.Maybe (Maybe(..)) | ||
|
||
import WebSocket | ||
|
||
main = do | ||
Connection socket <- newWebSocket (URL "ws://echo.websocket.org") [] | ||
|
||
socket.onopen $= \event -> do | ||
logAny event | ||
log "onopen: Connection opened" | ||
|
||
log <<< runURL =<< get socket.url | ||
|
||
log "onopen: Sending 'hello'" | ||
socket.send (Message "hello") | ||
|
||
log "onopen: Sending 'goodbye'" | ||
socket.send (Message "goodbye") | ||
|
||
socket.onmessage $= \event -> do | ||
logAny event | ||
let received = runMessage (runMessageEvent event) | ||
|
||
log $ "onmessage: Received '" ++ received ++ "'" | ||
|
||
when (received == "goodbye") do | ||
log "onmessage: closing connection" | ||
socket.close Nothing Nothing | ||
|
||
socket.onclose $= \event -> do | ||
logAny event | ||
log "onclose: Connection closed" |
Oops, something went wrong.