Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions interface/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@polywrap/web-socket-interface",
"name": "@polywrap/websocket-interface",
"description": "Polywrap WebSocket Interface",
"version": "0.10.0-pre.7",
"version": "0.10.0",
"scripts": {
"build": "npx polywrap build",
"deploy": "npx polywrap deploy -o deployment.json"
},
"devDependencies": {
"polywrap": "0.10.0-pre.7"
"polywrap": "0.10.3"
},
"publishConfig": {
"access": "public"
Expand Down
225 changes: 225 additions & 0 deletions interface/polywrap.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
type Module {
"""
Create a socket with id. Can return after `timeout` if the server is not responding. Returns the socket `id`.
"""
open(url: String!, protocols: [String], timeout: UInt32): Connection!

"""
Close socket `id`, optionally with a status code and reason.
"""
close(id: UInt32!, code: Int, reason: String): Boolean!

"""
Send message via socket `id`.
"""
send(id: UInt32!, message: String!): Boolean!

"""
Send a binary message via socket `id`.
"""
sendBinary(id: UInt32!, message: Bytes!): Boolean!

"""
Register a callback to be called when a message is received on socket `id`.
"""
setOnMessage(id: UInt32!, callback: Callback!): Boolean!

"""
Register a callback to be called when socket `id` is closed.
"""
setOnClose(id: UInt32!, callback: Callback!): Boolean!

"""
Register a callback to be called when an error occurs on socket `id`.
"""
setOnError(id: UInt32!, callback: Callback!): Boolean!

"""
Save messages to ws plugin cache for socket `id`.
"""
addCache(id: UInt32!): Boolean!

"""
Stop caching messages for socket `id`.
"""
removeCache(id: UInt32!): Boolean!

"""
Get messages and flush cache. Can wait until receives `min` events or reaches `timeout`.
"""
receive(id: UInt32!, min: UInt32, timeout: UInt32): [Message!]!

"""
Check the readyState of the WebSocket. Returns 0 for CONNECTING, 1 for OPEN, 2 for CLOSING, and 3 for CLOSED.
"""
getReadyState(id: UInt32!): ConnectionState!

"""
Get the Connection associated with the connection ID, or null if no connection with that ID is found
"""
getConnection(id: UInt32!): Connection
}

type Connection {
"""
The connection ID
"""
id: UInt!

"""
This represents the URL of the WebSocket server.
"""
url: String!

"""
This represents the current state of the WebSocket connection.
"""
state: ConnectionState!

"""
This represents the subprotocol selected by the server.
"""
subprotocol: String

"""
These are the extensions selected by the server.
"""
extensions: [String]

"""
This represents the close code when the connection is closed.
"""
closeCode: Int

"""
This represents the close reason when the connection is closed.
"""
closeReason: String
}

enum ConnectionState {
"""
The connection is not yet open.
"""
CONNECTING

"""
The connection is open and ready to communicate.
"""
OPEN

"""
The connection is in the process of closing.
"""
CLOSING

"""
The connection is closed or couldn't be opened.
"""
CLOSED
}

"""
A WebSocket Message
"""
type Message {
"""
The data sent by the server.
"""
data: String!

"""
The origin of the server that sent the message.
"""
origin: String!

"""
The timestamp at which the message was created.
"""
timeStamp: String!

"""
Indicates whether the message data is binary.
"""
isBinary: Boolean!

"""
The id of the last event, if server-sent events are used.
"""
lastEventId: String

"""
The binary data sent by the server, if any.
"""
binaryData: Bytes

"""
The extension data sent by the server, if any.
"""
extensionData: String
}

"""Information about a close event"""
type CloseEvent {
"""
The close code provided by the server.
"""
code: Int!

"""
The reason for closure provided by the server.
"""
reason: String!

"""
Indicates whether or not the connection was closed cleanly.
"""
wasClean: Boolean!

"""
The timestamp at which the event was created.
"""
timeStamp: String!
}

"""Information about an error event"""
type ErrorEvent {
"""
The error message.
"""
message: String!

"""
The name of the file in which the error occurred, if available.
"""
filename: String

"""
The line number in the file where the error occurred, if available.
"""
lineno: Int

"""
The column number in the line of the file where the error occurred, if available.
"""
colno: Int

"""
The timestamp at which the error event was created.
"""
timeStamp: String!
}

""" A callback """
type Callback {
"""
The URI of the WRAP module.
"""
uri: String!

"""
The method of the WRAP module.
"""
method: String!
}

7 changes: 2 additions & 5 deletions interface/polywrap.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
format: 0.3.0
project:
name: web-socket-interface
name: websocket-interface
type: interface
source:
schema: ./src/schema.graphql
extensions:
deploy: ./polywrap.deploy.yaml
resources: ./resources
schema: ./polywrap.graphql
112 changes: 57 additions & 55 deletions interface/resources/README.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,83 @@
# WebSocket Wrapper Interface
# Datetime Wrapper Interface

| Version | URI | WRAP Version |
|-|-|-|
| 1.0.0 | [`wrap://ens/wrappers.polywrap.eth:web-socket@1.0.0`](https://wrappers.io/v/ens/wrappers.polywrap.eth:web-socket@1.0.0) | 0.1 |
| 1.0.0 | [`wrap://ens/wraps.eth:websocket@1.0.0`](https://wrappers.io/v/ens/wraps.eth:websocket@1.0.0) | 0.1 |

## Interface
```graphql
"""Subset of JS MessageEvent interface"""
type Message {
data: String!
origin: String!
lastEventId: String!
type Module {
open(url: String!, protocols: [String], timeout: UInt32): Connection!
close(id: UInt32!, code: Int, reason: String): Boolean!
send(id: UInt32!, message: String!): Boolean!
sendBinary(id: UInt32!, message: Bytes!): Boolean!
setOnMessage(id: UInt32!, callback: Callback!): Boolean!
setOnClose(id: UInt32!, callback: Callback!): Boolean!
setOnError(id: UInt32!, callback: Callback!): Boolean!
addCache(id: UInt32!): Boolean!
removeCache(id: UInt32!): Boolean!
receive(id: UInt32!, min: UInt32, timeout: UInt32): [Message!]!
getReadyState(id: UInt32!): ConnectionState!
getConnection(id: UInt32!): Connection
}

type Callback {
"""WRAP Module URI"""
uri: String!
"""WRAP Module Method"""
method: String!
type Connection {
id: UInt!
url: String!
state: ConnectionState!
subprotocol: String
extensions: [String]
closeCode: Int
closeReason: String
}

type Module {
"""
create a socket with id, can return after `timeout`
if the server is not responding. Returns the socket `id`
"""
open(url: String!, timeout: UInt32): UInt32!

"""
close socket `id`
"""
close(id: UInt32!): Boolean!

"""
send message via socket `id`
"""
send(id: UInt32!, message: String!): Boolean!

"""
send all messages to callback for socket `id`
"""
addCallback(id: UInt32!, callback: Callback!): Boolean!
enum ConnectionState {
CONNECTING
OPEN
CLOSING
CLOSED
}

"""
stop sending messages to callback for socket `id`
"""
removeCallback(id: UInt32!, callback: Callback!): Boolean!
type Message {
data: String!
origin: String!
timeStamp: String!
isBinary: Boolean!
lastEventId: String
binaryData: Bytes
extensionData: String
}

"""
save messages to ws plugin cache for socket `id`
"""
addCache(id: UInt32!): Boolean!
type CloseEvent {
code: Int!
reason: String!
wasClean: Boolean!
timeStamp: String!
}

"""
stop caching messages for socket `id`
"""
removeCache(id: UInt32!): Boolean!
type ErrorEvent {
message: String!
filename: String
lineno: Int
colno: Int
timeStamp: String!
}

"""
get messages and flush cache,
can wait until receives `min` events or reaches `timeout`
"""
receive(id: UInt32!, min: UInt32, timeout: UInt32): [Message!]!
type Callback {
uri: String!
method: String!
}
```

## Usage
```graphql
#import { Module } into WebSocket from "ens/wrappers.polywrap.eth:web-socket@1.0.0"

type Module implements WebSocket_Module {}
#import * from "ens/wraps.eth:websocket@1.0.0"
```

And implement the interface methods within your programming language of choice.

## Source Code
[Link](https://github.com/polywrap/WebSocket)
[Link](https://github.com/polywrap/std/websocket)

## Known Implementations
[Link](https://github.com/polywrap/WebSocket/tree/master/implementations)
[Link](https://github.com/polywrap/websocket/tree/master/implementations)
Loading