Skip to content

websockets #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 16, 2022
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Features:
* IME support (for Chinese, Japanese etc text input)
* System clipboard (copy and paste) support
* Show a system tray icon and menu (Windows only)
* Non-blocking HTTP requests and WebSockets

### Documentation

Expand Down
5 changes: 3 additions & 2 deletions examples/httprequest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import windy

# You can have many requests in-flight at the same time.

# Calling startHttpRequest never fails. If there is any error, onError will
# be called during the next pollEvents (or later).
# Calling startHttpRequest never throws an exception.
# If there is any error, onError will be called during
# the next pollEvents (or later).

let req = startHttpRequest("https://www.google.com")

Expand Down
30 changes: 30 additions & 0 deletions examples/websocket.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import windy

# WebSockets do not block.

# All callbacks are called on the main thread.

# You can have many WebSockets open at the same time.

# Calling openWebSocket never throws an exception.
# If there is any error, onError will be called during
# the next pollEvents (or later).

let req = openWebSocket("wss://stream.pushbullet.com/websocket/test")

req.onError = proc(msg: string) =
echo "onError: " & msg

req.onOpen = proc() =
echo "onOpen"

req.onMessage = proc(msg: string, kind: WebSocketMessageKind) =
echo "onMessage: ", msg

req.onClose = proc() =
echo "onClose"

# Closing the window exits the demo
let window = newWindow("Windy Basic", ivec2(1280, 800))
while not window.closeRequested:
pollEvents()
13 changes: 7 additions & 6 deletions src/windy/platforms/macos/objc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,13 @@ template addClass*(className, superName: string, cls: Class, body: untyped) =
discard class_addProtocol(cls, objc_getProtocol(protocolName.cstring))

template addMethod(methodName: string, fn: untyped) =
discard class_addMethod(
cls,
s(methodName),
cast[IMP](fn),
"".cstring
)
{.cast(raises: []).}:
discard class_addMethod(
cls,
s(methodName),
cast[IMP](fn),
"".cstring
)

body

Expand Down
2 changes: 1 addition & 1 deletion src/windy/platforms/macos/platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ proc resetCursorRects(self: ID, cmd: SEL): ID {.cdecl.} =
cursor = NSCursor.alloc().initWithImage(image, hotspot)
self.NSView.addCursorRect(self.NSView.bounds, cursor)

proc init() =
proc init() {.raises: [].} =
if initialized:
return

Expand Down
Loading