Adding a solution like the one described in the Microsoft documentation.
https://docs.microsoft.com/en-us/sharepoint/dev/spfx/subscribe-to-list-notifications
I receive hundred of errors. Most of the notifications are not triggered and 99% of times it does not connect.

It returns {"code":1,"message":"Session ID unknown"}
Create a solution with the code given from Microsoft.
Create a solution and add
```
import { IListSubscription, ListSubscriptionFactory } from '@microsoft/sp-list-subscription';
import { Guid } from '@microsoft/sp-core-library';
.....
private _listSubscriptionFactory: ListSubscriptionFactory;
private _listSubscription: IListSubscription;
private createListSubscription(): void {
this._listSubscriptionFactory = new ListSubscriptionFactory(this);
this._listSubscriptionFactory.createSubscription({
siteId: this.context.pageContext.site.id,
webId: this.context.pageContext.web.id,
listId: Guid.parse('DOCUMENT LIBRARY GUID'),
callbacks: {
notification: this._loadDocuments.bind(this),
connect: this._subscriptionConnected.bind(this),
disconnect: this._subscriptionDisconnected.bind(this)
}
}).then(value => this._listSubscription = value).catch(e =>
console.log("Error " + e.message)
);
}
private _loadDocuments(): void {
console.log("CHANGED....");
} private _subscriptionConnected(): void {
console.log("Connected....");
} private _subscriptionDisconnected(reason: string): void {
console.log("Disconnected...." + reason);
}
```
The function _loadDocuments should be fired every time something is changed on the Library.
npm install @microsoft/sp-list-subscription --save --save-exact
Thanks for your contribution! Sharing is caring.
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
According to some articles {"code":1,"message":"Session ID unknown"} might mean that the session ID was created on one machine and load balance is sending you to another machine that does not have that session ID.
This might explain why this is working some of the times.
On sp-list-subscription.js line 3426
Changing the line from
this.transports = opts.transports || ['polling', 'websocket'];
to
this.transports = opts.transports || ['websocket','polling'];
Seams to solve the problem (it uses websocket instead of polling as first option).
It also seams to be working on Lists even if the Considerations say _"you can subscribe to events from libraries (but not lists)"_
@andrewconnell Can you please check if this solves the problem without any drawback and update the @microsoft/sp-list-subscription version accordingly?
Any news on this issue?
Microsoft/Office 365 support team said this is a wrong parameter sent by the app (@microsoft/sp-list-subscription).
They sent me here but no one replies to anything for over a week.
The above fix works but when deploying the production version to the SharePoint app catalog it get's the Microsoft bugged version instead my locally fixed version.
It seams we are on our own...
Installed on production with a fixed version of ListSubscriptionFactory.js.
socket = io(notificationUrl,{transports:["websocket","polling"]});
instead of
socket = io(notificationUrl);
Socket io should be:
"socket.io-client": "^2.1.1"
Last version of socket io client does not work. You get sid error.
Thanks for your help.
@Dangerous-Mind said:
@andrewconnell Can you please check if this solves the problem without any drawback and update the @microsoft/sp-list-subscription version accordingly?
Sorry, but I'm not official MSFT support... I'm just like you: community :). I can't with any authority say an OOTB package is incorrect nor fix it. I just help maintain this list & why I just added labels & that MSFT should review it.
@andrewconnell
Then we are really on our own...
Office 365 / SharePoint support never solves anything and sends us here or to the user's voice.
Then there is no one in here.
Let's hope they also understand when we don't report security bugs we find post them were any hacker can make good use of it.
Thanks Andrew
PS: By the way, you said this was a "type:question" but it seams like a bug or a bad server configuration to me.
@Dangerous-Mind said:
PS: By the way, you said this was a "type:question" but it seams like a bug or a bad server configuration to me.
That's not for me to decide... ACK something is a bug is something Microsoft should be responsible doing. ;)
I'm seeing this as well, any fix that works?
I'm seeing this as well, any fix that works?
@Tanddant
You can also change the io socket so that it prefers websocket instead of polling by default.
But that it's a worst solution then changing the ListSubscriptionFactory.js.
I have it running on production with the ListSubscriptionFactory.js change.
On production you will need to make a copy of the @microsoft/sp-list-subscription, change it and deploy it with your project since Microsoft will get the bugged version and not your changed one.
Copying the sp-list-subscription inside the project will require you to install socket.io-client.
Version "socket.io-client": "^2.1.1" is working fine
Most helpful comment
@Dangerous-Mind said:
That's not for me to decide... ACK something is a bug is something Microsoft should be responsible doing. ;)