Skip to content

Commit c248be2

Browse files
committed
Initial commit
1 parent 9b6a2df commit c248be2

14 files changed

+420
-1
lines changed

.eslintrc.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 5
4+
},
5+
"extends": "eslint:recommended",
6+
"env": {
7+
"commonjs": true,
8+
"browser": true
9+
},
10+
"rules": {
11+
"strict": [2, "global"],
12+
"block-scoped-var": 2,
13+
"consistent-return": 2,
14+
"eqeqeq": [2, "smart"],
15+
"guard-for-in": 2,
16+
"no-caller": 2,
17+
"no-extend-native": 2,
18+
"no-loop-func": 2,
19+
"no-new": 2,
20+
"no-param-reassign": 2,
21+
"no-return-assign": 2,
22+
"no-unused-expressions": 2,
23+
"no-use-before-define": 2,
24+
"radix": [2, "always"],
25+
"indent": [2, 2],
26+
"quotes": [2, "double"],
27+
"semi": [2, "always"]
28+
}
29+
}

.travis.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: node_js
2+
dist: trusty
3+
sudo: required
4+
node_js: stable
5+
install:
6+
- npm install -g bower
7+
- npm install
8+
- bower install
9+
script:
10+
- npm run -s build
11+
after_success:
12+
- >-
13+
test $TRAVIS_TAG &&
14+
echo $GITHUB_TOKEN | pulp login &&
15+
echo y | pulp publish --no-push

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# purescript-web-socket
1+
# purescript-web-socket

bower.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "purescript-web-socket",
3+
"homepage": "https://github.com/purescript-web/purescript-web-socket",
4+
"license": "MIT",
5+
"repository": {
6+
"type": "git",
7+
"url": "git://github.com/purescript-web/purescript-web-socket.git"
8+
},
9+
"ignore": [
10+
"**/.*",
11+
"bower_components",
12+
"node_modules",
13+
"output",
14+
"bower.json",
15+
"package.json"
16+
],
17+
"dependencies": {
18+
"purescript-arraybuffer-types": "^2.0.0",
19+
"purescript-web-file": "#compiler/0.12"
20+
}
21+
}

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"clean": "rimraf output && rimraf .pulp-cache",
5+
"build": "eslint src && pulp build -- --censor-lib --strict",
6+
"test": "pulp test --runtime phantomjs"
7+
},
8+
"devDependencies": {
9+
"eslint": "^3.19.0",
10+
"phantomjs-prebuilt": "^2.1.14",
11+
"pulp": "^11.0.0",
12+
"purescript-psa": "^0.5.0",
13+
"purescript": "^0.11.1",
14+
"rimraf": "^2.6.1"
15+
}
16+
}

src/Web/WebSocket/BinaryType.purs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module Web.WebSocket.BinaryType where
2+
3+
import Prelude
4+
import Data.Enum (Cardinality(..), class BoundedEnum, defaultPred, defaultSucc, class Enum)
5+
import Data.Maybe (Maybe(..))
6+
7+
data BinaryType
8+
= Blob
9+
| ArrayBuffer
10+
11+
derive instance eqBinaryType :: Eq BinaryType
12+
derive instance ordBinaryType :: Ord BinaryType
13+
14+
instance boundedBinaryType :: Bounded BinaryType where
15+
bottom = Blob
16+
top = ArrayBuffer
17+
18+
instance enumBinaryType :: Enum BinaryType where
19+
succ = defaultSucc toEnumBinaryType fromEnumBinaryType
20+
pred = defaultPred toEnumBinaryType fromEnumBinaryType
21+
22+
instance boundedEnumBinaryType :: BoundedEnum BinaryType where
23+
cardinality = Cardinality 2
24+
toEnum = toEnumBinaryType
25+
fromEnum = fromEnumBinaryType
26+
27+
instance showBinaryType :: Show BinaryType where
28+
show Blob = "Blob"
29+
show ArrayBuffer = "ArrayBuffer"
30+
31+
toEnumBinaryType :: Int -> Maybe BinaryType
32+
toEnumBinaryType =
33+
case _ of
34+
0 -> Just Blob
35+
1 -> Just ArrayBuffer
36+
_ -> Nothing
37+
38+
fromEnumBinaryType :: BinaryType -> Int
39+
fromEnumBinaryType =
40+
case _ of
41+
Blob -> 0
42+
ArrayBuffer -> 1
43+
44+
printBinaryType :: BinaryType -> String
45+
printBinaryType =
46+
case _ of
47+
Blob -> "blob"
48+
ArrayBuffer -> "arraybuffer"

src/Web/WebSocket/Event/CloseEvent.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
3+
exports.code = function (e) {
4+
return e.code;
5+
};
6+
7+
exports.reason = function (e) {
8+
return e.reason;
9+
};
10+
11+
exports.wasClean = function (e) {
12+
return e.wasClean;
13+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module Web.WebSocket.Event.CloseEvent where
2+
3+
import Data.Maybe (Maybe)
4+
import Unsafe.Coerce (unsafeCoerce)
5+
import Web.Event.Event (Event)
6+
import Web.Internal.FFI (unsafeReadProtoTagged)
7+
8+
foreign import data CloseEvent :: Type
9+
10+
fromEvent :: Event -> Maybe CloseEvent
11+
fromEvent = unsafeReadProtoTagged "CloseEvent"
12+
13+
toEvent :: CloseEvent -> Event
14+
toEvent = unsafeCoerce
15+
16+
foreign import code :: CloseEvent -> Int
17+
18+
foreign import reason :: CloseEvent -> String
19+
20+
foreign import wasClean :: CloseEvent -> Boolean
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Web.WebSocket.Event.EventTypes where
2+
3+
import Web.Event.Event (EventType(..))
4+
5+
onOpen :: EventType
6+
onOpen = EventType "open"
7+
8+
onMessage :: EventType
9+
onMessage = EventType "message"
10+
11+
onError :: EventType
12+
onError = EventType "error"
13+
14+
onClose :: EventType
15+
onClose = EventType "close"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
3+
exports.data_ = function (e) {
4+
return e.data;
5+
};
6+
7+
exports.origin = function (e) {
8+
return e.origin;
9+
};
10+
11+
exports.lastEventId = function (e) {
12+
return e.lastEventId;
13+
};

0 commit comments

Comments
 (0)