Skip to content

feat: support sending blobs #19

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 2 commits into from
Nov 6, 2024
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 @@ -53,6 +53,7 @@ ws.addEventListener('message', (event) => {

// Send different types of data
ws.send('Plain text message');
ws.send(new Blob('string'));
ws.send(new Uint8Array([1, 2, 3, 4]));

// Close the connection when done
Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PODS:
- boost (1.84.0)
- DoubleConversion (1.1.6)
- FastWebSocket (0.0.1):
- FastWebSocket (0.1.1):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1764,7 +1764,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
boost: 1dca942403ed9342f98334bf4c3621f011aa7946
DoubleConversion: f16ae600a246532c4020132d54af21d0ddb2a385
FastWebSocket: f7efa0908137535badb0fae69aedc6739fa6c0b7
FastWebSocket: 3e0362e21dd65bd5bca85b7ce6efd7ab03cf1749
FBLazyVector: aa59bef5c46e93168bffcf3dc37ee1e176de799a
fmt: 10c6e61f4be25dc963c36bd73fc7b1705fe975be
glog: 08b301085f15bcbb6ff8632a8ebaf239aae04e6a
Expand Down
11 changes: 7 additions & 4 deletions packages/react-native-fast-ws/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,13 @@ export class WebSocket
return
}

// tbd: Blob support
// if (message instanceof Blob) {
// return
// }
if (message instanceof Blob) {
;(async () => {
const arrayBuffer = await message.arrayBuffer()
this.ws.sendArrayBuffer(arrayBuffer)
})()
return
}

throw new TypeError('Invalid message type')
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-fast-ws/src/spec.nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface WebSocket extends HybridObject<{ ios: 'swift'; android: 'kotlin
sendArrayBuffer(buffer: ArrayBuffer): void

connect(): void
close(code?: number, reason?: string): void
close(code: number, reason: string): void
ping(): void

onOpen(callback: (selectedProtocol: string) => void): void
Expand Down