Class for creating a WebSocket server and sending messages between development server and the React Native applications.
↳ WebSocketMessageServer
• new WebSocketMessageServer(fastify
)
Create new instance of WebSocketMessageServer and attach it to the given Fastify instance.
Any logging information, will be passed through standard fastify.log
API.
Name | Type | Description |
---|---|---|
fastify |
FastifyDevServer |
Fastify instance to attach the WebSocket server to. |
packages/repack/src/server/ws/WebSocketMessageServer.ts:92
• Protected
fastify: FastifyDevServer
Fastify instance from which server will receive upgrade connections.
packages/repack/src/server/ws/WebSocketServer.ts:16
• Readonly
paths: string
[]
packages/repack/src/server/ws/WebSocketServer.ts:18
• Readonly
server: Server
An instance of the underlying WebSocket server.
packages/repack/src/server/ws/WebSocketServer.ts:13
▪ Static
Readonly
PROTOCOL_VERSION: 2
packages/repack/src/server/ws/WebSocketMessageServer.ts:39
▸ broadcast(method
, params?
): void
Send method broadcast to all connected clients.
Name | Type | Description |
---|---|---|
method |
string |
Method name to broadcast. |
params? |
Record <string , any > |
Method parameters. |
void
packages/repack/src/server/ws/WebSocketMessageServer.ts:348
▸ forwardRequest(clientId
, message
): void
Send given request message
to it's designated client's socket based on message.target
.
The target client must be connected, otherwise it will throw an error.
Name | Type | Description |
---|---|---|
clientId |
string |
Id of the client that requested the forward. |
message |
Partial <ReactNativeMessage > |
Message to forward. |
void
packages/repack/src/server/ws/WebSocketMessageServer.ts:204
▸ forwardResponse(message
): void
Send given response message
to it's designated client's socket based
on message.id.clientId
.
The target client must be connected, otherwise it will throw an error.
Name | Type | Description |
---|---|---|
message |
Partial <ReactNativeMessage > |
Message to forward. |
void
packages/repack/src/server/ws/WebSocketMessageServer.ts:235
▸ getClientSocket(clientId
): WebSocketWithUpgradeReq
Get client's WebSocket connection for given clientId
.
Throws if no such client is connected.
Name | Type | Description |
---|---|---|
clientId |
string |
Id of the client. |
WebSocketWithUpgradeReq
WebSocket connection.
packages/repack/src/server/ws/WebSocketMessageServer.ts:140
▸ handleError(clientId
, message
, error
): void
Process error by sending an error message to the client whose message caused the error to occur.
Name | Type | Description |
---|---|---|
clientId |
string |
Id of the client whose message caused an error. |
message |
Partial <ReactNativeMessage > |
Original message which caused the error. |
error |
Error |
Concrete instance of an error that occurred. |
void
packages/repack/src/server/ws/WebSocketMessageServer.ts:156
▸ onConnection(socket
, request
): void
Process new client's WebSocket connection.
Name | Type | Description |
---|---|---|
socket |
WebSocket |
Incoming WebSocket connection. |
request |
IncomingMessage |
Upgrade request for the connection. |
void
packages/repack/src/server/ws/WebSocketMessageServer.ts:358
▸ parseMessage(data
, binary
): undefined
| Partial
<ReactNativeMessage
>
Parse stringified message into a ReactNativeMessage.
Name | Type | Description |
---|---|---|
data |
string |
Stringified message. |
binary |
any |
Additional binary data if any. |
undefined
| Partial
<ReactNativeMessage
>
Parsed message or undefined
if parsing failed.
packages/repack/src/server/ws/WebSocketMessageServer.ts:103
▸ processServerRequest(clientId
, message
): void
Process request message targeted towards this WebSocketMessageServer and send back the results.
Name | Type | Description |
---|---|---|
clientId |
string |
Id of the client who send the message. |
message |
Partial <ReactNativeMessage > |
The message to process by the server. |
void
packages/repack/src/server/ws/WebSocketMessageServer.ts:258
▸ sendBroadcast(broadcasterId
, message
): void
Broadcast given message to all connected clients.
Name | Type | Description |
---|---|---|
broadcasterId |
undefined | string |
Id of the client who is broadcasting. |
message |
Partial <ReactNativeMessage > |
Message to broadcast. |
void
packages/repack/src/server/ws/WebSocketMessageServer.ts:307
▸ shouldUpgrade(pathname
): boolean
Name | Type |
---|---|
pathname |
string |
boolean
packages/repack/src/server/ws/WebSocketServer.ts:45
▸ upgrade(request
, socket
, head
): void
Name | Type |
---|---|
request |
IncomingMessage |
socket |
Socket |
head |
Buffer |
void
packages/repack/src/server/ws/WebSocketServer.ts:49
▸ Static
isBroadcast(message
): boolean
Check if message is a broadcast request.
Name | Type | Description |
---|---|---|
message |
Partial <ReactNativeMessage > |
Message to check. |
boolean
True if message is a broadcast request and should be broadcasted with sendBroadcast.
packages/repack/src/server/ws/WebSocketMessageServer.ts:48
▸ Static
isRequest(message
): boolean
Check if message is a method request.
Name | Type | Description |
---|---|---|
message |
Partial <ReactNativeMessage > |
Message to check. |
boolean
True if message is a request.
packages/repack/src/server/ws/WebSocketMessageServer.ts:62
▸ Static
isResponse(message
): boolean
Check if message is a response with results of performing some request.
Name | Type | Description |
---|---|---|
message |
Partial <ReactNativeMessage > |
Message to check. |
boolean
True if message is a response.