Skip to content

Commit

Permalink
Call subscribe again when there is no cached DRM profile (#456)
Browse files Browse the repository at this point in the history
* fix: call subscribe endpoint again when received active event to cache the DRM profile then forward to application
  • Loading branch information
vincentsong authored Oct 18, 2024
1 parent 9a39d65 commit 8b96f59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions packages/millicast-sdk/src/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,6 @@ export default class View extends BaseWebRTC {
streamName: this.streamName,
url: `${subscriberData.urls[0]}?token=${subscriberData.jwt}`
})
if (subscriberData.drmObject) {
// cache the DRM license server URLs
this.DRMProfile = subscriberData.drmObject
}
if (subscriberData.subscriberToken) {
this.subscriberToken = subscriberData.subscriberToken
}
Expand All @@ -258,10 +254,8 @@ export default class View extends BaseWebRTC {
await webRTCPeerInstance.createRTCPeer(this.options.peerConfig)
// Stop emiting events from the previous instances
this.stopReemitingWebRTCPeerInstanceEvents?.()
this.stopReemitingSignalingInstanceEvents?.()
// And start emitting from the new ones
this.stopReemitingWebRTCPeerInstanceEvents = reemit(webRTCPeerInstance, this, Object.values(webRTCEvents).filter(e => e !== webRTCEvents.track))
this.stopReemitingSignalingInstanceEvents = reemit(signalingInstance, this, [signalingEvents.broadcastEvent])

if (this.options.metadata) {
if (!this.worker) {
Expand Down Expand Up @@ -306,21 +300,30 @@ export default class View extends BaseWebRTC {
this.onTrackEvent(trackEvent)
})

signalingInstance.on(signalingEvents.broadcastEvent, (event) => {
signalingInstance.on(signalingEvents.broadcastEvent, async (event) => {
if (event.data.sourceId === null) {
switch (event.name) {
case 'active':
if (this.DRMProfile == null) {
const subscriberData = await this.tokenGenerator()
if (subscriberData.drmObject) {
// cache the DRM license server URLs
this.DRMProfile = subscriberData.drmObject
}
}
this.emit(signalingEvents.broadcastEvent, event)
this.isMainStreamActive = true
while (this.eventQueue.length > 0) {
this.onTrackEvent(this.eventQueue.shift())
}
break
return
case 'inactive':
this.isMainStreamActive = false
break
default:
break
}
this.emit(signalingEvents.broadcastEvent, event)
}
})

Expand Down
2 changes: 1 addition & 1 deletion packages/millicast-viewer-demo/src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const newViewer = () => {
}
});
millicastView.on("track", (event) => {
if (!millicastView.isDRMOn) addStream(event.streams[0]);
if (!enableDRM) addStream(event.streams[0]);
});

millicastView.on('metadata', (metadata) => {
Expand Down

0 comments on commit 8b96f59

Please sign in to comment.