Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
liowebrtc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sweng-group-15
liowebrtc
Commits
5170874c
Unverified
Commit
5170874c
authored
6 years ago
by
Leon
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Update README.md
parent
934fda9d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.md
+22
-13
22 additions, 13 deletions
README.md
with
22 additions
and
13 deletions
README.md
+
22
−
13
View file @
5170874c
...
...
@@ -42,29 +42,29 @@ webrtc.on('readyToCall', () => {
### Emitting to the hive
Sometimes a peer wants to let every other peer in the room to know about something. This can be accomplished with
```
shout(message
Label
, payload)```
```
shout(message
Type
, payload)```
```js
webrtc.shout('taskCompleted', { success: true, id: '137' });
```
Now for the recipients, handle the peer event with a listener:
```
js
webrtc
.
on
(
'
taskCompleted
'
,
(
data
,
peer
)
=>
{
if
(
data
.
success
)
console
.
log
(
`Peer
${
peer
.
id
}
completed task
${
data
.
id
}
`
);
webrtc
.
on
(
'
receivedPeerData
'
,
(
type
,
data
,
peer
)
=>
{
if
(
type
===
'
taskCompleted
'
&&
data
.
success
)
{
console
.
log
(
`Peer
${
peer
.
id
}
completed task
${
data
.
id
}
`
);
}
});
```
### Communicating with a single peer
Sometimes a peer only wants to send data directly to another peer. This can be accomplished with
```
whisper(peer, message
Label
, payload)```
```
whisper(peer, message
Type
, payload)```
```js
webrtc.whisper(peer, 'directMessage', { msg: 'Hello world!' });
// Or
webrtc.getPeers()[0].sendDirectly('directMessage', { msg: 'Hello world!' });
```
Receiving the message is the same as handling a peer event:
```
js
webrtc
.
on
(
'
di
rec
tMessage
'
,
(
data
,
peer
)
=>
{
console
.
log
(
`Peer
${
peer
.
id
}
says:
${
data
.
msg
}
`
);
webrtc
.
on
(
'
rec
eivedPeerData
'
,
(
type
,
data
,
peer
)
=>
{
if
(
type
===
'
directMessage
'
)
console
.
log
(
`Peer
${
peer
.
id
}
says:
${
data
.
msg
}
`
);
});
```
...
...
@@ -76,8 +76,8 @@ componentDidUpdate(prevProps, prevState) {
}
}
this
.
webrtc
.
on
(
'
stateUpd
at
e
'
,
(
state
,
peer
)
=>
{
this
.
setState
({
peerState
:
state
});
this
.
webrtc
.
on
(
'
receivedPeerD
at
a
'
,
(
type
,
state
,
peer
)
=>
{
if
(
type
===
'
stateUpdate
'
)
this
.
setState
({
peerState
:
state
});
});
```
...
...
@@ -324,17 +324,26 @@ enabled) streams have started
`resume()`
- resumes sending audio and video to all peers
`sendToAll(message
Label
, payload)`
- broadcasts a message to all peers in the
`sendToAll(message
Type
, payload)`
- broadcasts a message to all peers in the
room via the signaling channel (websocket)
-
`string messageLabel`
- The event label that be broadcasted via the signaling server
-
`object payload`
- an arbitrary value or object to send to peers
`sendDirectlyToAll(message
Label
, payload, channel)`
- broadcasts a message
`sendDirectlyToAll(message
Type
, payload, channel)`
- broadcasts a message
to all peers in the room via a dataChannel
-
`string messageType`
- the event label that peers will listen for
-
`object payload`
- an arbitrary value or object to send to peers
-
`string channel`
- (optional) the label for the dataChannel to send on
-
`string messageLabel`
- the event label that peers will listen for
`shout(messageType, payload)`
- broadcasts a message
to all peers in the room via the default data channel
-
`string messageType`
- A value that represents the classification of the payload
-
`object payload`
- an arbitrary value or object to send to peers
`whisper(peer, messageType, payload)`
- sends a message to a single peer in the room
-
`string messageType`
- A value that represents the classification of the payload
-
`object payload`
- an arbitrary value or object to send to peers
`getPeers(sessionId, type)`
- returns all peers by
`sessionId`
and/or
`type`
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment