Closed prbaron closed 7 years ago
hello,
I tried to use getScreenId in my own application but it needs to be called twice to work. After investigation, I found the culprit, https://github.com/muaz-khan/getScreenId/blob/master/getScreenId.js#L55. The listener on the message is removed a bit too soon.
getScreenId
During the first call, the value of event.data is
event.data
{request: "postUri", uri: "https://www.webrtc-experiment.com/getSourceId/"}
Based on the logic, it will remove the listener before triggering the correct value back to my custom code.
During the second call, the value of event.data is
{chromeMediaSourceId: "xhtC84z5dQzNWCZIFq5owA=="}
If found out that the code works fine in your example (https://github.com/muaz-khan/getScreenId/blob/master/index.html) because you are calling the method getChromeExtensionStatus which will simulate the first call.
getChromeExtensionStatus
Shouldn't we only remove the listener when calling the callback in getScreenId ?
callback
i.e
window.getScreenId = function(callback) { // for Firefox: // sourceId == 'firefox' // screen_constraints = {...} if (!!navigator.mozGetUserMedia) { callback(null, 'firefox', { video: { mozMediaSource: 'window', mediaSource: 'window' } }); return; } window.addEventListener('message', onIFrameCallback); function onIFrameCallback(event) { if (!event.data) return; if (event.data.chromeMediaSourceId) { // this event listener is no more needed window.removeEventListener('message', onIFrameCallback); if (event.data.chromeMediaSourceId === 'PermissionDeniedError') { callback('permission-denied'); } else callback(null, event.data.chromeMediaSourceId, getScreenConstraints(null, event.data.chromeMediaSourceId)); } if (event.data.chromeExtensionStatus) { // this event listener is no more needed window.removeEventListener('message', onIFrameCallback); callback(event.data.chromeExtensionStatus, null, getScreenConstraints(event.data.chromeExtensionStatus)); } // this event listener is no more needed //window.removeEventListener('message', onIFrameCallback); } setTimeout(postGetSourceIdMessage, 100); };
Best regards
hello,
I tried to use
getScreenId
in my own application but it needs to be called twice to work. After investigation, I found the culprit, https://github.com/muaz-khan/getScreenId/blob/master/getScreenId.js#L55. The listener on the message is removed a bit too soon.During the first call, the value of
event.data
isBased on the logic, it will remove the listener before triggering the correct value back to my custom code.
During the second call, the value of
event.data
isIf found out that the code works fine in your example (https://github.com/muaz-khan/getScreenId/blob/master/index.html) because you are calling the method
getChromeExtensionStatus
which will simulate the first call.Shouldn't we only remove the listener when calling the
callback
ingetScreenId
?i.e
Best regards