File tree 9 files changed +480
-224
lines changed
9 files changed +480
-224
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -2,6 +2,6 @@ import '@bacons/text-decoder/install'
2
2
3
3
import { AppRegistry } from 'react-native'
4
4
5
- import { App } from './App '
5
+ import { BenchmarkUI } from './tests/benchmark '
6
6
7
- AppRegistry . registerComponent ( 'NitroPlayground' , ( ) => App )
7
+ AppRegistry . registerComponent ( 'NitroPlayground' , ( ) => BenchmarkUI )
Original file line number Diff line number Diff line change 5
5
"android" : " react-native run-android" ,
6
6
"ios" : " react-native run-ios" ,
7
7
"start" : " react-native start" ,
8
- "server" : " bun server.ts"
8
+ "server" : " bun server/index .ts"
9
9
},
10
10
"dependencies" : {
11
11
"@bacons/text-decoder" : " ^0.0.0" ,
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ /// <reference types="bun-types" />
2
+
3
+ /**
4
+ * Creates a WebSocket server that sends configurable responses
5
+ */
6
+ export function createServer ( payload : string | Bun . BufferSource , port : number ) {
7
+ const server = Bun . serve ( {
8
+ fetch ( req , server ) {
9
+ if ( server . upgrade ( req ) ) {
10
+ return
11
+ }
12
+ return new Response ( 'Upgrade failed' , { status : 500 } )
13
+ } ,
14
+ websocket : {
15
+ message ( ws , message : string ) {
16
+ if ( typeof message !== 'string' ) {
17
+ return
18
+ }
19
+ const count = parseInt ( message )
20
+ if ( isNaN ( count ) ) {
21
+ return
22
+ }
23
+ try {
24
+ for ( let i = 0 ; i < count ; i ++ ) {
25
+ ws . send ( payload )
26
+ }
27
+ } catch ( error ) {
28
+ console . error ( 'Failed to parse message:' , error )
29
+ }
30
+ } ,
31
+ } ,
32
+ port,
33
+ } )
34
+
35
+ console . log ( `WebSocket server listening on ws://localhost:${ port } ` )
36
+
37
+ // Return cleanup function
38
+ return ( ) => server . stop ( )
39
+ }
Original file line number Diff line number Diff line change
1
+ import { createServer } from './createServer'
2
+ import {
3
+ CHAT_PAYLOAD ,
4
+ CHAT_PAYLOAD_BINARY ,
5
+ CHAT_SERVER_BINARY_PORT ,
6
+ CHAT_SERVER_PORT ,
7
+ COORDINATE_PAYLOAD ,
8
+ COORDINATE_PAYLOAD_BINARY ,
9
+ COORDINATE_SERVER_BINARY_PORT ,
10
+ COORDINATE_SERVER_PORT ,
11
+ IMAGE_SERVER_PORT ,
12
+ } from './payloads'
13
+
14
+ async function run ( ) {
15
+ const stopChatServer = createServer ( CHAT_PAYLOAD , CHAT_SERVER_PORT )
16
+ const stopChatBinaryServer = createServer ( CHAT_PAYLOAD_BINARY , CHAT_SERVER_BINARY_PORT )
17
+ const stopCoordinateServer = createServer ( COORDINATE_PAYLOAD , COORDINATE_SERVER_PORT )
18
+ const stopCoordinateBinaryServer = createServer (
19
+ COORDINATE_PAYLOAD_BINARY ,
20
+ COORDINATE_SERVER_BINARY_PORT
21
+ )
22
+ const stopImageServer = createServer (
23
+ await Bun . file ( __dirname + '/img.jpg' ) . arrayBuffer ( ) ,
24
+ IMAGE_SERVER_PORT
25
+ )
26
+
27
+ const stopAllServers = ( ) => {
28
+ stopChatServer ( )
29
+ stopChatBinaryServer ( )
30
+ stopCoordinateServer ( )
31
+ stopCoordinateBinaryServer ( )
32
+ stopImageServer ( )
33
+ }
34
+
35
+ process . on ( 'SIGINT' , ( ) => {
36
+ stopAllServers ( )
37
+ process . exit ( 0 )
38
+ } )
39
+ }
40
+
41
+ run ( )
Original file line number Diff line number Diff line change
1
+ /**
2
+ * This file contains the payloads that are used in the test.
3
+ */
4
+
5
+ const encoder = new TextEncoder ( )
6
+
7
+ export const CHAT_PAYLOAD = JSON . stringify ( {
8
+ id : '123e4567-e89b-12d3-a456-426614174000' ,
9
+ type : 'message' ,
10
+ content : {
11
+ text : 'Hello! How are you doing today? 👋' ,
12
+ mentions : [ '@mike' ] ,
13
+ attachments : [ ] ,
14
+ } ,
15
+ room : {
16
+ id : 'room_456' ,
17
+ type : 'direct' ,
18
+ } ,
19
+ metadata : {
20
+ client : 'react-native-fast-ws/1.0.0' ,
21
+ } ,
22
+ } )
23
+
24
+ export const CHAT_PAYLOAD_BINARY = encoder . encode ( JSON . stringify ( CHAT_PAYLOAD ) )
25
+
26
+ export const COORDINATE_PAYLOAD = JSON . stringify ( {
27
+ coords : [ 456 , 750 ] ,
28
+ } )
29
+ export const COORDINATE_PAYLOAD_BINARY = encoder . encode ( JSON . stringify ( COORDINATE_PAYLOAD ) )
30
+
31
+ export const CHAT_SERVER_PORT = 3000
32
+ export const CHAT_SERVER_BINARY_PORT = 3001
33
+
34
+ export const COORDINATE_SERVER_PORT = 3002
35
+ export const COORDINATE_SERVER_BINARY_PORT = 3003
36
+
37
+ export const IMAGE_SERVER_PORT = 3004
You can’t perform that action at this time.
0 commit comments