forked from yjs/y-webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Azure webpubsub signaling client #4
Closed
byrond
wants to merge
14
commits into
abstract-signaling-server
from
azure-webpubsub-signaling-client
Closed
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
28605c1
add a web pubsub client that extends SignalingConn
byrond 2c804af
change signaling conn class name
byrond 8c47d0f
add azure web pubsub client back
byrond ab02bf8
update lib0
byrond eaac2cc
add AzureWebPubSubSignalingWebrtcProvider and AzureWebPubSubSignaling…
byrond 7d6a619
remove old js file for azure client
byrond a42aa09
don't export publishSignalingMessage
byrond 8c42918
wrap client creation in undefined check
byrond ee548b0
call handleConnect in child class
byrond 197fdf3
bring over changes from ET
byrond 98d2291
Merge branch 'abstract-signaling-server' into azure-webpubsub-signali…
byrond 20bb93b
uncomment azure client code
byrond 2a78e95
remove azure signaling code and add joinAllRooms and addSignalingConn…
byrond 21fa227
Merge branch 'abstract-signaling-server' into azure-webpubsub-signali…
byrond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { WebrtcProvider, SignalingConn, publishSignalingMessage } from 'y-webrtc' | ||
import { WebPubSubClient } from "@azure/web-pubsub-client" | ||
|
||
export class AzureWebPubSubSignalingConn extends SignalingConn { | ||
constructor (url) { | ||
super(url) | ||
this.connected = false | ||
} | ||
|
||
setupClient() { | ||
this.client = new WebPubSubClient(this.url) | ||
this.client.on('connected', e => { | ||
this.connected = true | ||
log(`connected (${url}) with ID ${e.connectionId}`) | ||
// Join all the groups. | ||
const groups = Array.from(rooms.keys()) | ||
groups.forEach(group => | ||
this.subscribe(group) | ||
) | ||
rooms.forEach(room => | ||
publishSignalingMessage(this, room, { type: 'announce', from: room.peerId }) | ||
) | ||
}) | ||
this.client.on('disconnected', e => log(`disconnect (${url}): ${e.message}`)) | ||
this.client.on('stopped', () => log(`stopped (${url})`)) | ||
// Set an event handler for group messages before connecting, so we don't miss any. | ||
this.client.on('group-message', e => { | ||
this.handleMessage(e.message.group, e.message.data) | ||
}) | ||
// Connect to the signaling server. | ||
this.client.start() | ||
} | ||
|
||
connected () { | ||
return this.connected | ||
} | ||
|
||
subscribe (roomName) { | ||
this.client.joinGroup(roomName) | ||
} | ||
|
||
unsubscribe (roomName) { | ||
this.client.leaveGroup(roomName) | ||
} | ||
|
||
publish (roomName, message) { | ||
let messageType = "json" | ||
if (typeof message === 'string') { | ||
messageType = "text" | ||
} | ||
this.client.sendToGroup(roomName, message, messageType) | ||
} | ||
|
||
destroy () { | ||
this.client.stop() | ||
} | ||
} | ||
|
||
export class AzureWebPubSubSignalingWebrtcProvider extends WebrtcProvider { | ||
connect () { | ||
this.shouldConnect = true | ||
this.signalingUrls.forEach(url => { | ||
const signalingConn = map.setIfUndefined(signalingConns, url, () => new AzureWebPubSubSignalingConn(url)) | ||
this.signalingConns.push(signalingConn) | ||
signalingConn.providers.add(this) | ||
}) | ||
if (this.room) { | ||
this.room.connect() | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only line that is different in this overridden method, which is why it would be great to just pass in the new class name
AzureWebPubSubSignalingConn
somehow.