-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce broadcast API for event sharing (#884)
This commit implements broadcast API, which enables the sharing of a broader range of general events beyond the current document and presence events in Yorkie's Publish-Subscribe model. 1. Broadcast Events: Users can now broadcast custom events with a specified topic and payload. The payload can be of any type, as long as it is serializable. ```ts // Broadcast an event with a topic and payload const payload = 'hello'; doc.broadcast('TOPIC_NAME', payload); ``` 2. Subscribe to Broadcast Events: Users can subscribe to specific topics and handle the events via a callback function. The callback is triggered whenever an event with the corresponding topic is broadcast. ```ts // Subscribe to a specific topic for broadcast events doc.subscribe('broadcast', ({value: {topic, payload, clientID}}) => { // Handle the broadcast event for the specified topic }); ```
- Loading branch information
1 parent
18ad89f
commit 2b2ee0b
Showing
6 changed files
with
402 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2024 The Yorkie Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* `validateSerializable` returns whether the given value is serializable or not. | ||
*/ | ||
export const validateSerializable = (value: any): boolean => { | ||
try { | ||
const serialized = JSON.stringify(value); | ||
|
||
if (serialized === undefined) { | ||
return false; | ||
} | ||
} catch (error) { | ||
return false; | ||
} | ||
return true; | ||
}; |
Oops, something went wrong.