Skip to content

Commit b896767

Browse files
authored
feat: support sending blobs (#19)
* feat * revert accidential changes
1 parent 98339c7 commit b896767

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ ws.addEventListener('message', (event) => {
5353

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

5859
// Close the connection when done

example/ios/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PODS:
22
- boost (1.84.0)
33
- DoubleConversion (1.1.6)
4-
- FastWebSocket (0.0.1):
4+
- FastWebSocket (0.1.1):
55
- DoubleConversion
66
- glog
77
- hermes-engine
@@ -1764,7 +1764,7 @@ EXTERNAL SOURCES:
17641764
SPEC CHECKSUMS:
17651765
boost: 1dca942403ed9342f98334bf4c3621f011aa7946
17661766
DoubleConversion: f16ae600a246532c4020132d54af21d0ddb2a385
1767-
FastWebSocket: f7efa0908137535badb0fae69aedc6739fa6c0b7
1767+
FastWebSocket: 3e0362e21dd65bd5bca85b7ce6efd7ab03cf1749
17681768
FBLazyVector: aa59bef5c46e93168bffcf3dc37ee1e176de799a
17691769
fmt: 10c6e61f4be25dc963c36bd73fc7b1705fe975be
17701770
glog: 08b301085f15bcbb6ff8632a8ebaf239aae04e6a

packages/react-native-fast-ws/src/index.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,13 @@ export class WebSocket
168168
return
169169
}
170170

171-
// tbd: Blob support
172-
// if (message instanceof Blob) {
173-
// return
174-
// }
171+
if (message instanceof Blob) {
172+
;(async () => {
173+
const arrayBuffer = await message.arrayBuffer()
174+
this.ws.sendArrayBuffer(arrayBuffer)
175+
})()
176+
return
177+
}
175178

176179
throw new TypeError('Invalid message type')
177180
}

packages/react-native-fast-ws/src/spec.nitro.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export interface WebSocket extends HybridObject<{ ios: 'swift'; android: 'kotlin
55
sendArrayBuffer(buffer: ArrayBuffer): void
66

77
connect(): void
8-
close(code?: number, reason?: string): void
8+
close(code: number, reason: string): void
99
ping(): void
1010

1111
onOpen(callback: (selectedProtocol: string) => void): void

0 commit comments

Comments
 (0)